Remove useless &block and use yield instead
This commit is contained in:
parent
7767a708df
commit
f9e2f0766b
@ -18,15 +18,6 @@ module RablFastJson
|
||||
@template
|
||||
end
|
||||
|
||||
#
|
||||
# Same as compile_source but from a block
|
||||
#
|
||||
def compile_block(&block)
|
||||
@template = {}
|
||||
instance_eval(&block)
|
||||
@template
|
||||
end
|
||||
|
||||
#
|
||||
# Sets the object to be used as the data for the template
|
||||
# Example:
|
||||
@ -78,14 +69,14 @@ module RablFastJson
|
||||
# child(:@posts, :root => :posts) { attribute :id }
|
||||
# child(:posts, :partial => 'posts/base')
|
||||
#
|
||||
def child(name_or_data, options = {}, &block)
|
||||
def child(name_or_data, options = {})
|
||||
data, name = extract_data_and_name(name_or_data)
|
||||
name = options[:root] if options[:root]
|
||||
if options[:partial]
|
||||
template = Library.instance.get(options[:partial])
|
||||
@template[name] = template.merge!(:_data => data)
|
||||
else
|
||||
_compile_sub_template(name, data, &block)
|
||||
elsif block_given?
|
||||
@template[name] = sub_compile(data) { yield }
|
||||
end
|
||||
end
|
||||
|
||||
@ -94,11 +85,11 @@ module RablFastJson
|
||||
# Example:
|
||||
# glue(:@user) { attribute :name }
|
||||
#
|
||||
def glue(data, &block)
|
||||
def glue(data)
|
||||
return unless block_given?
|
||||
name = :"_glue#{@glue_count}"
|
||||
@glue_count += 1
|
||||
_compile_sub_template(name, data, &block)
|
||||
@template[name] = sub_compile(data) { yield }
|
||||
end
|
||||
|
||||
#
|
||||
@ -157,10 +148,13 @@ module RablFastJson
|
||||
end
|
||||
end
|
||||
|
||||
def _compile_sub_template(name, data, &block) #:nodoc:
|
||||
compiler = Compiler.new
|
||||
template = compiler.compile_block(&block)
|
||||
@template[name] = template.merge!(:_data => data)
|
||||
def sub_compile(data)
|
||||
return {} unless block_given?
|
||||
old_template, @template = @template, {}
|
||||
yield
|
||||
@template.merge!(:_data => data)
|
||||
ensure
|
||||
@template = old_template
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user