Class: Tilt::JbuilderTemplate

Inherits:
Template
  • Object
show all
Defined in:
lib/tilt/jbuilder.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.engine_initialized?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/tilt/jbuilder.rb', line 34

def self.engine_initialized?
  defined? ::Jbuilder
end

Instance Method Details

#evaluate(scope, locals, &block) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/tilt/jbuilder.rb', line 44

def evaluate(scope, locals, &block)
  scope ||= Object.new
  context = scope.instance_eval { binding }
  set_locals(locals, scope, context)
  klass = ::Tilt::Jbuilder
  eval %{
    if defined? json
      if @_tilt_data.kind_of? Proc
        return @_tilt_data.call(klass.new(scope))
      else
        eval @_tilt_data, binding
      end
    else
      klass.encode(scope) do |json|
        if @_tilt_data.kind_of? Proc
          return @_tilt_data.call(klass.new(scope))
        else
          eval @_tilt_data, binding
        end
      end
    end
  }, context
end

#initialize_engineObject



38
39
40
# File 'lib/tilt/jbuilder.rb', line 38

def initialize_engine
  require_template_library 'jbuilder'
end

#prepareObject



42
# File 'lib/tilt/jbuilder.rb', line 42

def prepare; end