bin/lscript in liquidscript-0.7.1 vs bin/lscript in liquidscript-0.7.2

- old
+ new

@@ -8,16 +8,27 @@ end infile = ARGV.shift outfile = ARGV.shift || infile.gsub(/\.liq\Z/, ".js") -File.open(infile, "r") do |f| +if infile == '-' + infile = $stdin +else + infile = File.open(infile, "r") +end - begin - out = Liquidscript.compile(f.read) - File.open(outfile, "w") { |o| o.write out } - rescue StandardError => e +if outfile == '-' + outfile = $stdout +else + outfile = File.open(outfile, "w") +end + +begin + out = Liquidscript.compile(infile.read) + outfile.write(out) +rescue StandardError => e $stderr.puts "ERROR: #{e.class}: #{e.message}" $stderr.puts e.backtrace[0..5].map { |s| "\t#{s.gsub(/^.*?\/lib\/liquidscript\//, "")}" }.join("\n") - end - +ensure + [infile, outfile].each(&:close) end +