class Tilt::YajlTemplate

  1. lib/tilt/yajl.rb
Superclass: Template

Public Instance methods

decorate(json)

Decorates the json input according to given options.

json - The json String to decorate. options - The option Hash to customize the behavior.

Returns the decorated String.

[show source]
   # File lib/tilt/yajl.rb
78 def decorate(json)
79   callback, variable = @options[:callback], @options[:variable]
80   if callback && variable
81     "var #{variable} = #{json}; #{callback}(#{variable});"
82   elsif variable
83     "var #{variable} = #{json};"
84   elsif callback
85     "#{callback}(#{json});"
86   else
87     json
88   end
89 end
evaluate(scope, locals, &block)
[show source]
   # File lib/tilt/yajl.rb
55 def evaluate(scope, locals, &block)
56   decorate(super)
57 end
precompiled_postamble(locals)
[show source]
   # File lib/tilt/yajl.rb
64 def precompiled_postamble(locals)
65   "Yajl::Encoder.new.encode(json)"
66 end
precompiled_preamble(locals)
[show source]
   # File lib/tilt/yajl.rb
59 def precompiled_preamble(locals)
60   return super if locals.include? :json
61   "json = {}\n#{super}"
62 end
precompiled_template(locals)
[show source]
   # File lib/tilt/yajl.rb
68 def precompiled_template(locals)
69   @data.to_str
70 end