# File lib/amrita/merge.rb, line 9def initialize(dir=nil, &block)
@dir = dir
if block_given?
@body = yieldelse
@body = nilendend
Public Instance methods
amrita_get_data(key, element, context)
# File lib/amrita/merge.rb, line 18def amrita_get_data(key, element, context)
amrita_expand_element(element, context)
end
amrita_expand_element(e, context)
# File lib/amrita/merge.rb, line 22def amrita_expand_element(e, context)
case e.hid
when /(.*)#(.*)/
fname, data_id = $1, $2
e = merge_templates(fname, data_id, e, context)
else
e.init_body do
e.body.expand1(self, context)
endendif @body
e.expand(@body, context)
else
e
endend
merge_templates(fname, data_id, e, context)
# File lib/amrita/merge.rb, line 40def merge_templates(fname, data_id, e, context)
h = read_template(fname)
ee = h.find {|e| e[:id] == data_id }
raise "no match for #{data_id}" unless ee
ee.delete_attr!(:id)
ee
end
read_template(fname)
# File lib/amrita/merge.rb, line 48def read_template(fname)
fname = @dir + "/" + fname if @dir
HtmlParser.parse_file fname
end