Multiple templates

This commit is contained in:
Alex Kotov 2023-09-30 00:38:39 +04:00
parent c97f60619f
commit d0c9332361
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
4 changed files with 17 additions and 7 deletions

View file

@ -34,9 +34,15 @@ module Referator
nil
end
def render(name, notes)
def render(template, name, notes)
exists! name
scripts[name].call(**script_vars(format: name, notes: notes.to_json))
scripts[name].call(
**script_vars(
template:,
format: name,
notes: notes.to_json,
),
)
end
private
@ -56,7 +62,9 @@ module Referator
raise 'Invalid name' unless NAME_RE.match? name
end
def script_vars(format: nil, notes: nil) = { format:, notes: }.freeze
def script_vars(template: nil, format: nil, notes: nil)
{ template:, format:, notes: }.freeze
end
end
end
end

View file

@ -20,7 +20,7 @@ module Referator
end
def render(format)
config.formats.render format, @notes.map(&:to_h).freeze
config.formats.render :footnotes, format, @notes.map(&:to_h).freeze
end
private

View file

@ -33,8 +33,10 @@ cmd :REGISTER_KIND, :self
cmd :REGISTER_KIND, :link
cmd :REGISTER_FORMAT, { name: :html,
args: ['test/footnotes.rb', { format: nil }],
stdin: { notes: nil } }
stdin: { notes: nil },
args: ['test/render.rb',
{ template: nil },
{ format: nil }] }
cmd :ADD_REF,
{ kind: :self,

View file

@ -12,6 +12,6 @@ def template(filename)
end.freeze
end
puts template("footnotes.#{ARGV.first}.erb").result_with_hash(
puts template("#{ARGV[0]}.#{ARGV[1]}.erb").result_with_hash(
notes: JSON.parse($stdin.read),
).strip