lib/ruhl.rb in ruhl-0.9.0 vs lib/ruhl.rb in ruhl-0.9.1
- old
+ new
@@ -8,17 +8,18 @@
attr_reader :document, :scope, :layout, :layout_source,
:local_object, :block_object
def initialize(html, options = {})
@local_object = options[:local_object]
+ @block_object = options[:block_object]
@layout_source = options[:layout_source]
if @layout = options[:layout]
raise LayoutNotFoundError.new(@layout) unless File.exists?(@layout)
end
- if @layout || @local_object
+ if @layout || @local_object || @block_object
@document = Nokogiri::HTML.fragment(html)
else
@document = Nokogiri::HTML(html)
end
end
@@ -67,10 +68,15 @@
end.to_s
tag.swap(new_content)
end
+ def render_block(tag, code)
+ bo = execute_ruby(tag, code)
+ Ruhl::Engine.new(tag.inner_html, :block_object => bo).render(scope)
+ end
+
def render_file(contents)
doc = Nokogiri::HTML( contents )
parse_doc(doc)
doc.to_s
end
@@ -105,12 +111,11 @@
unless attribute =~ /^_/
tag[attribute] = execute_ruby(tag, value)
else
case attribute
when "_use"
- @block_object = execute_ruby(tag, value)
- @tag_block = tag
+ tag.inner_html = render_block(tag, value)
when "_partial"
tag.inner_html = render_partial(tag, value)
when "_collection"
actions.delete_at(ndx)
render_collection(tag, value, actions.join(','))
@@ -120,14 +125,9 @@
when "_unless"
return if process_unless(tag, value)
end
end
end
- end
-
- if @tag_block == tag
- @tag_block = nil
- @block_object = nil
end
end
def process_if(tag, value)
contents = execute_ruby(tag, value)