lib/jason.rb in jason-0.1.0 vs lib/jason.rb in jason-0.2.0
- old
+ new
@@ -1,31 +1,45 @@
-require 'erb'
+require 'ember'
require 'json'
require 'yaml'
# Renders and compiles Jason templates.
module Jason
# Render a template.
#
# @example
# Jason.render('foo: bar') # => '{"foo": "bar"}'
#
- # @param template [String] the template to render
- # @param binding [Binding] the binding to render the template in
+ # @param [String] template the template to render
+ # @param [Binding] binding the binding to render the template in
# @return [String] the rendered template
def self.render(template, binding = nil)
- yaml = ERB.new(template).result(binding)
+ if binding
+ yaml = ember_template(template).render(binding)
+ else
+ yaml = ember_template(template).render
+ end
+
YAML::load(yaml).to_json
end
# Compile a template.
#
# Eval the returned value to render the template within the current binding.
#
- # @param template [String] the template to compile
+ # @param [String] template the template to compile
# @return [String] the compiled template
def self.compile(template)
- "#{ERB.new(template).src}; YAML::load(_erbout).to_json"
+ "YAML::load(#{ember_template(template).program}).to_json"
+ end
+
+ private
+
+ def self.ember_template(template)
+ Ember::Template.new(template,
+ :unindent => true,
+ :infer_end => true,:shorthand => true
+ )
end
end
require 'jason/version'
\ No newline at end of file