lib/kumogata/client.rb in kumogata-0.4.18 vs lib/kumogata/client.rb in kumogata-0.4.19
- old
+ new
@@ -39,22 +39,25 @@
output_format = case @options.format || guess_format(path_or_url)
when :ruby then :json
when :json then :ruby
when :yaml then :json
when :js then :json
+ when :json5 then :json
end
end
case output_format
when :ruby
devaluate_template(template).chomp.colorize_as(:ruby)
- when :json
+ when :json, :json5
JSON.pretty_generate(template).colorize_as(:json)
when :yaml
YAML.dump(template).colorize_as(:yaml)
when :js
'(' + JSON.pretty_generate(template).colorize_as(:json) + ')'
+ when :coffee
+ raise 'Output to CoffeeScript is not implemented'
end
end
def update(path_or_url, stack_name)
validate_stack_name(stack_name)
@@ -172,10 +175,21 @@
unless obj.instance_of?(V8::Object)
raise "Invalid JavaScript template. Please return Object: #{path_or_url}"
end
Kumogata::Utils.stringify(obj.to_hash)
+ when :coffee
+ completed = CoffeeScript.compile(f.read)
+ obj = V8::Context.new.eval(completed)
+
+ unless obj.instance_of?(V8::Object)
+ raise "Invalid CoffeeScript template. Please return Object: #{path_or_url}"
+ end
+
+ Kumogata::Utils.stringify(obj.to_hash)
+ when :json5
+ JSON5.parse(f.read)
else
raise "Unknown format: #{format}"
end
end
@@ -194,9 +208,13 @@
:json
when '.yml', '.yaml'
:yaml
when '.js'
:js
+ when '.coffee'
+ :coffee
+ when '.json5'
+ :json5
else
:json
end
end