2009-12-18 09:55:31 -05:00
|
|
|
require 'erb'
|
2009-12-18 06:59:06 -05:00
|
|
|
require 'fileutils'
|
|
|
|
require 'rake/testtask'
|
2010-02-24 19:57:29 -05:00
|
|
|
require 'rubygems'
|
2010-09-21 08:02:22 -04:00
|
|
|
require 'closure-compiler'
|
2009-12-18 06:59:06 -05:00
|
|
|
|
2010-06-01 22:09:00 -04:00
|
|
|
HEADER = <<-EOS
|
|
|
|
/**
|
2010-09-21 23:58:05 -04:00
|
|
|
* CoffeeScript Compiler v0.9.4
|
2010-06-01 22:09:00 -04:00
|
|
|
* http://coffeescript.org
|
|
|
|
*
|
|
|
|
* Copyright 2010, Jeremy Ashkenas
|
|
|
|
* Released under the MIT License
|
|
|
|
*/
|
|
|
|
EOS
|
|
|
|
|
2009-12-18 09:55:31 -05:00
|
|
|
desc "Build the documentation page"
|
|
|
|
task :doc do
|
2009-12-19 22:55:58 -05:00
|
|
|
source = 'documentation/index.html.erb'
|
2010-07-29 00:51:35 -04:00
|
|
|
child = fork { exec "bin/coffee --no-wrap -cw -o documentation/js documentation/coffee/*.coffee" }
|
2009-12-21 12:15:13 -05:00
|
|
|
at_exit { Process.kill("INT", child) }
|
|
|
|
Signal.trap("INT") { exit }
|
2009-12-19 22:55:58 -05:00
|
|
|
loop do
|
|
|
|
mtime = File.stat(source).mtime
|
|
|
|
if !@mtime || mtime > @mtime
|
|
|
|
rendered = ERB.new(File.read(source)).result(binding)
|
|
|
|
File.open('index.html', 'w+') {|f| f.write(rendered) }
|
|
|
|
end
|
|
|
|
@mtime = mtime
|
|
|
|
sleep 1
|
|
|
|
end
|
2009-12-18 09:55:31 -05:00
|
|
|
end
|
2010-02-24 19:57:29 -05:00
|
|
|
|
|
|
|
desc "Build the single concatenated and minified script for the browser"
|
|
|
|
task :browser do
|
2010-09-21 05:19:49 -04:00
|
|
|
sources = %w(helpers rewriter lexer parser scope nodes coffee-script browser)
|
|
|
|
code = sources.inject '' do |js, name|
|
|
|
|
js << <<-"JS"
|
|
|
|
require['./#{name}'] = new function(){
|
|
|
|
var exports = this;
|
|
|
|
#{ File.read "lib/#{name}.js" }
|
|
|
|
}
|
|
|
|
JS
|
|
|
|
end
|
2010-09-21 08:02:22 -04:00
|
|
|
code = Closure::Compiler.new.compress(<<-"JS")
|
2010-09-21 05:19:49 -04:00
|
|
|
this.CoffeeScript = function(){
|
|
|
|
function require(path){ return require[path] }
|
|
|
|
#{ code }
|
|
|
|
return require['./coffee-script']
|
|
|
|
}()
|
|
|
|
JS
|
|
|
|
File.open('extras/coffee-script.js', 'wb+') {|f| f.write(HEADER + code) }
|
2010-02-24 19:57:29 -05:00
|
|
|
end
|