Implement configuration files

This commit is contained in:
Alex Kotov 2024-01-11 13:03:04 +04:00
parent 15b24b8ebe
commit 16de2d44e6
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
3 changed files with 37 additions and 2 deletions

View file

@ -49,6 +49,25 @@ module Referator
:pong
end
def do_exec(command)
File.open File.expand_path command.data, workdir do |file|
code = ''
while running?
line = file.gets&.strip
break if line.nil?
next if line.empty? || line.start_with?('#')
if line.end_with? '\\'
code += line[...-1]
else
call Command.parse "#{code}#{line}"
code = ''
end
end
end
nil
end
##########
# Config #
##########

View file

@ -133,9 +133,9 @@ cmd :REGISTER_FORMAT, { name: :json, script: :render }
################
cmd :REGISTER_REF, RAW_REFS[:self][:foo]
cmd :REGISTER_REF, RAW_REFS[:self][:bar]
cmd :REGISTER_REF, RAW_REFS[:link][:example_com]
cmd :REGISTER_REF, RAW_REFS[:link][:causa_arcana_com]
cmd(:EXEC, 'conf_register_ref') { |result| raise unless result.nil? }
#######
# REF #

16
test/conf_register_ref Normal file
View file

@ -0,0 +1,16 @@
# self references
register_ref { \
"category": "self", \
"id": "/blog/bar", \
"slug": "blog-bar", \
"text": "Bar" \
}
# link references
register_ref { \
"category": "link", \
"id": "causa_arcana_com", \
"slug": "causa-arcana-com", \
"url": "https://causa-arcana.com", \
"text": "Causa Arcana" \
}