Skip to content

Instantly share code, notes, and snippets.

@douglasback
Forked from mnelson/application.json.jbuilder
Created December 20, 2013 19:36
Show Gist options
  • Save douglasback/8060146 to your computer and use it in GitHub Desktop.
Save douglasback/8060146 to your computer and use it in GitHub Desktop.
raw_content = JSON.parse(yield)
json.content raw_content
json.jsonp! params[:callback] if jsonp?
Mime::EXTENSION_LOOKUP['jsonp'] = Mime::Type.lookup_by_extension('json')
require 'jbuilder'
module Jsonp::Jbuilder
extend ActiveSupport::Concern
included do
alias_method_chain :target!, :jsonp
end
def jsonp!(callback_name)
@jsonp_callback = callback_name
end
def target_with_jsonp!
json = target_without_jsonp!
if @jsonp_callback
"#{@jsonp_callback}(#{json})"
else
json
end
end
end
::Jbuilder.send :include, Jsonp::Jbuilder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment