Sha256: e0012351fea29707001f992eb70ad119495a510106c63944f0e78cb226d6fa33

Contents?: true

Size: 744 Bytes

Versions: 8

Compression:

Stored size: 744 Bytes

Contents

module Jsonify

  class Template < Tilt::Template
    self.default_mime_type = 'application/json'

    def self.engine_initialized?
      defined? ::Jsonify
    end

    def initialize_engine
      require_template_library 'jsonify'
    end

    def prepare; end

    def evaluate(scope, locals, &block)
      return super(scope, locals, &block) if data.respond_to?(:to_str)
      json = ::Jsonify::Builder.new
      data.call(json)
      json.compile!
    end

    def precompiled_preamble(locals)
      return super if locals.include? :json
      "json = ::Jsonify::Builder.new\n#{super}"
    end

    def precompiled_postamble(locals)
      "json.compile!"
    end

    def precompiled_template(locals)
      data.to_str
    end
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
jsonify-0.4.1 lib/jsonify/template.rb
jsonify-0.4.0 lib/jsonify/template.rb
jsonify-0.3.1 lib/jsonify/template.rb
jsonify-0.3.0 lib/jsonify/template.rb
jsonify-0.2.0 lib/jsonify/template.rb
jsonify-0.1.3 lib/jsonify/template.rb
jsonify-0.1.2 lib/jsonify/template.rb
jsonify-0.1.1 lib/jsonify/template.rb