Add root option for collection

This commit is contained in:
ccocchi 2012-03-02 14:59:01 +01:00
parent 0011b57f8f
commit fbcbbd2328
2 changed files with 7 additions and 1 deletions

View File

@ -52,8 +52,8 @@ module RablFastJson
alias_method :code, :node
def collection(data, options = {})
@template.root_name = options[:root] if root_given?(options)
object(data)
@template.root_name = options[:root] if root_given?(options)
end
def extends(path)

View File

@ -103,6 +103,12 @@ class CompilerTest < ActiveSupport::TestCase
assert_equal :users, t.root_name
end
test "collection property can define root name via options" do
t = @compiler.compile_source(%{ collection :@user, :root => :users })
assert_equal :@user, t.data
assert_equal :users, t.root_name
end
test "extends use other template source as itself" do
template = mock('template', :source => { :id => :id })
RablFastJson::Library.reset_instance