Skip to content

Commit

Permalink
added build rake tasks, and a real distro package (including dialogs …
Browse files Browse the repository at this point in the history
…and modals where possible)
  • Loading branch information
jejacks0n committed Jun 25, 2011
1 parent 28392f3 commit 3e3729f
Show file tree
Hide file tree
Showing 9 changed files with 18,675 additions and 40 deletions.
166 changes: 126 additions & 40 deletions Rakefile
Expand Up @@ -2,65 +2,71 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end

require File.expand_path('../config/application', __FILE__)

Mercury::Application.load_tasks

#
# Cucumber
# Cucumber tasks
#
unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?

vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
begin
require 'cucumber/rake/task'

begin
require 'cucumber/rake/task'
namespace :cucumber do
Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
t.fork = true # You may get faster startup if you set this to false
t.profile = 'default'
end

namespace :cucumber do
Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
t.fork = true # You may get faster startup if you set this to false
t.profile = 'default'
end
Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
t.binary = vendored_cucumber_bin
t.fork = true # You may get faster startup if you set this to false
t.profile = 'wip'
end

Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
t.binary = vendored_cucumber_bin
t.fork = true # You may get faster startup if you set this to false
t.profile = 'wip'
end
Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
t.binary = vendored_cucumber_bin
t.fork = true # You may get faster startup if you set this to false
t.profile = 'rerun'
end

Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
t.binary = vendored_cucumber_bin
t.fork = true # You may get faster startup if you set this to false
t.profile = 'rerun'
desc 'Run all features'
task :all => [:ok, :wip]
end
desc 'Alias for cucumber:ok'
task :cucumber => 'cucumber:ok'

desc 'Run all features'
task :all => [:ok, :wip]
end
desc 'Alias for cucumber:ok'
task :cucumber => 'cucumber:ok'

task :default => :cucumber
task :default => :cucumber

task :features => :cucumber do
STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
end
task :features => :cucumber do
STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
end

# In case we don't have ActiveRecord, append a no-op task that we can depend upon.
task 'db:test:prepare' do
end
rescue LoadError
desc 'cucumber rake task not available (cucumber not installed)'
task :cucumber do
abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
# In case we don't have ActiveRecord, append a no-op task that we can depend upon.
task 'db:test:prepare' do
end
rescue LoadError
desc 'cucumber rake task not available (cucumber not installed)'
task :cucumber do
abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
end
end
end

end


#
# Jeweler tasks
#
require 'jeweler'
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
Expand Down Expand Up @@ -99,3 +105,83 @@ Jeweler::Tasks.new do |gem|
end
end
Jeweler::RubygemsDotOrgTasks.new

#
# Mercury build tasks
#
namespace :mercury do
desc "Builds Mercury into the distro ready package"
task :build => ['build:dialogs', 'build:javascripts', 'build:stylesheets'] do
end

namespace :build do

desc "Combines all dialog and model views into a js file"
task :dialogs => :environment do
input = Rails.root.join('app/views')
File.open(Rails.root.join('public/mercury_distro/javascripts/mercury_dialogs.js'), 'w') do |file|
%w[modals palettes panels selects].each do |path|
file.write "// -- #{path.upcase} --\n"
Dir[input.join('mercury', path, '*.html')].sort.each do |filename|
file.write %Q{Mercury.preloadedViews['#{filename.gsub(input.to_s, '').gsub(/\.html$/, '')}'] = "}
File.foreach(filename) { |line| file.write line.chomp.gsub('"', '\\"') }
file.write %Q{";\n}
end
end
end
end

desc "Combine javascripts into mercury.js and mercury.min.js"
task :javascripts => :environment do
require 'action_view/helpers/asset_tag_helpers/asset_paths.rb'
Sprockets::Helpers::RailsHelper
Rails.application.assets.precompile('mercury.js')
Dir[Rails.root.join('public/assets/mercury-*.js')].each do |filename|
copy_file(filename, Rails.root.join('public/mercury_distro/javascripts/mercury.js'))
remove(filename)
end

minified = Uglifier.compile(File.read(Rails.root.join('public/mercury_distro/javascripts/mercury.js')))
File.open(Rails.root.join('public/mercury_distro/javascripts/mercury.min.js'), 'w') do |file|
file.write(minified)
end
end

desc "Combine stylesheets into mercury.css and mercury.bundle.css (bundling images where possible)"
task :stylesheets => :environment do
require 'base64'
require 'action_view/helpers/asset_tag_helpers/asset_paths.rb'
Sprockets::Helpers::RailsHelper
Rails.application.assets.precompile('mercury.css')

Dir[Rails.root.join('public/assets/mercury-*.css')].each do |filename|
copy_file(filename, Rails.root.join('public/mercury_distro/stylesheets/mercury.css'))
remove(filename)
end

bundled = File.read(Rails.root.join('public/mercury_distro/stylesheets/mercury.css'))

# import image files using: url(data:image/gif;base64,XEQA7)
bundled.gsub!(/url\(\/assets\/(.*?)\)/ix) do |m|
encoded = Base64.encode64(File.read(Rails.root.join('app/assets/images', $1))).gsub("\n", '')
"url(data:image/png;base64,#{encoded})"
end

# remove comments (only /* */ style)
bundled.gsub!(/\/\*[^!].*?\*\//m, '')

# remove whitespace
bundled.gsub!(/\s+/, ' ')

# put a few line breaks back in
bundled.gsub!(/\}/, "}\n")
bundled.gsub!(/ \*/, "\n *")
bundled.gsub!(/ \*\//, " */\n")

File.open(Rails.root.join('public/mercury_distro/stylesheets/mercury.bundle.css'), 'wb') do |file|
file.write(bundled)
end
end

end
end
1 change: 1 addition & 0 deletions app/assets/javascripts/mercury/mercury.js.coffee
Expand Up @@ -40,6 +40,7 @@ jQuery.extend Mercury, {
Regions: {}
modalHandlers: {}
dialogHandlers: {}
preloadedViews: {}

# Custom event and logging methods
bind: (eventName, callback) ->
Expand Down

0 comments on commit 3e3729f

Please sign in to comment.