Class: Tilt::JsonitTemplate

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.engine_initialized?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/jsonit/tilt/tilt_jsonit.rb', line 6

def self.engine_initialized?
  defined? ::Jsonit
end

Instance Method Details

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



16
17
18
19
20
# File 'lib/jsonit/tilt/tilt_jsonit.rb', line 16

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

#initialize_engineObject



10
11
12
# File 'lib/jsonit/tilt/tilt_jsonit.rb', line 10

def initialize_engine
  require_template_library 'jsonit'
end

#precompiled_postamble(locals) ⇒ Object



26
27
28
# File 'lib/jsonit/tilt/tilt_jsonit.rb', line 26

def precompiled_postamble(locals)
  "\nend.to_json"
end

#precompiled_preamble(locals) ⇒ Object



22
23
24
# File 'lib/jsonit/tilt/tilt_jsonit.rb', line 22

def precompiled_preamble(locals)
  "\n#{super};::Jsonit::Builder.new do |json|"
end

#precompiled_template(locals) ⇒ Object



30
31
32
# File 'lib/jsonit/tilt/tilt_jsonit.rb', line 30

def precompiled_template(locals)
  data.to_str
end

#prepareObject



14
# File 'lib/jsonit/tilt/tilt_jsonit.rb', line 14

def prepare; end