Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
84 lines (72 sloc) 2.76 KB
require 'rake/clean'
require 'erb'
require 'BlueCloth'
LIBPATH = File.expand_path(File.dirname(__FILE__))
# builds and tests
desc 'writes lib/xui.js and lib/xui-min.js from src then launches specs'
task :default => :spec
desc 'writes out an uncompiled version of xui'
task :build do
require File.join(LIBPATH, 'util', 'sprockets', 'lib', 'sprockets')
secretary = => ['src/js/**'],
:source_files => ["src/js/xui.js"])
concatenation = secretary.concatenation
FileUtils.mkdir_p(File.join(LIBPATH, 'lib'))
desc 'creates lib/xui-min.js (tho not obfuscates)'
task :min => :build do
puts 'minifying js'
min_file = File.join(LIBPATH, 'lib', 'xui-min.js')
doc_file = File.join(LIBPATH, 'lib', 'xui.js')
yui_jar = File.join(LIBPATH, 'util', 'yuicompressor-2.3.6.jar')
sh "java -jar #{yui_jar} --charset UTF-8 -o #{min_file} #{doc_file}"
desc 'opens up the specs'
task :spec => :min do
puts 'running automated test suite'
spec_file = File.join(LIBPATH, 'spec', 'index.html')
sh "open -a WebKit file://#{spec_file}"
sh "open -a '/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone' file://#{spec_file}"
desc 'use JSLint to validate source code'
task :check => :build do
puts 'checking js for lint'
doc_file = File.join(LIBPATH, 'lib', 'xui.js')
rhino_jar = File.join(LIBPATH, 'util', 'js.jar')
jslint_file = File.join(LIBPATH, 'util', 'jslint.js')
sh "java -classpath #{rhino_jar} #{jslint_file} #{doc_file}"
# TODO open in MobileSafari, Fennec and MobileOpera
desc 'launches the semi official but seriously example app example'
task :example => :build do
example_file = File.join(LIBPATH, 'example', 'index.html')
sh "open -a WebKit #{example_file}"
# docs are inline to the code (as markdown)
desc 'bulds documentation from inline comments into'
task :doc => :build do
sauce =, 'lib', 'xui.js')).read
# fetches all multiline comments
comments = sauce.gsub( /\s+\/\/.*/,'' ).scan(/\/(?:\*(?:.)*?\*\/|\/[^\n]*)/m)
# removes comment debris
comments ={|r| r.gsub('*/','').gsub(/^\s+\* |\* |\/\*+|^\*|^\s+\*|^\s+\/\*+/, '')}
# build a readme
readme = comments.join("\n")
# write out the
open(File.join(LIBPATH, ''), 'w'){|f| f.puts(readme) }
# write out the doc/index.html
FileUtils.mkdir_p(File.join(LIBPATH, 'doc'))
index_file = File.join(LIBPATH, 'doc', 'index.html')
open(index_file, 'w') { |f| f.puts( }
# launch docs in safari
sh "open -a WebKit #{index_file}"
Something went wrong with that request. Please try again.