Add full template stack support. Closes #20
This commit is contained in:
parent
0761830988
commit
8c35a24408
@ -1,5 +1,8 @@
|
|||||||
# CHANGELOG
|
# CHANGELOG
|
||||||
|
|
||||||
|
## 0.3.1
|
||||||
|
* Add full template stack support to `glue` (fnordfish)
|
||||||
|
|
||||||
## 0.3.0
|
## 0.3.0
|
||||||
* Travis integration
|
* Travis integration
|
||||||
* Add test for keywords used as variable names
|
* Add test for keywords used as variable names
|
||||||
|
@ -70,9 +70,7 @@ module RablRails
|
|||||||
end
|
end
|
||||||
|
|
||||||
if key.to_s.start_with?('_') # glue
|
if key.to_s.start_with?('_') # glue
|
||||||
current_value.each_pair { |k, v|
|
output.merge!(render_resource(object, current_value))
|
||||||
output[k] = object.send(v)
|
|
||||||
}
|
|
||||||
next output
|
next output
|
||||||
else # child
|
else # child
|
||||||
object.respond_to?(:each) ? render_collection(object, current_value) : render_resource(object, current_value)
|
object.respond_to?(:each) ? render_collection(object, current_value) : render_resource(object, current_value)
|
||||||
|
@ -132,6 +132,18 @@ class CompilerTest < ActiveSupport::TestCase
|
|||||||
}, t.source)
|
}, t.source)
|
||||||
end
|
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
|
test "extends use other template source as itself" do
|
||||||
template = mock('template', :source => { :id => :id })
|
template = mock('template', :source => { :id => :id })
|
||||||
RablRails::Library.reset_instance
|
RablRails::Library.reset_instance
|
||||||
|
@ -61,6 +61,11 @@ class TestJsonRenderer < ActiveSupport::TestCase
|
|||||||
assert_equal %q({"name":"foobar"}), render_json_output
|
assert_equal %q({"name":"foobar"}), render_json_output
|
||||||
end
|
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
|
test "render collection with attributes" do
|
||||||
@data = [User.new(1, 'foo', 'male'), User.new(2, 'bar', 'female')]
|
@data = [User.new(1, 'foo', 'male'), User.new(2, 'bar', 'female')]
|
||||||
@context.assigns['data'] = @data
|
@context.assigns['data'] = @data
|
||||||
|
Loading…
Reference in New Issue
Block a user