Multiple templates
This commit is contained in:
parent
c97f60619f
commit
d0c9332361
4 changed files with 17 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
6
test.rb
6
test.rb
|
@ -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,
|
||||
|
|
|
@ -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
|
Loading…
Reference in a new issue