Sha256: c7c83b2178865f70a600660c0b973229ba270ea54823dc6b7cc31f0d6debeea6

Contents?: true

Size: 754 Bytes

Versions: 1

Compression:

Stored size: 754 Bytes

Contents

require "jbuilder"

class JPbuilderHandler
  cattr_accessor :default_format, :default_callback
  self.default_format = Mime::JSON
  self.default_callback = nil

  def self.call(template)
    %{
      if defined?(json)
        #{template.source}
      else
        result = JbuilderTemplate.encode(self) do |json|
          #{template.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
        if callback.present?
          "/**/\#{callback}(\#{result});"
        else
          result
        end
      end
    }
  end
end

ActionView::Template.register_template_handler :jpbuilder, JPbuilderHandler

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jpbuilder-0.2.5 lib/jpbuilder-handler.rb