Skip to content

Instantly share code, notes, and snippets.

@timruffles
Created February 18, 2011 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timruffles/833995 to your computer and use it in GitHub Desktop.
Save timruffles/833995 to your computer and use it in GitHub Desktop.
a little Textmate command to take a lot of typing out of require.js
#!/usr/bin/ruby
require 'pathname'
proj_dir = Pathname.new(ENV['TM_PROJECT_DIRECTORY'])
file_path = Pathname.new(ENV['TM_FILEPATH'])
path = file_path.relative_path_from(proj_dir).to_s
module_name = path.gsub(/\.js$/,'')
class_name = (module_name.split('/').last.capitalize.gsub(/_(\w)/) {|str| $1.upcase})
puts "define('#{module_name}',[],function() {
var #{class_name} = function() {
$1
}
#{class_name}.prototype = {
}
return #{class_name}
})"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment