Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 265 lines (221 sloc) 9.232 kB
e9071aa @jejacks0n initial commit
authored
1 #!/usr/bin/env rake
2 # Add your own tasks in files placed in lib/tasks ending in .rake,
3 # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
3e3729f @jejacks0n added build rake tasks, and a real distro package (including dialogs …
authored
5 begin
23a5455 @jejacks0n updated how gemspec works -- removed jeweler, sass-rails, and json de…
authored
6 require 'bundler/gem_tasks'
3e3729f @jejacks0n added build rake tasks, and a real distro package (including dialogs …
authored
7 rescue LoadError
8 puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
9 end
10
e9071aa @jejacks0n initial commit
authored
11 require File.expand_path('../config/application', __FILE__)
12
af96d67 @jejacks0n renamed the project
authored
13 Mercury::Application.load_tasks
2ad23e0 @jejacks0n minor updates to rake tasks, readme, and views
authored
14
15 #
3e3729f @jejacks0n added build rake tasks, and a real distro package (including dialogs …
authored
16 # Mercury build tasks
17 #
18 namespace :mercury do
fd05d32 @jejacks0n updated the build tasks, and added a document task that just shells a…
authored
19
20 desc "Builds the documentation using docco"
21 task :document do
0f6e8ef @jejacks0n switching the documentation to rocco since it's easier for us to twea…
authored
22 require 'rocco'
492f65c @jejacks0n updated the annotated source.
authored
23 output_dir = Rails.root.join('annotated_source').to_s
0f6e8ef @jejacks0n switching the documentation to rocco since it's easier for us to twea…
authored
24 sources = Dir[Rails.root.join('vendor/assets/javascripts/*.js').to_s]
25 sources += Dir[Rails.root.join('vendor/assets/javascripts/**/*.coffee').to_s]
26 sources.each do |filename|
492f65c @jejacks0n updated the annotated source.
authored
27 rocco = Rocco.new(filename, sources, {:template_file => Rails.root.join('annotated_source.template'), :docblocks => true})
0f6e8ef @jejacks0n switching the documentation to rocco since it's easier for us to twea…
authored
28 dest = File.join(output_dir, filename.sub(Regexp.new("^#{Rails.root.join('vendor/assets/javascripts')}"), '').sub(Regexp.new("#{File.extname(filename)}$"),".html"))
29 puts "rocco: #{filename} -> #{dest}"
30 FileUtils.mkdir_p File.dirname(dest)
31 File.open(dest, 'wb') { |fd| fd.write(rocco.to_html) }
32 end
3e3729f @jejacks0n added build rake tasks, and a real distro package (including dialogs …
authored
33 end
34
7ca5ff7 @jejacks0n updated the version, bundled, created a distro package and renamed th…
authored
35 desc "Builds Mercury into the distribution ready package"
fd05d32 @jejacks0n updated the build tasks, and added a document task that just shells a…
authored
36 task :build => ['build:dialogs', 'build:javascripts', 'build:stylesheets']
37
3e3729f @jejacks0n added build rake tasks, and a real distro package (including dialogs …
authored
38 namespace :build do
39
40 desc "Combines all dialog and model views into a js file"
41 task :dialogs => :environment do
42 input = Rails.root.join('app/views')
7ca5ff7 @jejacks0n updated the version, bundled, created a distro package and renamed th…
authored
43 File.open(Rails.root.join('public/mercury/javascripts/mercury_dialogs.js'), 'w') do |file|
25ab0b2 @jejacks0n updated rakefile and loader
authored
44 file.write "if (!window.Mercury) window.Mercury = {preloadedViews: {}};\n"
5c7a97e @jejacks0n added lightviews to the dialogs that are preloaded (primarily for the…
authored
45 %w[lightviews modals palettes panels selects].each do |path|
3e3729f @jejacks0n added build rake tasks, and a real distro package (including dialogs …
authored
46 file.write "// -- #{path.upcase} --\n"
47 Dir[input.join('mercury', path, '*.html')].sort.each do |filename|
7d63d34 @jejacks0n adjusted configuration to include html extensions on files that are l…
authored
48 file.write %Q{Mercury.preloadedViews['#{filename.gsub(input.to_s, '')}'] = "}
3e3729f @jejacks0n added build rake tasks, and a real distro package (including dialogs …
authored
49 File.foreach(filename) { |line| file.write line.chomp.gsub('"', '\\"') }
50 file.write %Q{";\n}
51 end
52 end
53 end
54 end
55
56 desc "Combine javascripts into mercury.js and mercury.min.js"
57 task :javascripts => :environment do
3511002 updating the build tasks (lamely) to work with the current Sprockets:…
Glen Ivey & Jeremy Jackson authored
58 config = Rails.application.config
59 env = Rails.application.assets
60 target = Pathname.new(File.join(Rails.public_path, config.assets.prefix))
61 manifest = {}
62
63 ['mercury.js', 'mercury/mercury.js'].each do |path|
64 env.each_logical_path do |logical_path|
65 if path.is_a?(Regexp)
66 next unless path.match(logical_path)
67 else
68 next unless File.fnmatch(path.to_s, logical_path)
69 end
70
71 if asset = env.find_asset(logical_path)
72 manifest[logical_path] = asset.digest_path
73 filename = target.join(asset.digest_path)
74 mkdir_p filename.dirname
75 asset.write_to(filename)
76 end
77 end
78 end
79
3e3729f @jejacks0n added build rake tasks, and a real distro package (including dialogs …
authored
80 Dir[Rails.root.join('public/assets/mercury-*.js')].each do |filename|
7ca5ff7 @jejacks0n updated the version, bundled, created a distro package and renamed th…
authored
81 copy_file(filename, Rails.root.join('public/mercury/javascripts/mercury.js'))
3e3729f @jejacks0n added build rake tasks, and a real distro package (including dialogs …
authored
82 remove(filename)
4e4b992 @jejacks0n updated build process and minified js
authored
83 end
3e3729f @jejacks0n added build rake tasks, and a real distro package (including dialogs …
authored
84
4e4b992 @jejacks0n updated build process and minified js
authored
85 Dir[Rails.root.join('public/assets/mercury/mercury-*.js')].each do |filename|
86 copy_file(filename, Rails.root.join('public/mercury/javascripts/mercury.min.js'))
87 remove(filename)
88 minified = Uglifier.compile(File.read(Rails.root.join('vendor/assets/javascripts/mercury/dependencies/jquery-1.7.js')))
89 minified += Uglifier.compile(File.read(Rails.root.join('public/mercury/javascripts/mercury.min.js')))
7ca5ff7 @jejacks0n updated the version, bundled, created a distro package and renamed th…
authored
90 File.open(Rails.root.join('public/mercury/javascripts/mercury.min.js'), 'w') do |file|
4e4b992 @jejacks0n updated build process and minified js
authored
91 file.write(File.read(Rails.root.join('vendor/assets/javascripts/mercury.js')))
1be511b @jejacks0n Adjusted the build process to put the configuration at the top of the…
authored
92 file.write(minified)
93 end
3e3729f @jejacks0n added build rake tasks, and a real distro package (including dialogs …
authored
94 end
fd05d32 @jejacks0n updated the build tasks, and added a document task that just shells a…
authored
95
7ca5ff7 @jejacks0n updated the version, bundled, created a distro package and renamed th…
authored
96 copy_file(Rails.root.join('vendor/assets/javascripts/mercury_loader.js'), Rails.root.join('public/mercury/javascripts/mercury_loader.js'))
3e3729f @jejacks0n added build rake tasks, and a real distro package (including dialogs …
authored
97 end
98
99 desc "Combine stylesheets into mercury.css and mercury.bundle.css (bundling images where possible)"
100 task :stylesheets => :environment do
3511002 updating the build tasks (lamely) to work with the current Sprockets:…
Glen Ivey & Jeremy Jackson authored
101 config = Rails.application.config
102 env = Rails.application.assets
103 target = Pathname.new(File.join(Rails.public_path, config.assets.prefix))
104 manifest = {}
105
106 ['mercury.css'].each do |path|
107 env.each_logical_path do |logical_path|
108 if path.is_a?(Regexp)
109 next unless path.match(logical_path)
110 else
111 next unless File.fnmatch(path.to_s, logical_path)
112 end
113
114 if asset = env.find_asset(logical_path)
115 manifest[logical_path] = asset.digest_path
116 filename = target.join(asset.digest_path)
117 mkdir_p filename.dirname
118 asset.write_to(filename)
119 end
120 end
121 end
3e3729f @jejacks0n added build rake tasks, and a real distro package (including dialogs …
authored
122
123 Dir[Rails.root.join('public/assets/mercury-*.css')].each do |filename|
7ca5ff7 @jejacks0n updated the version, bundled, created a distro package and renamed th…
authored
124 copy_file(filename, Rails.root.join('public/mercury/stylesheets/mercury.css'))
3e3729f @jejacks0n added build rake tasks, and a real distro package (including dialogs …
authored
125 remove(filename)
126 end
127
7ca5ff7 @jejacks0n updated the version, bundled, created a distro package and renamed th…
authored
128 bundled = File.read(Rails.root.join('public/mercury/stylesheets/mercury.css'))
3e3729f @jejacks0n added build rake tasks, and a real distro package (including dialogs …
authored
129
130 # import image files using: url(data:image/gif;base64,XEQA7)
131 bundled.gsub!(/url\(\/assets\/(.*?)\)/ix) do |m|
139f574 @jejacks0n updated build tasks and distro files
authored
132 encoded = Base64.encode64(File.read(Rails.root.join('vendor/assets/images', $1))).gsub("\n", '')
3e3729f @jejacks0n added build rake tasks, and a real distro package (including dialogs …
authored
133 "url(data:image/png;base64,#{encoded})"
134 end
135
136 # remove comments (only /* */ style)
137 bundled.gsub!(/\/\*[^!].*?\*\//m, '')
138
139 # remove whitespace
140 bundled.gsub!(/\s+/, ' ')
141
142 # put a few line breaks back in
143 bundled.gsub!(/\}/, "}\n")
144 bundled.gsub!(/ \*/, "\n *")
145 bundled.gsub!(/ \*\//, " */\n")
146
7ca5ff7 @jejacks0n updated the version, bundled, created a distro package and renamed th…
authored
147 File.open(Rails.root.join('public/mercury/stylesheets/mercury.bundle.css'), 'wb') do |file|
3e3729f @jejacks0n added build rake tasks, and a real distro package (including dialogs …
authored
148 file.write(bundled)
149 end
150 end
151
152 end
153 end
23a5455 @jejacks0n updated how gemspec works -- removed jeweler, sass-rails, and json de…
authored
154
155 #
156 # Cucumber tasks
157 #
158 unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
159 vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
160 $LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
161
162 begin
163 require 'cucumber/rake/task'
164
165 namespace :cucumber do
166 Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
167 t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
168 t.fork = true # You may get faster startup if you set this to false
169 t.profile = 'default'
170 end
171
172 Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
173 t.binary = vendored_cucumber_bin
174 t.fork = true # You may get faster startup if you set this to false
175 t.profile = 'wip'
176 end
177
178 Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
179 t.binary = vendored_cucumber_bin
180 t.fork = true # You may get faster startup if you set this to false
181 t.profile = 'rerun'
182 end
183
184 desc 'Run all features'
185 task :all => [:ok, :wip]
186 end
187 desc 'Alias for cucumber:ok'
188 task :cucumber => 'cucumber:ok'
189
190 task :default => :cucumber
191
192 task :features => :cucumber do
193 STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
194 end
195
196 # In case we don't have ActiveRecord, append a no-op task that we can depend upon.
197 task 'db:test:prepare' do
198 end
199 rescue LoadError
200 desc 'cucumber rake task not available (cucumber not installed)'
201 task :cucumber do
202 abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
203 end
204 end
205 end
8a53507 @mixonic Add a gemspec task to populate the gemspec and avoid git calls.
mixonic authored
206
207 # Always build the gemspec before build
208 task :release => :gemspec
209 task :build => :gemspec
210
211 desc "Generate the .gemspec manifest"
212 task :gemspec do
213 # read spec file and split out manifest section
214 #
215 spec = File.read(File.join(File.dirname(__FILE__), 'mercury-rails.gemspec'))
216 head, manifest, tail = spec.split(" # = MANIFEST =\n")
217
218 replace_header(head, :date)
219
220 # determine file list from git ls-files
221 files = `git ls-files`.
222 split("\n").
223 sort.
224 reject { |file| file =~ /^\./ }.
225 select { |file| file =~ %r{^(lib/|vendor/assets/|app/|db/migrate/|config/engine\.rb)} }.
226 map { |file| " #{file}" }.
227 join("\n")
228
229 test_files = `git ls-files -- {test,spec,features}/*`.
230 split("\n").
231 sort.
232 map { |file| " #{file}" }.
233 join("\n")
234
235 executables = `git ls-files -- bin/*`.
236 split("\n").
237 sort.
238 map{ |f| " #{File.basename(f)}" }.
239 join("\n")
240
241 # piece file back together and write
242 manifest = <<MANIFEST
243 s.files = %w[
244 #{files}
245 ]
246 s.test_files = %w[
247 #{test_files}
248 ]
249 s.executables = %w[
250 #{executables}
251 ]
252 MANIFEST
253 spec = [head, manifest, tail].join(" # = MANIFEST =\n")
254 File.open(File.join(File.dirname(__FILE__), 'mercury-rails.gemspec'), 'w') { |io| io.write(spec) }
255 puts "Updated mercury-rails.gemspec"
256 end
257
258 def replace_header(head, header_name)
259 head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
260 end
261
262 def date
263 Date.today.to_s
264 end
Something went wrong with that request. Please try again.