Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

39 lines (32 sloc) 0.765 kb
class JbuilderTemplate < Jbuilder
def self.encode(context)
new(context)._tap { |jbuilder| yield jbuilder }.target!
end
def initialize(context)
@context = context
super()
end
def partial!(partial_name, options = {})
@context.render(partial_name, options.merge(:json => self))
end
private
def _new_instance
__class__.new(@context)
end
end
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
}
end
end
ActionView::Template.register_template_handler :jbuilder, JbuilderHandler
Jump to Line
Something went wrong with that request. Please try again.