@@ -4,7 +4,7 @@ require 'yaml'
44
55module PrototypeHelper
66 extend Rake ::DSL
7-
7+
88 ROOT_DIR = File . expand_path ( File . dirname ( __FILE__ ) )
99 SRC_DIR = File . join ( ROOT_DIR , 'src' )
1010 DIST_DIR = File . join ( ROOT_DIR , 'dist' )
@@ -15,9 +15,9 @@ module PrototypeHelper
1515 TEST_UNIT_DIR = File . join ( TEST_DIR , 'unit' )
1616 TMP_DIR = File . join ( TEST_UNIT_DIR , 'tmp' )
1717 VERSION = YAML . load ( IO . read ( File . join ( SRC_DIR , 'constants.yml' ) ) ) [ 'PROTOTYPE_VERSION' ]
18-
18+
1919 DEFAULT_SELECTOR_ENGINE = 'sizzle'
20-
20+
2121 # Possible options for PDoc syntax highlighting, in order of preference.
2222 SYNTAX_HIGHLIGHTERS = [ :pygments , :coderay , :none ]
2323
@@ -33,7 +33,7 @@ module PrototypeHelper
3333 return false
3434 end
3535 end
36-
36+
3737 def self . require_git
3838 return if has_git?
3939 puts "\n Prototype requires Git in order to load its dependencies."
@@ -42,30 +42,30 @@ module PrototypeHelper
4242 puts " http://book.git-scm.com/2_installing_git.html"
4343 exit
4444 end
45-
45+
4646 def self . sprocketize ( options = { } )
4747 options = {
4848 :destination => File . join ( DIST_DIR , options [ :source ] ) ,
4949 :strip_comments => true
5050 } . merge ( options )
51-
51+
5252 require_sprockets
5353 load_path = [ SRC_DIR ]
54-
54+
5555 if selector_path = get_selector_engine ( options [ :selector_engine ] )
5656 load_path << selector_path
5757 end
58-
58+
5959 secretary = Sprockets ::Secretary . new (
6060 :root => File . join ( ROOT_DIR , options [ :path ] ) ,
6161 :load_path => load_path ,
6262 :source_files => [ options [ :source ] ] ,
6363 :strip_comments => options [ :strip_comments ]
6464 )
65-
65+
6666 secretary . concatenation . save_to ( options [ :destination ] )
6767 end
68-
68+
6969 def self . build_doc_for ( file )
7070 rm_rf ( DOC_DIR )
7171 mkdir_p ( DOC_DIR )
9898 :assets => 'doc_assets'
9999 } )
100100 end
101-
101+
102102 def self . syntax_highlighter
103103 if ENV [ 'SYNTAX_HIGHLIGHTER' ]
104104 highlighter = ENV [ 'SYNTAX_HIGHLIGHTER' ] . to_sym
105105 require_highlighter ( highlighter , true )
106106 return highlighter
107107 end
108-
108+
109109 SYNTAX_HIGHLIGHTERS . detect { |n | require_highlighter ( n ) }
110110 end
111-
111+
112112 def self . require_highlighter ( name , verbose = false )
113113 case name
114114 when :pygments
@@ -141,42 +141,42 @@ EOF
141141 exit
142142 end
143143 end
144-
144+
145145 def self . require_sprockets
146146 require_submodule ( 'Sprockets' , 'sprockets' )
147147 end
148-
148+
149149 def self . require_pdoc
150150 require_submodule ( 'PDoc' , 'pdoc' )
151151 end
152-
152+
153153 def self . require_unittest_js
154154 require_submodule ( 'UnittestJS' , 'unittest_js' )
155155 end
156-
156+
157157 def self . require_caja_builder
158158 require_submodule ( 'CajaBuilder' , 'caja_builder' )
159159 end
160-
160+
161161 def self . get_selector_engine ( name )
162162 return if !name
163163 # If the submodule exists, we should use it.
164164 submodule_path = File . join ( ROOT_DIR , "vendor" , name )
165165 return submodule_path if File . exist? ( File . join ( submodule_path , "repository" , ".git" ) )
166166 return submodule_path if name === "legacy_selector"
167-
167+
168168 # If it doesn't exist, we should fetch it.
169169 get_submodule ( 'the required selector engine' , "#{ name } /repository" )
170170 unless File . exist? ( submodule_path )
171171 puts "The selector engine you required isn't available at vendor/#{ name } .\n \n "
172172 exit
173173 end
174174 end
175-
175+
176176 def self . get_submodule ( name , path )
177177 require_git
178178 puts "\n You seem to be missing #{ name } . Obtaining it via git...\n \n "
179-
179+
180180 Kernel . system ( "git submodule init" )
181181 return true if Kernel . system ( "git submodule update vendor/#{ path } " )
182182 # If we got this far, something went wrong.
@@ -185,16 +185,18 @@ EOF
185185 puts " $ git submodule update vendor/#{ path } "
186186 false
187187 end
188-
188+
189189 def self . require_submodule ( name , path )
190190 begin
191- require path
191+ full_path = File . join ( PrototypeHelper ::ROOT_DIR , 'vendor' , path , 'lib' , path )
192+ # We need to require the explicit version in the submodule.
193+ require full_path
192194 rescue LoadError => e
193195 # Wait until we notice that a submodule is missing before we bother the
194196 # user about installing git. (Maybe they brought all the files over
195197 # from a different machine.)
196198 missing_file = e . message . sub ( 'no such file to load -- ' , '' ) . sub ( 'cannot load such file -- ' , '' )
197- if missing_file == path
199+ if missing_file == full_path
198200 # Missing a git submodule.
199201 retry if get_submodule ( name , path )
200202 else
206208 exit
207209 end
208210 end
209-
211+
210212 def self . current_head
211213 `git show-ref --hash HEAD` . chomp [ 0 ..6 ]
212214 end
@@ -228,7 +230,7 @@ namespace :doc do
228230 task :build => [ :require ] do
229231 PrototypeHelper . build_doc_for ( ENV [ 'SECTION' ] ? "#{ ENV [ 'SECTION' ] } .js" : 'prototype.js' )
230232 end
231-
233+
232234 task :require do
233235 PrototypeHelper . require_pdoc
234236 end
@@ -273,17 +275,17 @@ namespace :test do
273275 runner . add_test ( file , testcases )
274276 end
275277 end
276-
278+
277279 UnittestJS ::Browser ::SUPPORTED . each do |browser |
278280 unless browsers_to_test && !browsers_to_test . include? ( browser )
279281 runner . add_browser ( browser . to_sym )
280282 end
281283 end
282-
284+
283285 trap ( 'INT' ) { runner . teardown ; exit }
284286 runner . run
285287 end
286-
288+
287289 task :build => [ :clean , :dist ] do
288290 builder = UnittestJS ::Builder ::SuiteBuilder . new ( {
289291 :input_dir => PrototypeHelper ::TEST_UNIT_DIR ,
@@ -293,36 +295,36 @@ namespace :test do
293295 builder . collect ( *selected_tests )
294296 builder . render
295297 end
296-
298+
297299 task :clean => [ :require ] do
298300 UnittestJS ::Builder . empty_dir! ( PrototypeHelper ::TMP_DIR )
299301 end
300-
302+
301303 task :require do
302304 PrototypeHelper . require_unittest_js
303305 end
304-
306+
305307 desc "Builds all the unit tests and starts the server. (The user can visit the tests manually in a browser at their leisure.)"
306- task :server => [ :build ] do
308+ task :server => [ :build ] do
307309 runner = UnittestJS ::WEBrickRunner ::Runner . new ( :test_dir => PrototypeHelper ::TMP_DIR )
308310 testcases = ENV [ 'TESTCASES' ]
309-
311+
310312 Dir [ File . join ( PrototypeHelper ::TMP_DIR , '*_test.html' ) ] . each do |file |
311313 file = File . basename ( file )
312314 test = file . sub ( '_test.html' , '' )
313315 runner . add_test ( file , testcases )
314316 end
315-
317+
316318 trap ( 'INT' ) do
317319 puts "...server stopped."
318320 runner . teardown
319321 exit
320322 end
321-
323+
322324 puts "Server started..."
323-
325+
324326 runner . setup
325-
327+
326328 loop do
327329 sleep 1
328330 end
@@ -343,11 +345,11 @@ end
343345
344346namespace :caja do
345347 task :test => [ 'test:build' , 'test:run' ]
346-
348+
347349 namespace :test do
348350 task :run => [ 'rake:test:run' ]
349351
350- task :build => [ :require , 'rake:test:clean' , :dist ] do
352+ task :build => [ :require , 'rake:test:clean' , :dist ] do
351353 builder = UnittestJS ::CajaBuilder ::SuiteBuilder . new ( {
352354 :input_dir => PrototypeHelper ::TEST_UNIT_DIR ,
353355 :assets_dir => PrototypeHelper ::DIST_DIR ,
0 commit comments