lib/ruhl.rb in ruhl-0.8.1 vs lib/ruhl.rb in ruhl-0.8.2

- old
+ new

@@ -23,11 +23,11 @@ end def render(current_scope) set_scope(current_scope) - parse_doc(@document) + parse_doc(document) if @layout render_with_layout else document.to_s @@ -52,13 +52,14 @@ file = execute_ruby(tag, code) raise PartialNotFoundError.new(file) unless File.exists?(file) render_file( File.read(file) ) end - def render_collection(tag, code) + def render_collection(tag, code, actions = nil) results = execute_ruby(tag, code) + tag['data-ruhl'] = actions if actions.to_s.strip.length > 0 html = tag.to_html new_content = results.collect do |item| Ruhl::Engine.new(html, :local_object => item).render(scope) end.to_s @@ -71,11 +72,11 @@ parse_doc(doc) doc.to_s end def parse_doc(doc) - if (nodes = doc.xpath('//*[@data-ruhl][1]')).empty? + if (nodes = doc.xpath('*[@data-ruhl][1]')).empty? nodes = doc.search('*[@data-ruhl]') end return if nodes.empty? @@ -84,11 +85,12 @@ process_attribute(tag, code.value) parse_doc(doc) end def process_attribute(tag, code) - code.split(',').each do |pair| + actions = code.split(',') + actions.dup.each_with_index do |pair, ndx| attribute, value = pair.split(':') if value.nil? tag.inner_html = execute_ruby(tag, attribute.strip) else @@ -96,11 +98,13 @@ case attribute when "_partial" tag.inner_html = render_partial(tag, value) when "_collection" - render_collection(tag, value) + actions.delete_at(ndx) + render_collection(tag, value, actions.join(',')) + return when "_if" return unless process_if(tag, value) when "_unless" return if process_unless(tag, value) else @@ -139,9 +143,18 @@ scope.send(code, tag) end else _render_ end + rescue NoMethodError => e + puts <<CONTEXT +Context: + tag : #{tag.inspect} + code : #{code.inspect} + local_object : #{local_object.inspect} + scope : #{scope.inspect} +CONTEXT + raise e end def set_scope(current_scope) raise Ruhl::NoScopeError unless current_scope @scope = current_scope