Sha256: cbc456e45332e140bacbbd4e300145d7f1bda60deb7d69cbfd6d0bd3d0a183e8

Contents?: true

Size: 903 Bytes

Versions: 1

Compression:

Stored size: 903 Bytes

Contents

require 'tilt'
require 'tilt/template'

module Tilt
   # Builder template implementation. See:
  # http://builder.rubyforge.org/
  class JsonifyTemplate < 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

Tilt.register Tilt::JsonifyTemplate, 'jsonify'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jsonify-0.1.0 lib/tilt/jsonify_template.rb