Skip to content

Instantly share code, notes, and snippets.

@thurloat
Created February 3, 2011 01:41
Show Gist options
  • Save thurloat/808886 to your computer and use it in GitHub Desktop.
Save thurloat/808886 to your computer and use it in GitHub Desktop.
Aptana Javascript Ruble formatter. Replaces the JS Beautifier with Google's fixjsstyle script.
require 'ruble'
command "Reformat Document" do |cmd|
cmd.key_binding = "CTRL+ALT+COMMAND+F"
cmd.output = :replace_selection
cmd.input = :selection, :document
cmd.scope = "source.js"
cmd.invoke do
require 'open3'
require 'beautify2'
file_contents = Beautifier.new.js_beautify($stdin.read)
File.open('/tmp/test.js', 'w') do |f2|
f2.puts file_contents
end
sin, sout, serr = Open3.popen3('/usr/local/bin/fixjsstyle /tmp/test.js')
# Can outputting to the console. It's sorta annoying.
# STDERR.puts sout.readlines
File.open('/tmp/test.js', "r") do |fr|
puts fr.read
end
end
end
@acebone
Copy link

acebone commented Oct 18, 2011

Hi!
I've installed jsfixstyle on my Mac, but how do I tell Aptana to use it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment