@@ -4,7 +4,7 @@ require 'yaml'
4
4
5
5
module PrototypeHelper
6
6
extend Rake ::DSL
7
-
7
+
8
8
ROOT_DIR = File . expand_path ( File . dirname ( __FILE__ ) )
9
9
SRC_DIR = File . join ( ROOT_DIR , 'src' )
10
10
DIST_DIR = File . join ( ROOT_DIR , 'dist' )
@@ -15,9 +15,9 @@ module PrototypeHelper
15
15
TEST_UNIT_DIR = File . join ( TEST_DIR , 'unit' )
16
16
TMP_DIR = File . join ( TEST_UNIT_DIR , 'tmp' )
17
17
VERSION = YAML . load ( IO . read ( File . join ( SRC_DIR , 'constants.yml' ) ) ) [ 'PROTOTYPE_VERSION' ]
18
-
18
+
19
19
DEFAULT_SELECTOR_ENGINE = 'sizzle'
20
-
20
+
21
21
# Possible options for PDoc syntax highlighting, in order of preference.
22
22
SYNTAX_HIGHLIGHTERS = [ :pygments , :coderay , :none ]
23
23
@@ -33,7 +33,7 @@ module PrototypeHelper
33
33
return false
34
34
end
35
35
end
36
-
36
+
37
37
def self . require_git
38
38
return if has_git?
39
39
puts "\n Prototype requires Git in order to load its dependencies."
@@ -42,30 +42,30 @@ module PrototypeHelper
42
42
puts " http://book.git-scm.com/2_installing_git.html"
43
43
exit
44
44
end
45
-
45
+
46
46
def self . sprocketize ( options = { } )
47
47
options = {
48
48
:destination => File . join ( DIST_DIR , options [ :source ] ) ,
49
49
:strip_comments => true
50
50
} . merge ( options )
51
-
51
+
52
52
require_sprockets
53
53
load_path = [ SRC_DIR ]
54
-
54
+
55
55
if selector_path = get_selector_engine ( options [ :selector_engine ] )
56
56
load_path << selector_path
57
57
end
58
-
58
+
59
59
secretary = Sprockets ::Secretary . new (
60
60
:root => File . join ( ROOT_DIR , options [ :path ] ) ,
61
61
:load_path => load_path ,
62
62
:source_files => [ options [ :source ] ] ,
63
63
:strip_comments => options [ :strip_comments ]
64
64
)
65
-
65
+
66
66
secretary . concatenation . save_to ( options [ :destination ] )
67
67
end
68
-
68
+
69
69
def self . build_doc_for ( file )
70
70
rm_rf ( DOC_DIR )
71
71
mkdir_p ( DOC_DIR )
98
98
:assets => 'doc_assets'
99
99
} )
100
100
end
101
-
101
+
102
102
def self . syntax_highlighter
103
103
if ENV [ 'SYNTAX_HIGHLIGHTER' ]
104
104
highlighter = ENV [ 'SYNTAX_HIGHLIGHTER' ] . to_sym
105
105
require_highlighter ( highlighter , true )
106
106
return highlighter
107
107
end
108
-
108
+
109
109
SYNTAX_HIGHLIGHTERS . detect { |n | require_highlighter ( n ) }
110
110
end
111
-
111
+
112
112
def self . require_highlighter ( name , verbose = false )
113
113
case name
114
114
when :pygments
@@ -141,42 +141,42 @@ EOF
141
141
exit
142
142
end
143
143
end
144
-
144
+
145
145
def self . require_sprockets
146
146
require_submodule ( 'Sprockets' , 'sprockets' )
147
147
end
148
-
148
+
149
149
def self . require_pdoc
150
150
require_submodule ( 'PDoc' , 'pdoc' )
151
151
end
152
-
152
+
153
153
def self . require_unittest_js
154
154
require_submodule ( 'UnittestJS' , 'unittest_js' )
155
155
end
156
-
156
+
157
157
def self . require_caja_builder
158
158
require_submodule ( 'CajaBuilder' , 'caja_builder' )
159
159
end
160
-
160
+
161
161
def self . get_selector_engine ( name )
162
162
return if !name
163
163
# If the submodule exists, we should use it.
164
164
submodule_path = File . join ( ROOT_DIR , "vendor" , name )
165
165
return submodule_path if File . exist? ( File . join ( submodule_path , "repository" , ".git" ) )
166
166
return submodule_path if name === "legacy_selector"
167
-
167
+
168
168
# If it doesn't exist, we should fetch it.
169
169
get_submodule ( 'the required selector engine' , "#{ name } /repository" )
170
170
unless File . exist? ( submodule_path )
171
171
puts "The selector engine you required isn't available at vendor/#{ name } .\n \n "
172
172
exit
173
173
end
174
174
end
175
-
175
+
176
176
def self . get_submodule ( name , path )
177
177
require_git
178
178
puts "\n You seem to be missing #{ name } . Obtaining it via git...\n \n "
179
-
179
+
180
180
Kernel . system ( "git submodule init" )
181
181
return true if Kernel . system ( "git submodule update vendor/#{ path } " )
182
182
# If we got this far, something went wrong.
@@ -185,16 +185,18 @@ EOF
185
185
puts " $ git submodule update vendor/#{ path } "
186
186
false
187
187
end
188
-
188
+
189
189
def self . require_submodule ( name , path )
190
190
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
192
194
rescue LoadError => e
193
195
# Wait until we notice that a submodule is missing before we bother the
194
196
# user about installing git. (Maybe they brought all the files over
195
197
# from a different machine.)
196
198
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
198
200
# Missing a git submodule.
199
201
retry if get_submodule ( name , path )
200
202
else
206
208
exit
207
209
end
208
210
end
209
-
211
+
210
212
def self . current_head
211
213
`git show-ref --hash HEAD` . chomp [ 0 ..6 ]
212
214
end
@@ -228,7 +230,7 @@ namespace :doc do
228
230
task :build => [ :require ] do
229
231
PrototypeHelper . build_doc_for ( ENV [ 'SECTION' ] ? "#{ ENV [ 'SECTION' ] } .js" : 'prototype.js' )
230
232
end
231
-
233
+
232
234
task :require do
233
235
PrototypeHelper . require_pdoc
234
236
end
@@ -273,17 +275,17 @@ namespace :test do
273
275
runner . add_test ( file , testcases )
274
276
end
275
277
end
276
-
278
+
277
279
UnittestJS ::Browser ::SUPPORTED . each do |browser |
278
280
unless browsers_to_test && !browsers_to_test . include? ( browser )
279
281
runner . add_browser ( browser . to_sym )
280
282
end
281
283
end
282
-
284
+
283
285
trap ( 'INT' ) { runner . teardown ; exit }
284
286
runner . run
285
287
end
286
-
288
+
287
289
task :build => [ :clean , :dist ] do
288
290
builder = UnittestJS ::Builder ::SuiteBuilder . new ( {
289
291
:input_dir => PrototypeHelper ::TEST_UNIT_DIR ,
@@ -293,36 +295,36 @@ namespace :test do
293
295
builder . collect ( *selected_tests )
294
296
builder . render
295
297
end
296
-
298
+
297
299
task :clean => [ :require ] do
298
300
UnittestJS ::Builder . empty_dir! ( PrototypeHelper ::TMP_DIR )
299
301
end
300
-
302
+
301
303
task :require do
302
304
PrototypeHelper . require_unittest_js
303
305
end
304
-
306
+
305
307
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
307
309
runner = UnittestJS ::WEBrickRunner ::Runner . new ( :test_dir => PrototypeHelper ::TMP_DIR )
308
310
testcases = ENV [ 'TESTCASES' ]
309
-
311
+
310
312
Dir [ File . join ( PrototypeHelper ::TMP_DIR , '*_test.html' ) ] . each do |file |
311
313
file = File . basename ( file )
312
314
test = file . sub ( '_test.html' , '' )
313
315
runner . add_test ( file , testcases )
314
316
end
315
-
317
+
316
318
trap ( 'INT' ) do
317
319
puts "...server stopped."
318
320
runner . teardown
319
321
exit
320
322
end
321
-
323
+
322
324
puts "Server started..."
323
-
325
+
324
326
runner . setup
325
-
327
+
326
328
loop do
327
329
sleep 1
328
330
end
@@ -343,11 +345,11 @@ end
343
345
344
346
namespace :caja do
345
347
task :test => [ 'test:build' , 'test:run' ]
346
-
348
+
347
349
namespace :test do
348
350
task :run => [ 'rake:test:run' ]
349
351
350
- task :build => [ :require , 'rake:test:clean' , :dist ] do
352
+ task :build => [ :require , 'rake:test:clean' , :dist ] do
351
353
builder = UnittestJS ::CajaBuilder ::SuiteBuilder . new ( {
352
354
:input_dir => PrototypeHelper ::TEST_UNIT_DIR ,
353
355
:assets_dir => PrototypeHelper ::DIST_DIR ,
0 commit comments