Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 325 lines (279 sloc) 9.977 kb
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
1 require 'rake'
2 require 'rake/packagetask'
0445d37 @savetheclocktower Update Rake "doc" task to integrate with Sprockets.
savetheclocktower authored
3 require 'yaml'
4
ea9f797 @tobie 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 @savetheclocktower Change how PDoc is told which syntax highlighting engine to use. SYNT…
savetheclocktower authored
16
a44a8db @tobie Avoid automatically fetching the vendor/sizzle git submodule.
tobie authored
17 DEFAULT_SELECTOR_ENGINE = 'sizzle'
732eb3d @savetheclocktower Change how PDoc is told which syntax highlighting engine to use. SYNT…
savetheclocktower authored
18
19 # Possible options for PDoc syntax highlighting, in order of preference.
20 SYNTAX_HIGHLIGHTERS = [:pygments, :coderay, :none]
107f812 @tobie Modify PrototypeHelper.sprocketize to take a hash of options rather t…
tobie authored
21
75aab03 @tobie Repo and Rakefile refactoring.
tobie authored
22 %w[sprockets pdoc unittest_js caja_builder].each do |name|
c5372d8 @savetheclocktower Detect if Sizzle hasn't been loaded via submodule.
savetheclocktower authored
23 $:.unshift File.join(PrototypeHelper::ROOT_DIR, 'vendor', name, 'lib')
24 end
d3df9ba @savetheclocktower 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 @savetheclocktower Change how PDoc is told which syntax highlighting engine to use. SYNT…
savetheclocktower authored
43
107f812 @tobie Modify PrototypeHelper.sprocketize to take a hash of options rather t…
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 Refactor Rakefile.
tobie authored
50 require_sprockets
74c5d45 @samleb Fix custom selector engine load path resolution.
samleb authored
51 load_path = [SRC_DIR]
107f812 @tobie Modify PrototypeHelper.sprocketize to take a hash of options rather t…
tobie authored
52
a44a8db @tobie 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 Modify PrototypeHelper.sprocketize to take a hash of options rather t…
tobie authored
55 end
56
ea9f797 @tobie Refactor Rakefile.
tobie authored
57 secretary = Sprockets::Secretary.new(
107f812 @tobie Modify PrototypeHelper.sprocketize to take a hash of options rather t…
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 Refactor Rakefile.
tobie authored
62 )
63
107f812 @tobie Modify PrototypeHelper.sprocketize to take a hash of options rather t…
tobie authored
64 secretary.concatenation.save_to(options[:destination])
7762e00 @tobie Reorder repository to allow for custom selector engines to be include…
tobie authored
65 end
66
ea9f797 @tobie Refactor Rakefile.
tobie authored
67 def self.build_doc_for(file)
d11f317 @tobie Update PDoc.
tobie authored
68 rm_rf(DOC_DIR)
69 mkdir_p(DOC_DIR)
732eb3d @savetheclocktower Change how PDoc is told which syntax highlighting engine to use. SYNT…
savetheclocktower authored
70
6839886 @tobie doc: Update PDoc. Default to BlueCloth Markdown parser to avoid Maruk…
tobie authored
71 PDoc.run({
d11f317 @tobie Update PDoc.
tobie authored
72 :source_files => Dir[File.join('src', '**', '*.js')],
6839886 @tobie doc: Update PDoc. Default to BlueCloth Markdown parser to avoid Maruk…
tobie authored
73 :destination => DOC_DIR,
fb93b80 @tobie doc: using pygments for syntax highlighting.
tobie authored
74 :index_page => 'README.markdown',
d11f317 @tobie Update PDoc.
tobie authored
75 :syntax_highlighter => syntax_highlighter,
76 :markdown_parser => :bluecloth,
694f36d @tobie Update to latest version of pdoc.
tobie authored
77 :src_code_href => proc { |file, line|
78 "http://github.com/sstephenson/prototype/blob/#{current_head}/#{file}#LID#{line}"
79 },
5d454e4 @tobie Make documentation pretty urls option false. The Rake task is targete…
tobie authored
80 :pretty_urls => false,
748e73f @tobie Update PDoc yet again.
tobie authored
81 :bust_cache => false,
82 :name => 'Prototype JavaScript Framework',
83 :short_name => 'Prototype',
84 :home_url => 'http://prototypejs.org',
85 :doc_url => 'http://prototypejs.org/doc',
86 :version => PrototypeHelper::VERSION,
87 :copyright_notice => '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>.'
6839886 @tobie doc: Update PDoc. Default to BlueCloth Markdown parser to avoid Maruk…
tobie authored
88 })
ea9f797 @tobie Refactor Rakefile.
tobie authored
89 end
90
732eb3d @savetheclocktower Change how PDoc is told which syntax highlighting engine to use. SYNT…
savetheclocktower authored
91 def self.syntax_highlighter
92 if ENV['SYNTAX_HIGHLIGHTER']
93 highlighter = ENV['SYNTAX_HIGHLIGHTER'].to_sym
94 require_highlighter(highlighter, true)
95 return highlighter
96 end
97
98 SYNTAX_HIGHLIGHTERS.detect { |n| require_highlighter(n) }
99 end
100
101 def self.require_highlighter(name, verbose=false)
102 case name
103 when :pygments
d11f317 @tobie Update PDoc.
tobie authored
104 success = system("pygmentize -V > /dev/null")
732eb3d @savetheclocktower Change how PDoc is told which syntax highlighting engine to use. SYNT…
savetheclocktower authored
105 if !success && verbose
106 puts "\nYou asked to use Pygments, but I can't find the 'pygmentize' binary."
107 puts "To install, visit:\n"
108 puts " http://pygments.org/docs/installation/\n\n"
109 exit
110 end
111 return success # (we have pygments)
112 when :coderay
113 begin
114 require 'coderay'
115 rescue LoadError => e
116 if verbose
117 puts "\nYou asked to use CodeRay, but I can't find the 'coderay' gem. Just run:\n\n"
118 puts " $ gem install coderay"
119 puts "\nand you should be all set.\n\n"
120 exit
121 end
122 return false
123 end
124 return true # (we have CodeRay)
125 when :none
126 return true
127 else
128 puts "\nYou asked to use a syntax highlighter I don't recognize."
129 puts "Valid options: #{SYNTAX_HIGHLIGHTERS.join(', ')}\n\n"
130 exit
131 end
132 end
133
ea9f797 @tobie Refactor Rakefile.
tobie authored
134 def self.require_sprockets
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
135 require_submodule('Sprockets', 'sprockets')
ea9f797 @tobie Refactor Rakefile.
tobie authored
136 end
137
138 def self.require_pdoc
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
139 require_submodule('PDoc', 'pdoc')
ea9f797 @tobie Refactor Rakefile.
tobie authored
140 end
141
142 def self.require_unittest_js
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
143 require_submodule('UnittestJS', 'unittest_js')
ea9f797 @tobie Refactor Rakefile.
tobie authored
144 end
6d70608 @sstephenson Update to Sprockets 0.9.0
authored
145
ea9f797 @tobie Refactor Rakefile.
tobie authored
146 def self.require_caja_builder
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
147 require_submodule('CajaBuilder', 'caja_builder')
ea9f797 @tobie Refactor Rakefile.
tobie authored
148 end
149
75aab03 @tobie Repo and Rakefile refactoring.
tobie authored
150 def self.get_selector_engine(name)
7770ab9 @sstephenson Fix 'rake' without SELECTOR_ENGINE environment variable set
authored
151 return if name == DEFAULT_SELECTOR_ENGINE || !name
74c5d45 @samleb Fix custom selector engine load path resolution.
samleb authored
152 submodule_path = File.join(ROOT_DIR, "vendor", name)
153 return submodule_path if File.exist?(File.join(submodule_path, "repository", ".git"))
d9aee20 @tobie Refactor selector engine wrapper and add convenience helper methods t…
tobie authored
154 return submodule_path if name === "legacy_selector"
74c5d45 @samleb Fix custom selector engine load path resolution.
samleb authored
155 get_submodule('the required selector engine', "#{name}/repository")
9d47112 @tobie Fix typo in Rakefile.
tobie authored
156 unless File.exist?(submodule_path)
74c5d45 @samleb Fix custom selector engine load path resolution.
samleb authored
157 puts "The selector engine you required isn't available at vendor/#{name}.\n\n"
158 exit
15c323b @tobie Include NWMatcher as a submodule.
tobie authored
159 end
160 end
161
d3df9ba @savetheclocktower Automate installation of Git submodules.
savetheclocktower authored
162 def self.get_submodule(name, path)
163 require_git
164 puts "\nYou seem to be missing #{name}. Obtaining it via git...\n\n"
165
166 Kernel.system("git submodule init")
167 return true if Kernel.system("git submodule update vendor/#{path}")
168 # If we got this far, something went wrong.
169 puts "\nLooks like it didn't work. Try it manually:\n\n"
170 puts " $ git submodule init"
171 puts " $ git submodule update vendor/#{path}"
172 false
173 end
174
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
175 def self.require_submodule(name, path)
ea9f797 @tobie Refactor Rakefile.
tobie authored
176 begin
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
177 require path
ea9f797 @tobie Refactor Rakefile.
tobie authored
178 rescue LoadError => e
d3df9ba @savetheclocktower Automate installation of Git submodules.
savetheclocktower authored
179 # Wait until we notice that a submodule is missing before we bother the
180 # user about installing git. (Maybe they brought all the files over
181 # from a different machine.)
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
182 missing_file = e.message.sub('no such file to load -- ', '')
183 if missing_file == path
d3df9ba @savetheclocktower Automate installation of Git submodules.
savetheclocktower authored
184 # Missing a git submodule.
185 retry if get_submodule(name, path)
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
186 else
d3df9ba @savetheclocktower Automate installation of Git submodules.
savetheclocktower authored
187 # Missing a gem.
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
188 puts "\nIt looks like #{name} is missing the '#{missing_file}' gem. Just run:\n\n"
189 puts " $ gem install #{missing_file}"
190 puts "\nand you should be all set.\n\n"
191 end
ea9f797 @tobie Refactor Rakefile.
tobie authored
192 exit
193 end
194 end
d11f317 @tobie Update PDoc.
tobie authored
195
196 def self.current_head
f890b3d @tobie Update PDoc some more.
tobie authored
197 `git show-ref --hash HEAD`.chomp[0..6]
d11f317 @tobie Update PDoc.
tobie authored
198 end
b2597ec @samleb Start PDoc integration.
samleb authored
199 end
200
ea9f797 @tobie Refactor Rakefile.
tobie authored
201 task :default => [:dist, :dist_helper, :package, :clean_package_source]
202
a519c02 @sstephenson Sprocketize Prototype
authored
203 desc "Builds the distribution."
204 task :dist do
107f812 @tobie Modify PrototypeHelper.sprocketize to take a hash of options rather t…
tobie authored
205 PrototypeHelper.sprocketize(
206 :path => 'src',
207 :source => 'prototype.js',
a44a8db @tobie Avoid automatically fetching the vendor/sizzle git submodule.
tobie authored
208 :selector_engine => ENV['SELECTOR_ENGINE'] || PrototypeHelper::DEFAULT_SELECTOR_ENGINE
107f812 @tobie Modify PrototypeHelper.sprocketize to take a hash of options rather t…
tobie authored
209 )
a519c02 @sstephenson Sprocketize Prototype
authored
210 end
211
4428747 @savetheclocktower Updated Rakefile to check for presence of PDoc before running 'doc' t…
savetheclocktower authored
212 namespace :doc do
213 desc "Builds the documentation."
214 task :build => [:require] do
63f96ea @tobie Fixed doc template to allow separate building of the documentation of…
tobie authored
215 PrototypeHelper.build_doc_for(ENV['SECTION'] ? "#{ENV['SECTION']}.js" : 'prototype.js')
732eb3d @savetheclocktower Change how PDoc is told which syntax highlighting engine to use. SYNT…
savetheclocktower authored
216 end
4428747 @savetheclocktower Updated Rakefile to check for presence of PDoc before running 'doc' t…
savetheclocktower authored
217
218 task :require do
ea9f797 @tobie Refactor Rakefile.
tobie authored
219 PrototypeHelper.require_pdoc
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
220 end
221 end
222
4428747 @savetheclocktower Updated Rakefile to check for presence of PDoc before running 'doc' t…
savetheclocktower authored
223 task :doc => ['doc:build']
224
cf5d180 @tobie refactored unit tests quite a bit. Added JS and CSS fixtures.
tobie authored
225 desc "Builds the updating helper."
87ce153 @tobie prototype: Complete rewrite of the deprecation helper.
tobie authored
226 task :dist_helper do
107f812 @tobie Modify PrototypeHelper.sprocketize to take a hash of options rather t…
tobie authored
227 PrototypeHelper.sprocketize(:path => 'ext/update_helper', :source => 'prototype_update_helper.js')
87ce153 @tobie prototype: Complete rewrite of the deprecation helper.
tobie authored
228 end
229
ea9f797 @tobie Refactor Rakefile.
tobie authored
230 Rake::PackageTask.new('prototype', PrototypeHelper::VERSION) do |package|
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
231 package.need_tar_gz = true
ea9f797 @tobie Refactor Rakefile.
tobie authored
232 package.package_dir = PrototypeHelper::PKG_DIR
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
233 package.package_files.include(
234 '[A-Z]*',
235 'dist/prototype.js',
236 'lib/**',
237 'src/**',
238 'test/**'
239 )
240 end
241
52a781a @tobie Switch to UnittestJS.
tobie authored
242 task :clean_package_source do
ea9f797 @tobie Refactor Rakefile.
tobie authored
243 rm_rf File.join(PrototypeHelper::PKG_DIR, "prototype-#{PrototypeHelper::VERSION}")
52a781a @tobie Switch to UnittestJS.
tobie authored
244 end
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
245
52a781a @tobie Switch to UnittestJS.
tobie authored
246 task :test => ['test:build', 'test:run']
247 namespace :test do
248 desc 'Runs all the JavaScript unit tests and collects the results'
249 task :run => [:require] do
250 testcases = ENV['TESTCASES']
251 browsers_to_test = ENV['BROWSERS'] && ENV['BROWSERS'].split(',')
252 tests_to_run = ENV['TESTS'] && ENV['TESTS'].split(',')
ea9f797 @tobie Refactor Rakefile.
tobie authored
253 runner = UnittestJS::WEBrickRunner::Runner.new(:test_dir => PrototypeHelper::TMP_DIR)
52a781a @tobie Switch to UnittestJS.
tobie authored
254
ea9f797 @tobie Refactor Rakefile.
tobie authored
255 Dir[File.join(PrototypeHelper::TMP_DIR, '*_test.html')].each do |file|
52a781a @tobie Switch to UnittestJS.
tobie authored
256 file = File.basename(file)
257 test = file.sub('_test.html', '')
258 unless tests_to_run && !tests_to_run.include?(test)
259 runner.add_test(file, testcases)
260 end
261 end
262
263 UnittestJS::Browser::SUPPORTED.each do |browser|
264 unless browsers_to_test && !browsers_to_test.include?(browser)
265 runner.add_browser(browser.to_sym)
266 end
267 end
268
269 trap('INT') { runner.teardown; exit }
270 runner.run
271 end
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
272
52a781a @tobie Switch to UnittestJS.
tobie authored
273 task :build => [:clean, :dist] do
274 builder = UnittestJS::Builder::SuiteBuilder.new({
ea9f797 @tobie Refactor Rakefile.
tobie authored
275 :input_dir => PrototypeHelper::TEST_UNIT_DIR,
276 :assets_dir => PrototypeHelper::DIST_DIR
52a781a @tobie Switch to UnittestJS.
tobie authored
277 })
278 selected_tests = (ENV['TESTS'] || '').split(',')
279 builder.collect(*selected_tests)
280 builder.render
281 end
ba6934e @tobie Make Rake auto-generate test/unit/temp directory if it is missing.
tobie authored
282
52a781a @tobie Switch to UnittestJS.
tobie authored
283 task :clean => [:require] do
ea9f797 @tobie Refactor Rakefile.
tobie authored
284 UnittestJS::Builder.empty_dir!(PrototypeHelper::TMP_DIR)
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
285 end
286
52a781a @tobie Switch to UnittestJS.
tobie authored
287 task :require do
ea9f797 @tobie Refactor Rakefile.
tobie authored
288 PrototypeHelper.require_unittest_js
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
289 end
290 end
41ef42e @tobie Unit test lib reorganizing.
tobie authored
291
52a781a @tobie Switch to UnittestJS.
tobie authored
292 task :test_units do
293 puts '"rake test_units" is deprecated. Please use "rake test" instead.'
41ef42e @tobie Unit test lib reorganizing.
tobie authored
294 end
295
52a781a @tobie Switch to UnittestJS.
tobie authored
296 task :build_unit_tests do
297 puts '"rake test_units" is deprecated. Please use "rake test:build" instead.'
41ef42e @tobie Unit test lib reorganizing.
tobie authored
298 end
299
300 task :clean_tmp do
52a781a @tobie Switch to UnittestJS.
tobie authored
301 puts '"rake clean_tmp" is deprecated. Please use "rake test:clean" instead.'
41ef42e @tobie Unit test lib reorganizing.
tobie authored
302 end
99f74b5 @tobie Add caja_builder for optional cajoled tests.
tobie authored
303
304 namespace :caja do
305 task :test => ['test:build', 'test:run']
306
307 namespace :test do
308 task :run => ['rake:test:run']
309
310 task :build => [:require, 'rake:test:clean', :dist] do
311 builder = UnittestJS::CajaBuilder::SuiteBuilder.new({
ea9f797 @tobie Refactor Rakefile.
tobie authored
312 :input_dir => PrototypeHelper::TEST_UNIT_DIR,
313 :assets_dir => PrototypeHelper::DIST_DIR,
314 :whitelist_dir => File.join(PrototypeHelper::TEST_DIR, 'unit', 'caja_whitelists'),
99f74b5 @tobie Add caja_builder for optional cajoled tests.
tobie authored
315 :html_attrib_schema => 'html_attrib.json'
316 })
317 selected_tests = (ENV['TESTS'] || '').split(',')
318 builder.collect(*selected_tests)
319 builder.render
320 end
321 end
322 task :require => ['rake:test:require'] do
ea9f797 @tobie Refactor Rakefile.
tobie authored
323 PrototypeHelper.require_caja_builder
99f74b5 @tobie Add caja_builder for optional cajoled tests.
tobie authored
324 end
325 end
Something went wrong with that request. Please try again.