Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/jpbuilder-handler.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

class JPbuilderHandler
cattr_accessor :default_format, :default_callback
self.default_format = Mime[:json]
self.default_callback = nil

def initialize
self.default_callback = nil
self.default_format = (Rails.version < '6.0.0') ? Mime[:json] : :json
end

def self.call(template)
def self.call(template, source=nil)
source =|| template.source

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
source =|| template.source
source ||= template.source

%{
if defined?(json)
#{template.source}
#{source}
else
result = JbuilderTemplate.encode(self) do |json|
#{template.source}
#{source}
end
result = result.each_char.to_a.map { |chr| chr.ord > 1000 ? "\\\\u\#{"%4.4x" % chr.ord}" : chr }.join
callback = params[:callback] || JPbuilderHandler.default_callback
Expand Down