Module: Jason
- Defined in:
- lib/jason.rb,
lib/jason/version.rb,
lib/jason/json_eruby.rb,
lib/jason/rails_template_handler.rb
Overview
Renders and compiles Jason templates.
Defined Under Namespace
Classes: JSONEruby, RailsTemplateHandler
Constant Summary collapse
- VERSION =
'0.3.1'
Class Method Summary collapse
-
.compile(template) ⇒ String
Compile a template.
-
.process(buffer)
Process a rendered buffer.
-
.render(template, binding = nil) ⇒ String
Render a template.
Class Method Details
.compile(template) ⇒ String
Compile a template.
Eval the returned value to render the template within the current binding.
31 32 33 |
# File 'lib/jason.rb', line 31 def self.compile(template) "#{eruby_template(template).src}; Jason.process(_buf)" end |
.process(buffer)
Process a rendered buffer.
Removes any trailing commas and compresses the buffer.
Usually, you should not have to call this method.
42 43 44 |
# File 'lib/jason.rb', line 42 def self.process(buffer) JSON.load(remove_trailing_commas(buffer)).to_json end |
.render(template, binding = nil) ⇒ String
Render a template.
15 16 17 18 19 20 21 22 23 |
# File 'lib/jason.rb', line 15 def self.render(template, binding = nil) if binding yaml = eruby_template(template).result(binding) else yaml = eruby_template(template).result end process(yaml) end |