lib/jason.rb in jason-0.3.1 vs lib/jason.rb in jason-0.4.0
- old
+ new
@@ -2,10 +2,24 @@
require 'json'
require 'strscan'
# Renders and compiles Jason templates.
module Jason
+ class << self
+ attr_writer :output_format
+
+ # The output format of the JSON.
+ #
+ # I suggest using `:pretty` for development and testing and `:compact` for
+ # production.
+ #
+ # @returns [:pretty, :compact]
+ def output_format
+ @output_format ||= :compact
+ end
+ end
+
# Render a template.
#
# @example
# Jason.render('foo: bar') # => '{"foo": "bar"}'
#
@@ -38,10 +52,16 @@
#
# Usually, you should not have to call this method.
#
# @param [String] buffer
def self.process(buffer)
- JSON.load(remove_trailing_commas(buffer)).to_json
+ obj = JSON.load(remove_trailing_commas(buffer))
+
+ if output_format == :pretty
+ JSON.pretty_generate(obj)
+ else
+ JSON.generate(obj)
+ end
end
private
def self.eruby_template(template)
\ No newline at end of file