summaryrefslogtreecommitdiff
path: root/controllers/cartridges.rb
diff options
context:
space:
mode:
authoricebaker <icebaker@proton.me>2024-01-08 21:41:30 -0300
committericebaker <icebaker@proton.me>2024-01-08 21:41:30 -0300
commit31e53046bd35b83027f8a8e1ab99a6eceb4e6a3c (patch)
treed13179fb7eb91db4e70a97c96f24889b3153c451 /controllers/cartridges.rb
parent819381e7bd3e3ca5d310ad0a29b6925dcfa26720 (diff)
adding support to markdown cartridges
Diffstat (limited to 'controllers/cartridges.rb')
-rw-r--r--controllers/cartridges.rb28
1 files changed, 17 insertions, 11 deletions
diff --git a/controllers/cartridges.rb b/controllers/cartridges.rb
index df474a9..7215a99 100644
--- a/controllers/cartridges.rb
+++ b/controllers/cartridges.rb
@@ -3,16 +3,21 @@
require_relative '../components/storage'
require_relative '../logic/helpers/hash'
require_relative '../logic/cartridge/default'
+require_relative '../logic/cartridge/parser'
module NanoBot
module Controllers
class Cartridges
+ def self.load(path)
+ Logic::Cartridge::Parser.parse(File.read(path), format: File.extname(path))
+ end
+
def self.all
files = {}
path = Components::Storage.cartridges_path
- Dir.glob("#{path}/**/*.{yml,yaml}").each do |file|
+ Dir.glob("#{path}/**/*.{yml,yaml,markdown,mdown,mkdn,md}").each do |file|
files[Pathname.new(file).realpath] = {
base: path,
path: Pathname.new(file).realpath
@@ -22,16 +27,17 @@ module NanoBot
cartridges = []
files.values.uniq.map do |file|
- cartridge = Logic::Helpers::Hash.symbolize_keys(
- YAML.safe_load_file(file[:path], permitted_classes: [Symbol])
- ).merge({
- system: {
- id: file[:path].to_s.sub(/^#{Regexp.escape(file[:base])}/, '').sub(%r{^/}, '').sub(/\.[^.]+\z/,
- ''),
- path: file[:path],
- base: file[:base]
- }
- })
+ cartridge = load_cartridge(file[:path]).merge(
+ {
+ system: {
+ id: file[:path].to_s.sub(
+ /^#{Regexp.escape(file[:base])}/, ''
+ ).sub(%r{^/}, '').sub(/\.[^.]+\z/, ''),
+ path: file[:path],
+ base: file[:base]
+ }
+ }
+ )
next if cartridge[:meta][:name].nil?