1
1
require 'rake'
2
2
require 'rake/packagetask'
3
+ require 'rbconfig'
3
4
require 'yaml'
4
5
5
6
module PrototypeHelper
6
7
extend Rake ::DSL
7
-
8
+
8
9
ROOT_DIR = File . expand_path ( File . dirname ( __FILE__ ) )
9
10
SRC_DIR = File . join ( ROOT_DIR , 'src' )
10
11
DIST_DIR = File . join ( ROOT_DIR , 'dist' )
@@ -15,9 +16,12 @@ module PrototypeHelper
15
16
TEST_UNIT_DIR = File . join ( TEST_DIR , 'unit' )
16
17
TMP_DIR = File . join ( TEST_UNIT_DIR , 'tmp' )
17
18
VERSION = YAML . load ( IO . read ( File . join ( SRC_DIR , 'constants.yml' ) ) ) [ 'PROTOTYPE_VERSION' ]
18
-
19
+
19
20
DEFAULT_SELECTOR_ENGINE = 'sizzle'
20
-
21
+
22
+ host = RbConfig ::CONFIG [ 'host' ]
23
+ IS_WINDOWS = host . include? ( 'mswin' ) || host . include? ( 'mingw32' )
24
+
21
25
# Possible options for PDoc syntax highlighting, in order of preference.
22
26
SYNTAX_HIGHLIGHTERS = [ :pygments , :coderay , :none ]
23
27
@@ -33,7 +37,7 @@ module PrototypeHelper
33
37
return false
34
38
end
35
39
end
36
-
40
+
37
41
def self . require_git
38
42
return if has_git?
39
43
puts "\n Prototype requires Git in order to load its dependencies."
@@ -42,30 +46,30 @@ module PrototypeHelper
42
46
puts " http://book.git-scm.com/2_installing_git.html"
43
47
exit
44
48
end
45
-
49
+
46
50
def self . sprocketize ( options = { } )
47
51
options = {
48
52
:destination => File . join ( DIST_DIR , options [ :source ] ) ,
49
53
:strip_comments => true
50
54
} . merge ( options )
51
-
55
+
52
56
require_sprockets
53
57
load_path = [ SRC_DIR ]
54
-
58
+
55
59
if selector_path = get_selector_engine ( options [ :selector_engine ] )
56
60
load_path << selector_path
57
61
end
58
-
62
+
59
63
secretary = Sprockets ::Secretary . new (
60
64
:root => File . join ( ROOT_DIR , options [ :path ] ) ,
61
65
:load_path => load_path ,
62
66
:source_files => [ options [ :source ] ] ,
63
67
:strip_comments => options [ :strip_comments ]
64
68
)
65
-
69
+
66
70
secretary . concatenation . save_to ( options [ :destination ] )
67
71
end
68
-
72
+
69
73
def self . build_doc_for ( file )
70
74
rm_rf ( DOC_DIR )
71
75
mkdir_p ( DOC_DIR )
98
102
:assets => 'doc_assets'
99
103
} )
100
104
end
101
-
105
+
102
106
def self . require_package ( name )
103
107
begin
104
108
require name
@@ -108,26 +112,27 @@ EOF
108
112
exit
109
113
end
110
114
end
111
-
115
+
112
116
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 )
114
119
if !success
115
120
puts "\n You need phantomjs installed to run this task. Find out how at:"
116
121
puts " http://phantomjs.org/download.html"
117
122
exit
118
123
end
119
124
end
120
-
125
+
121
126
def self . syntax_highlighter
122
127
if ENV [ 'SYNTAX_HIGHLIGHTER' ]
123
128
highlighter = ENV [ 'SYNTAX_HIGHLIGHTER' ] . to_sym
124
129
require_highlighter ( highlighter , true )
125
130
return highlighter
126
131
end
127
-
132
+
128
133
SYNTAX_HIGHLIGHTERS . detect { |n | require_highlighter ( n ) }
129
134
end
130
-
135
+
131
136
def self . require_highlighter ( name , verbose = false )
132
137
case name
133
138
when :pygments
@@ -160,42 +165,42 @@ EOF
160
165
exit
161
166
end
162
167
end
163
-
168
+
164
169
def self . require_sprockets
165
170
require_submodule ( 'Sprockets' , 'sprockets' )
166
171
end
167
-
172
+
168
173
def self . require_pdoc
169
174
require_submodule ( 'PDoc' , 'pdoc' )
170
175
end
171
-
176
+
172
177
def self . require_unittest_js
173
178
require_submodule ( 'UnittestJS' , 'unittest_js' )
174
179
end
175
-
180
+
176
181
def self . require_caja_builder
177
182
require_submodule ( 'CajaBuilder' , 'caja_builder' )
178
183
end
179
-
184
+
180
185
def self . get_selector_engine ( name )
181
186
return if !name
182
187
# If the submodule exists, we should use it.
183
188
submodule_path = File . join ( ROOT_DIR , "vendor" , name )
184
189
return submodule_path if File . exist? ( File . join ( submodule_path , "repository" , ".git" ) )
185
190
return submodule_path if name === "legacy_selector"
186
-
191
+
187
192
# If it doesn't exist, we should fetch it.
188
193
get_submodule ( 'the required selector engine' , "#{ name } /repository" )
189
194
unless File . exist? ( submodule_path )
190
195
puts "The selector engine you required isn't available at vendor/#{ name } .\n \n "
191
196
exit
192
197
end
193
198
end
194
-
199
+
195
200
def self . get_submodule ( name , path )
196
201
require_git
197
202
puts "\n You seem to be missing #{ name } . Obtaining it via git...\n \n "
198
-
203
+
199
204
Kernel . system ( "git submodule init" )
200
205
return true if Kernel . system ( "git submodule update vendor/#{ path } " )
201
206
# If we got this far, something went wrong.
204
209
puts " $ git submodule update vendor/#{ path } "
205
210
false
206
211
end
207
-
212
+
208
213
def self . require_submodule ( name , path )
209
214
begin
210
215
require path
225
230
exit
226
231
end
227
232
end
228
-
233
+
229
234
def self . current_head
230
235
`git show-ref --hash HEAD` . chomp [ 0 ..6 ]
231
236
end
@@ -247,7 +252,7 @@ namespace :doc do
247
252
task :build => [ :require ] do
248
253
PrototypeHelper . build_doc_for ( ENV [ 'SECTION' ] ? "#{ ENV [ 'SECTION' ] } .js" : 'prototype.js' )
249
254
end
250
-
255
+
251
256
task :require do
252
257
PrototypeHelper . require_pdoc
253
258
end
@@ -282,30 +287,30 @@ namespace :test do
282
287
task :start => [ :require ] do
283
288
path_to_app = File . join ( PrototypeHelper ::ROOT_DIR , 'test' , 'unit' , 'server.rb' )
284
289
require path_to_app
285
-
290
+
286
291
puts "Starting unit test server..."
287
292
puts "Unit tests available at <http://127.0.0.1:4567/test/>\n \n "
288
293
UnitTests . run!
289
294
end
290
-
295
+
291
296
task :require do
292
297
PrototypeHelper . require_package ( 'sinatra' )
293
298
end
294
-
299
+
295
300
desc "Opens the test suite in several different browsers. (Does not start or stop the server; you should do that separately.)"
296
301
task :run => [ :require ] do
297
302
browsers , tests , grep = ENV [ 'BROWSERS' ] , ENV [ 'TESTS' ] , ENV [ 'GREP' ]
298
303
path_to_runner = File . join ( PrototypeHelper ::ROOT_DIR , 'test' , 'unit' , 'runner.rb' )
299
304
require path_to_runner
300
-
305
+
301
306
Runner ::run ( browsers , tests , grep )
302
307
end
303
-
308
+
304
309
task :phantom => [ :require ] do
305
310
PrototypeHelper . require_phantomjs
306
311
tests , grep = ENV [ 'TESTS' ] , ENV [ 'GREP' ]
307
312
url = "http://127.0.0.1:4567/test/#{ tests } "
308
313
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 } "] )
310
315
end
311
316
end
0 commit comments