lib/kumogata/client.rb in kumogata-0.4.17 vs lib/kumogata/client.rb in kumogata-0.4.18

- old
+ new

@@ -38,20 +38,23 @@ unless output_format 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 end end case output_format when :ruby devaluate_template(template).chomp.colorize_as(:ruby) when :json JSON.pretty_generate(template).colorize_as(:json) when :yaml YAML.dump(template).colorize_as(:yaml) + when :js + '(' + JSON.pretty_generate(template).colorize_as(:json) + ')' end end def update(path_or_url, stack_name) validate_stack_name(stack_name) @@ -161,10 +164,18 @@ when :json JSON.parse(f.read) when :yaml parsed = YAML.load(f.read) Kumogata::Utils.stringify(parsed) + when :js + obj = V8::Context.new.eval(f.read) + + unless obj.instance_of?(V8::Object) + raise "Invalid JavaScript template. Please return Object: #{path_or_url}" + end + + Kumogata::Utils.stringify(obj.to_hash) else raise "Unknown format: #{format}" end end @@ -177,13 +188,15 @@ def guess_format(path_or_url) case File.extname(path_or_url) when '.rb' :ruby - when '.json', '.js' + when '.json' :json when '.yml', '.yaml' :yaml + when '.js' + :js else :json end end