Sha256: cd622512f550650afcbe5fc1b2c8e59e34a3a48dbe178b74ab46089d15138af7
Contents?: true
Size: 1.12 KB
Versions: 7
Compression:
Stored size: 1.12 KB
Contents
module JellyController protected include Jelly::Common def jelly_callback(callback_base_name = @action_name, options = {}, &block) raw_jelly_callback(options) do arguments = block ? instance_eval(&block) : [] arguments = [arguments] unless arguments.is_a?(Array) jelly_notify_hash("on_#{callback_base_name}", *arguments).merge(options) end end def raw_jelly_callback(options={}, &block) options.symbolize_keys! options[:format] ||= if params[:callback] :jsonp elsif request.xhr? :json else :iframe end render :inline => jelly_callback_erb(options, &block) end def jelly_callback_erb(options={}, &block) options[:format] ||= :json @jelly_block = block case options[:format].to_sym when :iframe "<textarea>#{jelly_callback_erb_template}</textarea>" when :jsonp "#{params[:callback]}(#{jelly_callback_erb_template});" else jelly_callback_erb_template end end def jelly_callback_erb_template %Q{<%= instance_eval(&controller.instance_variable_get(:@jelly_block)).to_json.html_safe %>} end end
Version data entries
7 entries across 7 versions & 1 rubygems