Class: Tilt::YajlTemplate
Instance Attribute Summary
Attributes inherited from Template
#compiled_path, #data, #file, #line, #options
Instance Method Summary collapse
-
#decorate(json) ⇒ Object
Decorates the
jsoninput according to givenoptions. - #evaluate(scope, locals, &block) ⇒ Object
- #precompiled_postamble(locals) ⇒ Object
- #precompiled_preamble(locals) ⇒ Object
- #precompiled_template(locals) ⇒ Object
Methods inherited from Template
#basename, #compiled_method, default_mime_type, default_mime_type=, #eval_file, #fixed_locals?, #initialize, #metadata, metadata, #name, #render
Constructor Details
This class inherits a constructor from Tilt::Template
Instance Method Details
#decorate(json) ⇒ Object
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.
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/tilt/yajl.rb', line 78 def decorate(json) callback, variable = @options[:callback], @options[:variable] if callback && variable "var #{variable} = #{json}; #{callback}(#{variable});" elsif variable "var #{variable} = #{json};" elsif callback "#{callback}(#{json});" else json end end |
#evaluate(scope, locals, &block) ⇒ Object
55 56 57 |
# File 'lib/tilt/yajl.rb', line 55 def evaluate(scope, locals, &block) decorate(super) end |
#precompiled_postamble(locals) ⇒ Object
64 65 66 |
# File 'lib/tilt/yajl.rb', line 64 def precompiled_postamble(locals) "Yajl::Encoder.new.encode(json)" end |
#precompiled_preamble(locals) ⇒ Object
59 60 61 62 |
# File 'lib/tilt/yajl.rb', line 59 def precompiled_preamble(locals) return super if locals.include? :json "json = {}\n#{super}" end |
#precompiled_template(locals) ⇒ Object
68 69 70 |
# File 'lib/tilt/yajl.rb', line 68 def precompiled_template(locals) @data.to_str end |