Add full template stack support. Closes #20

This commit is contained in:
ccocchi 2013-01-19 16:46:33 +01:00
parent 0761830988
commit 8c35a24408
4 changed files with 21 additions and 3 deletions

View File

@ -1,5 +1,8 @@
# CHANGELOG
## 0.3.1
* Add full template stack support to `glue` (fnordfish)
## 0.3.0
* Travis integration
* Add test for keywords used as variable names

View File

@ -70,9 +70,7 @@ module RablRails
end
if key.to_s.start_with?('_') # glue
current_value.each_pair { |k, v|
output[k] = object.send(v)
}
output.merge!(render_resource(object, current_value))
next output
else # child
object.respond_to?(:each) ? render_collection(object, current_value) : render_resource(object, current_value)

View File

@ -132,6 +132,18 @@ class CompilerTest < ActiveSupport::TestCase
}, t.source)
end
test "glue accepts all dsl in its body" do
t = @compiler.compile_source(%{
glue :@user do node(:foo) { |u| u.name } end
})
assert_not_nil(t.source[:_glue0])
s = t.source[:_glue0]
assert_equal(:@user, s[:_data])
assert_instance_of(Proc, s[:foo])
end
test "extends use other template source as itself" do
template = mock('template', :source => { :id => :id })
RablRails::Library.reset_instance

View File

@ -61,6 +61,11 @@ class TestJsonRenderer < ActiveSupport::TestCase
assert_equal %q({"name":"foobar"}), render_json_output
end
test "render glued node" do
@template.source = { :_glue0 => { :_data => :@data, :foo => lambda { |u| u.name } } }
assert_equal(%q({"foo":"foobar"}), render_json_output)
end
test "render collection with attributes" do
@data = [User.new(1, 'foo', 'male'), User.new(2, 'bar', 'female')]
@context.assigns['data'] = @data