Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 343 lines (297 sloc) 10.815 kb
bb4d189 Sam Stephenson prototype: Reorganize the source tree.
authored
1 require 'rake'
2 require 'rake/packagetask'
0445d37 Andrew Dupont Update Rake "doc" task to integrate with Sprockets.
savetheclocktower authored
3 require 'yaml'
4
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
5 module PrototypeHelper
6 ROOT_DIR = File.expand_path(File.dirname(__FILE__))
7 SRC_DIR = File.join(ROOT_DIR, 'src')
8 DIST_DIR = File.join(ROOT_DIR, 'dist')
9 DOC_DIR = File.join(ROOT_DIR, 'doc')
10 TEMPLATES_DIR = File.join(ROOT_DIR, 'templates')
11 PKG_DIR = File.join(ROOT_DIR, 'pkg')
12 TEST_DIR = File.join(ROOT_DIR, 'test')
13 TEST_UNIT_DIR = File.join(TEST_DIR, 'unit')
14 TMP_DIR = File.join(TEST_UNIT_DIR, 'tmp')
15 VERSION = YAML.load(IO.read(File.join(SRC_DIR, 'constants.yml')))['PROTOTYPE_VERSION']
732eb3d Andrew Dupont Change how PDoc is told which syntax highlighting engine to use. SYNTAX_...
savetheclocktower authored
16
a44a8db Tobie Langel Avoid automatically fetching the vendor/sizzle git submodule.
tobie authored
17 DEFAULT_SELECTOR_ENGINE = 'sizzle'
732eb3d Andrew Dupont Change how PDoc is told which syntax highlighting engine to use. SYNTAX_...
savetheclocktower authored
18
19 # Possible options for PDoc syntax highlighting, in order of preference.
20 SYNTAX_HIGHLIGHTERS = [:pygments, :coderay, :none]
107f812 Tobie Langel Modify PrototypeHelper.sprocketize to take a hash of options rather than...
tobie authored
21
75aab03 Tobie Langel Repo and Rakefile refactoring.
tobie authored
22 %w[sprockets pdoc unittest_js caja_builder].each do |name|
c5372d8 Andrew Dupont Detect if Sizzle hasn't been loaded via submodule.
savetheclocktower authored
23 $:.unshift File.join(PrototypeHelper::ROOT_DIR, 'vendor', name, 'lib')
24 end
d3df9ba Andrew Dupont Automate installation of Git submodules.
savetheclocktower authored
25
26 def self.has_git?
27 begin
28 `git --version`
29 return true
30 rescue Error => e
31 return false
32 end
33 end
34
35 def self.require_git
36 return if has_git?
37 puts "\nPrototype requires Git in order to load its dependencies."
38 puts "\nMake sure you've got Git installed and in your path."
39 puts "\nFor more information, visit:\n\n"
40 puts " http://book.git-scm.com/2_installing_git.html"
41 exit
42 end
732eb3d Andrew Dupont Change how PDoc is told which syntax highlighting engine to use. SYNTAX_...
savetheclocktower authored
43
107f812 Tobie Langel Modify PrototypeHelper.sprocketize to take a hash of options rather than...
tobie authored
44 def self.sprocketize(options = {})
45 options = {
46 :destination => File.join(DIST_DIR, options[:source]),
47 :strip_comments => true
48 }.merge(options)
49
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
50 require_sprockets
74c5d45 Samuel Lebeau Fix custom selector engine load path resolution.
samleb authored
51 load_path = [SRC_DIR]
107f812 Tobie Langel Modify PrototypeHelper.sprocketize to take a hash of options rather than...
tobie authored
52
a44a8db Tobie Langel Avoid automatically fetching the vendor/sizzle git submodule.
tobie authored
53 if selector_path = get_selector_engine(options[:selector_engine])
54 load_path << selector_path
107f812 Tobie Langel Modify PrototypeHelper.sprocketize to take a hash of options rather than...
tobie authored
55 end
56
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
57 secretary = Sprockets::Secretary.new(
107f812 Tobie Langel Modify PrototypeHelper.sprocketize to take a hash of options rather than...
tobie authored
58 :root => File.join(ROOT_DIR, options[:path]),
59 :load_path => load_path,
60 :source_files => [options[:source]],
61 :strip_comments => options[:strip_comments]
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
62 )
63
107f812 Tobie Langel Modify PrototypeHelper.sprocketize to take a hash of options rather than...
tobie authored
64 secretary.concatenation.save_to(options[:destination])
7762e00 Tobie Langel Reorder repository to allow for custom selector engines to be included i...
tobie authored
65 end
66
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
67 def self.build_doc_for(file)
d11f317 Tobie Langel Update PDoc.
tobie authored
68 rm_rf(DOC_DIR)
69 mkdir_p(DOC_DIR)
0a0673a Andrew Dupont Update PDoc Rake task to include proper URLs for source code references.
savetheclocktower authored
70 hash = current_head
6a584d2 Tobie Langel Update pdoc.
tobie authored
71 index_header = <<EOF
72 <h1 style="margin-top: 31px; height: 75px; padding: 1px 0; background: url(images/header-stripe-small.png) repeat-x;">
73 <a href="http://prototypejs.org" style="padding-left: 120px;">
74 <img src="images/header-logo-small.png" alt="Prototype JavaScript Framework API" />
75 </a>
76 </h1>
77 EOF
6839886 Tobie Langel doc: Update PDoc. Default to BlueCloth Markdown parser to avoid Maruku w...
tobie authored
78 PDoc.run({
5e5cfff Joshua Peek Sprockets 2 compatibility
josh authored
79 :source_files => Dir[File.join('src', 'prototype', '**', '*.js')],
0a0673a Andrew Dupont Update PDoc Rake task to include proper URLs for source code references.
savetheclocktower authored
80 :destination => DOC_DIR,
81 :index_page => 'README.markdown',
d11f317 Tobie Langel Update PDoc.
tobie authored
82 :syntax_highlighter => syntax_highlighter,
0a0673a Andrew Dupont Update PDoc Rake task to include proper URLs for source code references.
savetheclocktower authored
83 :markdown_parser => :bluecloth,
84 :src_code_text => "View source on GitHub &rarr;",
6a584d2 Tobie Langel Update pdoc.
tobie authored
85 :src_code_href => proc { |obj|
0a0673a Andrew Dupont Update PDoc Rake task to include proper URLs for source code references.
savetheclocktower authored
86 "https://github.com/sstephenson/prototype/blob/#{hash}/#{obj.file}#L#{obj.line_number}"
694f36d Tobie Langel Update to latest version of pdoc.
tobie authored
87 },
5d454e4 Tobie Langel Make documentation pretty urls option false. The Rake task is targeted a...
tobie authored
88 :pretty_urls => false,
0a0673a Andrew Dupont Update PDoc Rake task to include proper URLs for source code references.
savetheclocktower authored
89 :bust_cache => false,
748e73f Tobie Langel Update PDoc yet again.
tobie authored
90 :name => 'Prototype JavaScript Framework',
91 :short_name => 'Prototype',
92 :home_url => 'http://prototypejs.org',
93 :version => PrototypeHelper::VERSION,
6a584d2 Tobie Langel Update pdoc.
tobie authored
94 :index_header => index_header,
95 :footer => 'This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0 Unported License</a>.',
96 :assets => 'doc_assets'
6839886 Tobie Langel doc: Update PDoc. Default to BlueCloth Markdown parser to avoid Maruku w...
tobie authored
97 })
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
98 end
99
732eb3d Andrew Dupont Change how PDoc is told which syntax highlighting engine to use. SYNTAX_...
savetheclocktower authored
100 def self.syntax_highlighter
101 if ENV['SYNTAX_HIGHLIGHTER']
102 highlighter = ENV['SYNTAX_HIGHLIGHTER'].to_sym
103 require_highlighter(highlighter, true)
104 return highlighter
105 end
106
107 SYNTAX_HIGHLIGHTERS.detect { |n| require_highlighter(n) }
108 end
109
110 def self.require_highlighter(name, verbose=false)
111 case name
112 when :pygments
d11f317 Tobie Langel Update PDoc.
tobie authored
113 success = system("pygmentize -V > /dev/null")
732eb3d Andrew Dupont Change how PDoc is told which syntax highlighting engine to use. SYNTAX_...
savetheclocktower authored
114 if !success && verbose
115 puts "\nYou asked to use Pygments, but I can't find the 'pygmentize' binary."
116 puts "To install, visit:\n"
117 puts " http://pygments.org/docs/installation/\n\n"
118 exit
119 end
120 return success # (we have pygments)
121 when :coderay
122 begin
123 require 'coderay'
124 rescue LoadError => e
125 if verbose
126 puts "\nYou asked to use CodeRay, but I can't find the 'coderay' gem. Just run:\n\n"
127 puts " $ gem install coderay"
128 puts "\nand you should be all set.\n\n"
129 exit
130 end
131 return false
132 end
133 return true # (we have CodeRay)
134 when :none
135 return true
136 else
137 puts "\nYou asked to use a syntax highlighter I don't recognize."
138 puts "Valid options: #{SYNTAX_HIGHLIGHTERS.join(', ')}\n\n"
139 exit
140 end
141 end
142
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
143 def self.require_sprockets
0a8cf9b Tobie Langel Prevent Rakefile from mishandling missing gem errors.
tobie authored
144 require_submodule('Sprockets', 'sprockets')
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
145 end
146
147 def self.require_pdoc
0a8cf9b Tobie Langel Prevent Rakefile from mishandling missing gem errors.
tobie authored
148 require_submodule('PDoc', 'pdoc')
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
149 end
150
151 def self.require_unittest_js
0a8cf9b Tobie Langel Prevent Rakefile from mishandling missing gem errors.
tobie authored
152 require_submodule('UnittestJS', 'unittest_js')
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
153 end
6d70608 Sam Stephenson Update to Sprockets 0.9.0
authored
154
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
155 def self.require_caja_builder
0a8cf9b Tobie Langel Prevent Rakefile from mishandling missing gem errors.
tobie authored
156 require_submodule('CajaBuilder', 'caja_builder')
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
157 end
158
75aab03 Tobie Langel Repo and Rakefile refactoring.
tobie authored
159 def self.get_selector_engine(name)
c312cbc Andrew Dupont Build with the submodule version Sizzle if it exists; otherwise build fr...
savetheclocktower authored
160 return if !name
161 # If the submodule exists, we should use it, even if we're using the
162 # default engine; the user might have fetched it manually, and thus would
163 # want to build a distributable with the most recent version of that
164 # engine.
74c5d45 Samuel Lebeau Fix custom selector engine load path resolution.
samleb authored
165 submodule_path = File.join(ROOT_DIR, "vendor", name)
166 return submodule_path if File.exist?(File.join(submodule_path, "repository", ".git"))
d9aee20 Tobie Langel Refactor selector engine wrapper and add convenience helper methods to s...
tobie authored
167 return submodule_path if name === "legacy_selector"
c312cbc Andrew Dupont Build with the submodule version Sizzle if it exists; otherwise build fr...
savetheclocktower authored
168
169 # If it doesn't exist, we should fetch it, _unless_ it's the default
170 # engine. We've already got a known version of the default engine in our
171 # load path.
172 return if name == DEFAULT_SELECTOR_ENGINE
74c5d45 Samuel Lebeau Fix custom selector engine load path resolution.
samleb authored
173 get_submodule('the required selector engine', "#{name}/repository")
9d47112 Tobie Langel Fix typo in Rakefile.
tobie authored
174 unless File.exist?(submodule_path)
74c5d45 Samuel Lebeau Fix custom selector engine load path resolution.
samleb authored
175 puts "The selector engine you required isn't available at vendor/#{name}.\n\n"
176 exit
15c323b Tobie Langel Include NWMatcher as a submodule.
tobie authored
177 end
178 end
179
d3df9ba Andrew Dupont Automate installation of Git submodules.
savetheclocktower authored
180 def self.get_submodule(name, path)
181 require_git
182 puts "\nYou seem to be missing #{name}. Obtaining it via git...\n\n"
183
184 Kernel.system("git submodule init")
185 return true if Kernel.system("git submodule update vendor/#{path}")
186 # If we got this far, something went wrong.
187 puts "\nLooks like it didn't work. Try it manually:\n\n"
188 puts " $ git submodule init"
189 puts " $ git submodule update vendor/#{path}"
190 false
191 end
192
0a8cf9b Tobie Langel Prevent Rakefile from mishandling missing gem errors.
tobie authored
193 def self.require_submodule(name, path)
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
194 begin
0a8cf9b Tobie Langel Prevent Rakefile from mishandling missing gem errors.
tobie authored
195 require path
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
196 rescue LoadError => e
d3df9ba Andrew Dupont Automate installation of Git submodules.
savetheclocktower authored
197 # Wait until we notice that a submodule is missing before we bother the
198 # user about installing git. (Maybe they brought all the files over
199 # from a different machine.)
0a8cf9b Tobie Langel Prevent Rakefile from mishandling missing gem errors.
tobie authored
200 missing_file = e.message.sub('no such file to load -- ', '')
201 if missing_file == path
d3df9ba Andrew Dupont Automate installation of Git submodules.
savetheclocktower authored
202 # Missing a git submodule.
203 retry if get_submodule(name, path)
0a8cf9b Tobie Langel Prevent Rakefile from mishandling missing gem errors.
tobie authored
204 else
d3df9ba Andrew Dupont Automate installation of Git submodules.
savetheclocktower authored
205 # Missing a gem.
0a8cf9b Tobie Langel Prevent Rakefile from mishandling missing gem errors.
tobie authored
206 puts "\nIt looks like #{name} is missing the '#{missing_file}' gem. Just run:\n\n"
207 puts " $ gem install #{missing_file}"
208 puts "\nand you should be all set.\n\n"
209 end
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
210 exit
211 end
212 end
d11f317 Tobie Langel Update PDoc.
tobie authored
213
214 def self.current_head
f890b3d Tobie Langel Update PDoc some more.
tobie authored
215 `git show-ref --hash HEAD`.chomp[0..6]
d11f317 Tobie Langel Update PDoc.
tobie authored
216 end
b2597ec Samuel Lebeau Start PDoc integration.
samleb authored
217 end
218
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
219 task :default => [:dist, :dist_helper, :package, :clean_package_source]
220
a519c02 Sam Stephenson Sprocketize Prototype
authored
221 desc "Builds the distribution."
222 task :dist do
107f812 Tobie Langel Modify PrototypeHelper.sprocketize to take a hash of options rather than...
tobie authored
223 PrototypeHelper.sprocketize(
224 :path => 'src',
225 :source => 'prototype.js',
a44a8db Tobie Langel Avoid automatically fetching the vendor/sizzle git submodule.
tobie authored
226 :selector_engine => ENV['SELECTOR_ENGINE'] || PrototypeHelper::DEFAULT_SELECTOR_ENGINE
107f812 Tobie Langel Modify PrototypeHelper.sprocketize to take a hash of options rather than...
tobie authored
227 )
a519c02 Sam Stephenson Sprocketize Prototype
authored
228 end
229
4428747 Andrew Dupont Updated Rakefile to check for presence of PDoc before running 'doc' task...
savetheclocktower authored
230 namespace :doc do
231 desc "Builds the documentation."
232 task :build => [:require] do
63f96ea Tobie Langel Fixed doc template to allow separate building of the documentation of ea...
tobie authored
233 PrototypeHelper.build_doc_for(ENV['SECTION'] ? "#{ENV['SECTION']}.js" : 'prototype.js')
732eb3d Andrew Dupont Change how PDoc is told which syntax highlighting engine to use. SYNTAX_...
savetheclocktower authored
234 end
4428747 Andrew Dupont Updated Rakefile to check for presence of PDoc before running 'doc' task...
savetheclocktower authored
235
236 task :require do
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
237 PrototypeHelper.require_pdoc
bb4d189 Sam Stephenson prototype: Reorganize the source tree.
authored
238 end
239 end
240
4428747 Andrew Dupont Updated Rakefile to check for presence of PDoc before running 'doc' task...
savetheclocktower authored
241 task :doc => ['doc:build']
242
cf5d180 Tobie Langel refactored unit tests quite a bit. Added JS and CSS fixtures.
tobie authored
243 desc "Builds the updating helper."
87ce153 Tobie Langel prototype: Complete rewrite of the deprecation helper.
tobie authored
244 task :dist_helper do
107f812 Tobie Langel Modify PrototypeHelper.sprocketize to take a hash of options rather than...
tobie authored
245 PrototypeHelper.sprocketize(:path => 'ext/update_helper', :source => 'prototype_update_helper.js')
87ce153 Tobie Langel prototype: Complete rewrite of the deprecation helper.
tobie authored
246 end
247
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
248 Rake::PackageTask.new('prototype', PrototypeHelper::VERSION) do |package|
bb4d189 Sam Stephenson prototype: Reorganize the source tree.
authored
249 package.need_tar_gz = true
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
250 package.package_dir = PrototypeHelper::PKG_DIR
bb4d189 Sam Stephenson prototype: Reorganize the source tree.
authored
251 package.package_files.include(
252 '[A-Z]*',
253 'dist/prototype.js',
254 'lib/**',
255 'src/**',
256 'test/**'
257 )
258 end
259
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
260 task :clean_package_source do
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
261 rm_rf File.join(PrototypeHelper::PKG_DIR, "prototype-#{PrototypeHelper::VERSION}")
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
262 end
bb4d189 Sam Stephenson prototype: Reorganize the source tree.
authored
263
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
264 task :test => ['test:build', 'test:run']
265 namespace :test do
266 desc 'Runs all the JavaScript unit tests and collects the results'
267 task :run => [:require] do
268 testcases = ENV['TESTCASES']
269 browsers_to_test = ENV['BROWSERS'] && ENV['BROWSERS'].split(',')
270 tests_to_run = ENV['TESTS'] && ENV['TESTS'].split(',')
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
271 runner = UnittestJS::WEBrickRunner::Runner.new(:test_dir => PrototypeHelper::TMP_DIR)
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
272
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
273 Dir[File.join(PrototypeHelper::TMP_DIR, '*_test.html')].each do |file|
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
274 file = File.basename(file)
275 test = file.sub('_test.html', '')
276 unless tests_to_run && !tests_to_run.include?(test)
277 runner.add_test(file, testcases)
278 end
279 end
280
281 UnittestJS::Browser::SUPPORTED.each do |browser|
282 unless browsers_to_test && !browsers_to_test.include?(browser)
283 runner.add_browser(browser.to_sym)
284 end
285 end
286
287 trap('INT') { runner.teardown; exit }
288 runner.run
289 end
bb4d189 Sam Stephenson prototype: Reorganize the source tree.
authored
290
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
291 task :build => [:clean, :dist] do
292 builder = UnittestJS::Builder::SuiteBuilder.new({
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
293 :input_dir => PrototypeHelper::TEST_UNIT_DIR,
294 :assets_dir => PrototypeHelper::DIST_DIR
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
295 })
296 selected_tests = (ENV['TESTS'] || '').split(',')
297 builder.collect(*selected_tests)
298 builder.render
299 end
ba6934e Tobie Langel Make Rake auto-generate test/unit/temp directory if it is missing.
tobie authored
300
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
301 task :clean => [:require] do
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
302 UnittestJS::Builder.empty_dir!(PrototypeHelper::TMP_DIR)
bb4d189 Sam Stephenson prototype: Reorganize the source tree.
authored
303 end
304
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
305 task :require do
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
306 PrototypeHelper.require_unittest_js
bb4d189 Sam Stephenson prototype: Reorganize the source tree.
authored
307 end
308 end
41ef42e Tobie Langel Unit test lib reorganizing.
tobie authored
309
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
310 task :test_units do
311 puts '"rake test_units" is deprecated. Please use "rake test" instead.'
41ef42e Tobie Langel Unit test lib reorganizing.
tobie authored
312 end
313
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
314 task :build_unit_tests do
315 puts '"rake test_units" is deprecated. Please use "rake test:build" instead.'
41ef42e Tobie Langel Unit test lib reorganizing.
tobie authored
316 end
317
318 task :clean_tmp do
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
319 puts '"rake clean_tmp" is deprecated. Please use "rake test:clean" instead.'
41ef42e Tobie Langel Unit test lib reorganizing.
tobie authored
320 end
99f74b5 Tobie Langel Add caja_builder for optional cajoled tests.
tobie authored
321
322 namespace :caja do
323 task :test => ['test:build', 'test:run']
324
325 namespace :test do
326 task :run => ['rake:test:run']
327
328 task :build => [:require, 'rake:test:clean', :dist] do
329 builder = UnittestJS::CajaBuilder::SuiteBuilder.new({
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
330 :input_dir => PrototypeHelper::TEST_UNIT_DIR,
331 :assets_dir => PrototypeHelper::DIST_DIR,
332 :whitelist_dir => File.join(PrototypeHelper::TEST_DIR, 'unit', 'caja_whitelists'),
99f74b5 Tobie Langel Add caja_builder for optional cajoled tests.
tobie authored
333 :html_attrib_schema => 'html_attrib.json'
334 })
335 selected_tests = (ENV['TESTS'] || '').split(',')
336 builder.collect(*selected_tests)
337 builder.render
338 end
339 end
340 task :require => ['rake:test:require'] do
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
341 PrototypeHelper.require_caja_builder
99f74b5 Tobie Langel Add caja_builder for optional cajoled tests.
tobie authored
342 end
343 end
Something went wrong with that request. Please try again.