From 25cd124631d2b8e3495f4989b8bb8f15fc5cbb03 Mon Sep 17 00:00:00 2001 From: Tyler Rick Date: Sun, 22 Feb 2009 15:18:01 -0800 Subject: [PATCH] Added bin/beautify_js, which is a wrapper for rhino beautify-cl.js that also lets you supply input via standard input rather than suppyling a filename. This allows it to be used in vim as a filter command. --- bin/beautify_js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 bin/beautify_js diff --git a/bin/beautify_js b/bin/beautify_js new file mode 100755 index 000000000..14cbbbbb9 --- /dev/null +++ b/bin/beautify_js @@ -0,0 +1,53 @@ +#!/usr/bin/ruby + +def print_usage + puts <,!#{$0} + +Then you can simply type BeautifyJavascript to process the entire buffer or select a range of lines to only pass those lines through the filter. +End + exit +end + + +if STDIN.tty? + if ARGV.size >= 1 + # Get the absolute path of the filename given + require 'pathname' + path = Pathname.new(ARGV[0]).realpath.to_s + else + print_usage + end +else + # Assume they are piping the input in. Save that input in a temporary file and pass that file to beautify-cl.js + require 'tempfile' + file = Tempfile.new('beautify_js') + file.puts STDIN.read + file.close + path = file.path +end +#system "cat #{path}" + + +# Change directory so that the load() calls in beautify-cl.js are able to find the files they need +Dir.chdir File.dirname(__FILE__) +Dir.chdir '..' +#puts Dir.getwd + + +command = "rhino beautify-cl.js '#{path}' 2>&1" +#puts command +#output = `#{command}` +system command +