class Handlebars::Helpers::Json::AsJson
AsJson
will take handlebars object and write it out as JSON
Public Instance Methods
handlebars_helper()
click to toggle source
# File lib/handlebars/helpers/json/as_json.rb, line 32 def handlebars_helper proc do |_context, value| # Handle optional: value # value = nil if value.is_a?(V8::Object) wrapper(parse(value)) end end
parse(value)
click to toggle source
Parse will take a ruby or handlebars object and write it out as JSON
@example
puts AsJson.new.parse({david: "was here", why: ['reason1', 'reason2', 'reason3']}) { "david": "was here", "why": ['reason1', 'reason2', 'reason3'] }
@param [Object] value - object to be converted to JSON string @return [String] value as JSON string
# File lib/handlebars/helpers/json/as_json.rb, line 24 def parse(value) value = '' if value.nil? value = parse_json(value).to_json if value.is_a?(Hash) || value.is_a?(OpenStruct) || value.is_a?(V8::Object) || value.is_a?(V8::Array) value end