./lib/jbuilder_template.rb in jbuilder-0.4.0 vs ./lib/jbuilder_template.rb in jbuilder-0.4.2
- old
+ new
@@ -5,15 +5,22 @@
def initialize(context)
@context = context
super()
end
-
- def partial!(partial_name, options = {})
- @context.render(partial_name, options.merge(:json => self))
+
+ def partial!(options, locals = {})
+ case options
+ when Hash
+ options[:locals] ||= {}
+ options[:locals].merge!(:json => self)
+ @context.render(options)
+ else
+ @context.render(options, locals.merge(:json => self))
+ end
end
-
+
private
def _new_instance
__class__.new(@context)
end
end
@@ -21,18 +28,13 @@
class JbuilderHandler
cattr_accessor :default_format
self.default_format = Mime::JSON
def self.call(template)
- %{
- if defined?(json)
- #{template.source}
- else
- JbuilderTemplate.encode(self) do |json|
- #{template.source}
- end
- end
- }
+
+ # this juggling is required to keep line numbers right in the error
+ %{__already_defined = defined?(json); json||=JbuilderTemplate.new(self); #{template.source}
+ json.target! unless __already_defined}
end
end
ActionView::Template.register_template_handler :jbuilder, JbuilderHandler