Sha256: af856ca0ba00affb75d5c44b5d1bf9d4ab0506d5002ea77690b7b117f279fffe

Contents?: true

Size: 765 Bytes

Versions: 7

Compression:

Stored size: 765 Bytes

Contents

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

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/jbuilder-0.4.0/lib/jbuilder_template.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/jbuilder-0.4.0/lib/jbuilder_template.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/jbuilder-0.4.0/lib/jbuilder_template.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/jbuilder-0.4.0/lib/jbuilder_template.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/jbuilder-0.4.0/lib/jbuilder_template.rb
jbuilder-0.4.0 ./lib/jbuilder_template.rb
jbuilder-0.3.2 ./lib/jbuilder_template.rb