11require 'rake'
22require 'rake/packagetask'
3+ require 'rbconfig'
34require 'yaml'
45
56module PrototypeHelper
67 extend Rake ::DSL
7-
8+
89 ROOT_DIR = File . expand_path ( File . dirname ( __FILE__ ) )
910 SRC_DIR = File . join ( ROOT_DIR , 'src' )
1011 DIST_DIR = File . join ( ROOT_DIR , 'dist' )
@@ -15,9 +16,12 @@ module PrototypeHelper
1516 TEST_UNIT_DIR = File . join ( TEST_DIR , 'unit' )
1617 TMP_DIR = File . join ( TEST_UNIT_DIR , 'tmp' )
1718 VERSION = YAML . load ( IO . read ( File . join ( SRC_DIR , 'constants.yml' ) ) ) [ 'PROTOTYPE_VERSION' ]
18-
19+
1920 DEFAULT_SELECTOR_ENGINE = 'sizzle'
20-
21+
22+ host = RbConfig ::CONFIG [ 'host' ]
23+ IS_WINDOWS = host . include? ( 'mswin' ) || host . include? ( 'mingw32' )
24+
2125 # Possible options for PDoc syntax highlighting, in order of preference.
2226 SYNTAX_HIGHLIGHTERS = [ :pygments , :coderay , :none ]
2327
@@ -33,7 +37,7 @@ module PrototypeHelper
3337 return false
3438 end
3539 end
36-
40+
3741 def self . require_git
3842 return if has_git?
3943 puts "\n Prototype requires Git in order to load its dependencies."
@@ -42,30 +46,30 @@ module PrototypeHelper
4246 puts " http://book.git-scm.com/2_installing_git.html"
4347 exit
4448 end
45-
49+
4650 def self . sprocketize ( options = { } )
4751 options = {
4852 :destination => File . join ( DIST_DIR , options [ :source ] ) ,
4953 :strip_comments => true
5054 } . merge ( options )
51-
55+
5256 require_sprockets
5357 load_path = [ SRC_DIR ]
54-
58+
5559 if selector_path = get_selector_engine ( options [ :selector_engine ] )
5660 load_path << selector_path
5761 end
58-
62+
5963 secretary = Sprockets ::Secretary . new (
6064 :root => File . join ( ROOT_DIR , options [ :path ] ) ,
6165 :load_path => load_path ,
6266 :source_files => [ options [ :source ] ] ,
6367 :strip_comments => options [ :strip_comments ]
6468 )
65-
69+
6670 secretary . concatenation . save_to ( options [ :destination ] )
6771 end
68-
72+
6973 def self . build_doc_for ( file )
7074 rm_rf ( DOC_DIR )
7175 mkdir_p ( DOC_DIR )
98102 :assets => 'doc_assets'
99103 } )
100104 end
101-
105+
102106 def self . require_package ( name )
103107 begin
104108 require name
@@ -108,26 +112,27 @@ EOF
108112 exit
109113 end
110114 end
111-
115+
112116 def self . require_phantomjs
113- success = system ( "phantomjs -v > /dev/null 2>&1" )
117+ cmd = IS_WINDOWS ? "phantomjs.cmd -v" : "phantomjs -v > /dev/null 2>&1"
118+ success = system ( cmd )
114119 if !success
115120 puts "\n You need phantomjs installed to run this task. Find out how at:"
116121 puts " http://phantomjs.org/download.html"
117122 exit
118123 end
119124 end
120-
125+
121126 def self . syntax_highlighter
122127 if ENV [ 'SYNTAX_HIGHLIGHTER' ]
123128 highlighter = ENV [ 'SYNTAX_HIGHLIGHTER' ] . to_sym
124129 require_highlighter ( highlighter , true )
125130 return highlighter
126131 end
127-
132+
128133 SYNTAX_HIGHLIGHTERS . detect { |n | require_highlighter ( n ) }
129134 end
130-
135+
131136 def self . require_highlighter ( name , verbose = false )
132137 case name
133138 when :pygments
@@ -160,42 +165,42 @@ EOF
160165 exit
161166 end
162167 end
163-
168+
164169 def self . require_sprockets
165170 require_submodule ( 'Sprockets' , 'sprockets' )
166171 end
167-
172+
168173 def self . require_pdoc
169174 require_submodule ( 'PDoc' , 'pdoc' )
170175 end
171-
176+
172177 def self . require_unittest_js
173178 require_submodule ( 'UnittestJS' , 'unittest_js' )
174179 end
175-
180+
176181 def self . require_caja_builder
177182 require_submodule ( 'CajaBuilder' , 'caja_builder' )
178183 end
179-
184+
180185 def self . get_selector_engine ( name )
181186 return if !name
182187 # If the submodule exists, we should use it.
183188 submodule_path = File . join ( ROOT_DIR , "vendor" , name )
184189 return submodule_path if File . exist? ( File . join ( submodule_path , "repository" , ".git" ) )
185190 return submodule_path if name === "legacy_selector"
186-
191+
187192 # If it doesn't exist, we should fetch it.
188193 get_submodule ( 'the required selector engine' , "#{ name } /repository" )
189194 unless File . exist? ( submodule_path )
190195 puts "The selector engine you required isn't available at vendor/#{ name } .\n \n "
191196 exit
192197 end
193198 end
194-
199+
195200 def self . get_submodule ( name , path )
196201 require_git
197202 puts "\n You seem to be missing #{ name } . Obtaining it via git...\n \n "
198-
203+
199204 Kernel . system ( "git submodule init" )
200205 return true if Kernel . system ( "git submodule update vendor/#{ path } " )
201206 # If we got this far, something went wrong.
204209 puts " $ git submodule update vendor/#{ path } "
205210 false
206211 end
207-
212+
208213 def self . require_submodule ( name , path )
209214 begin
210215 require path
225230 exit
226231 end
227232 end
228-
233+
229234 def self . current_head
230235 `git show-ref --hash HEAD` . chomp [ 0 ..6 ]
231236 end
@@ -247,7 +252,7 @@ namespace :doc do
247252 task :build => [ :require ] do
248253 PrototypeHelper . build_doc_for ( ENV [ 'SECTION' ] ? "#{ ENV [ 'SECTION' ] } .js" : 'prototype.js' )
249254 end
250-
255+
251256 task :require do
252257 PrototypeHelper . require_pdoc
253258 end
@@ -282,30 +287,30 @@ namespace :test do
282287 task :start => [ :require ] do
283288 path_to_app = File . join ( PrototypeHelper ::ROOT_DIR , 'test' , 'unit' , 'server.rb' )
284289 require path_to_app
285-
290+
286291 puts "Starting unit test server..."
287292 puts "Unit tests available at <http://127.0.0.1:4567/test/>\n \n "
288293 UnitTests . run!
289294 end
290-
295+
291296 task :require do
292297 PrototypeHelper . require_package ( 'sinatra' )
293298 end
294-
299+
295300 desc "Opens the test suite in several different browsers. (Does not start or stop the server; you should do that separately.)"
296301 task :run => [ :require ] do
297302 browsers , tests , grep = ENV [ 'BROWSERS' ] , ENV [ 'TESTS' ] , ENV [ 'GREP' ]
298303 path_to_runner = File . join ( PrototypeHelper ::ROOT_DIR , 'test' , 'unit' , 'runner.rb' )
299304 require path_to_runner
300-
305+
301306 Runner ::run ( browsers , tests , grep )
302307 end
303-
308+
304309 task :phantom => [ :require ] do
305310 PrototypeHelper . require_phantomjs
306311 tests , grep = ENV [ 'TESTS' ] , ENV [ 'GREP' ]
307312 url = "http://127.0.0.1:4567/test/#{ tests } "
308313 url << "?grep=#{ grep } " if grep
309- system ( %Q[phantomjs ./test.new /phantomjs/mocha-phantomjs.js "#{ url } "] )
314+ system ( %Q[phantomjs ./test/unit /phantomjs/mocha-phantomjs.js "#{ url } "] )
310315 end
311316end
0 commit comments