Skip to content

Commit 920c85a

Browse files
author
Luca Guidi
committed
Hide development related tasks to end users
1 parent 0d68a1a commit 920c85a

File tree

2 files changed

+65
-84
lines changed

2 files changed

+65
-84
lines changed

Diff for: Rakefile

+65
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@ require 'rake'
22
require 'rake/testtask'
33
require 'rake/rdoctask'
44

5+
rails_root = File.expand_path(RAILS_ROOT)
6+
plugin_root = File.join(rails_root, 'vendor', 'plugins', 'click-to-globalize')
7+
templates_root = File.join(plugin_root, 'templates')
8+
shared_folder = File.join(rails_root, 'app', 'views', 'shared')
9+
10+
require plugin_root + '/test/javascript/lib/jstest'
11+
12+
files = [ File.join(rails_root, 'public', 'javascripts', 'click_to_globalize.js'),
13+
File.join(rails_root, 'public', 'stylesheets', 'click_to_globalize.css'),
14+
File.join(rails_root, 'app', 'controllers', 'locales_controller.rb'),
15+
File.join(rails_root, 'app', 'helpers', 'locales_helper.rb'),
16+
File.join(rails_root, 'app', 'views', 'shared', '_click_to_globalize.html.erb'),
17+
File.join(rails_root, 'config', 'click.yml') ]
18+
519
desc 'Default: run unit tests.'
620
task :default => :test
721

@@ -21,3 +35,54 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
2135
rdoc.rdoc_files.include('README')
2236
rdoc.rdoc_files.include('lib/**/*.rb')
2337
end
38+
39+
desc 'Test Click To Globalize.'
40+
task :test => ['click:test:all']
41+
42+
namespace :test do
43+
desc 'Test both ruby and javascript code.'
44+
task :all => [:ruby, :js]
45+
46+
desc 'Test ruby code.'
47+
Rake::TestTask.new(:ruby) do |t|
48+
t.libs << "#{plugin_root}/lib"
49+
t.libs << "#{plugin_root}/test/test_helper"
50+
t.pattern = "#{plugin_root}/test/**/*_test.rb"
51+
t.verbose = true
52+
end
53+
54+
# Taken from Prototype rake tasks.
55+
desc "Runs all the JavaScript unit tests and collects the results"
56+
JavaScriptTestTask.new(:js) do |t|
57+
tests_to_run = ENV['TESTS'] && ENV['TESTS'].split(',')
58+
browsers_to_test = ENV['BROWSERS'] && ENV['BROWSERS'].split(',')
59+
60+
t.mount("/public", "#{rails_root}/public")
61+
t.mount("/test", "#{plugin_root}/test")
62+
63+
test_files = (Dir["#{plugin_root}/test/unit/*.html"] + Dir["#{plugin_root}/test/functional/*.html"])
64+
test_files.sort.reverse.each do |test_file|
65+
test_file = test_file.gsub(plugin_root, '')
66+
test_name = test_file[/.*\/(.+?)\.html/, 1]
67+
t.run(test_file) unless tests_to_run && !tests_to_run.include?(test_name)
68+
end
69+
70+
%w( safari firefox ie konqueror opera ).each do |browser|
71+
t.browser(browser.to_sym) unless browsers_to_test && !browsers_to_test.include?(browser)
72+
end
73+
end
74+
end
75+
76+
desc 'Show the diffs for each file, camparing the app files with the plugin ones.'
77+
task :diff do
78+
files.each do |file, path|
79+
file = path.split(File::SEPARATOR).last
80+
res = `diff #{path} #{templates_root}/#{file}`
81+
puts "#{file.upcase}\n#{res}" unless res.empty?
82+
end
83+
end
84+
85+
desc 'Prepare the folder plugin, copying files from the app, here.'
86+
task :prepare do
87+
files.each { |file, path| File.cp path, templates_root }
88+
end

Diff for: tasks/click_to_globalize.rake

-84
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,9 @@
11
require 'rake'
22
require 'rake/testtask'
33
require 'rake/rdoctask'
4-
require 'erb'
5-
require 'rubygems'
6-
require 'active_record'
7-
require 'active_record/fixtures'
84
require 'ftools'
95

10-
rails_root = File.expand_path(RAILS_ROOT)
11-
plugin_root = File.join(rails_root, 'vendor', 'plugins', 'click-to-globalize')
12-
templates_root = File.join(plugin_root, 'templates')
13-
shared_folder = File.join(rails_root, 'app', 'views', 'shared')
14-
15-
require plugin_root + '/test/javascript/lib/jstest'
16-
17-
files = [ File.join(rails_root, 'public', 'javascripts', 'click_to_globalize.js'),
18-
File.join(rails_root, 'public', 'stylesheets', 'click_to_globalize.css'),
19-
File.join(rails_root, 'app', 'controllers', 'locales_controller.rb'),
20-
File.join(rails_root, 'app', 'helpers', 'locales_helper.rb'),
21-
File.join(rails_root, 'app', 'views', 'shared', '_click_to_globalize.html.erb'),
22-
File.join(rails_root, 'config', 'click.yml') ]
23-
24-
desc 'Default: run click task.'
25-
task :default => :click
26-
27-
desc 'Run tests.'
28-
task :click => ['click:test']
29-
306
namespace :click do
31-
desc 'Test Click To Globalize.'
32-
task :test => ['click:test:all']
33-
34-
namespace :test do
35-
desc 'Test both ruby and javascript code.'
36-
task :all => [:ruby, :js]
37-
38-
desc 'Test ruby code.'
39-
Rake::TestTask.new(:ruby) do |t|
40-
t.libs << "#{plugin_root}/lib"
41-
t.libs << "#{plugin_root}/test/test_helper"
42-
t.pattern = "#{plugin_root}/test/**/*_test.rb"
43-
t.verbose = true
44-
end
45-
46-
# Taken from Prototype rake tasks.
47-
desc "Runs all the JavaScript unit tests and collects the results"
48-
JavaScriptTestTask.new(:js) do |t|
49-
tests_to_run = ENV['TESTS'] && ENV['TESTS'].split(',')
50-
browsers_to_test = ENV['BROWSERS'] && ENV['BROWSERS'].split(',')
51-
52-
t.mount("/public", "#{rails_root}/public")
53-
t.mount("/test", "#{plugin_root}/test")
54-
55-
test_files = (Dir["#{plugin_root}/test/unit/*.html"] + Dir["#{plugin_root}/test/functional/*.html"])
56-
test_files.sort.reverse.each do |test_file|
57-
test_file = test_file.gsub(plugin_root, '')
58-
test_name = test_file[/.*\/(.+?)\.html/, 1]
59-
t.run(test_file) unless tests_to_run && !tests_to_run.include?(test_name)
60-
end
61-
62-
%w( safari firefox ie konqueror opera ).each do |browser|
63-
t.browser(browser.to_sym) unless browsers_to_test && !browsers_to_test.include?(browser)
64-
end
65-
end
66-
67-
desc 'Generate documentation for Click to Globalize plugin.'
68-
Rake::RDocTask.new(:rdoc) do |rdoc|
69-
rdoc.rdoc_dir = "#{plugin_root}/rdoc"
70-
rdoc.title = 'ClickToGlobalize'
71-
rdoc.options << '--line-numbers' << '--inline-source'
72-
rdoc.rdoc_files.include("#{plugin_root}/README")
73-
rdoc.rdoc_files.include("#{plugin_root}/lib/**/*.rb")
74-
end
75-
end
76-
777
desc 'Setup Click to Globalize plugin (alias for click:install).'
788
task :setup => :install
799

@@ -91,18 +21,4 @@ namespace :click do
9121
targets = Dir["#{Rails.root}/public/**/click_to_globalize.*"]
9222
FileUtils.rm targets
9323
end
94-
95-
desc 'Show the diffs for each file, camparing the app files with the plugin ones.'
96-
task :diff do
97-
files.each do |file, path|
98-
file = path.split(File::SEPARATOR).last
99-
res = `diff #{path} #{templates_root}/#{file}`
100-
puts "#{file.upcase}\n#{res}" unless res.empty?
101-
end
102-
end
103-
104-
desc 'Prepare the folder plugin, copying files from the app, here.'
105-
task :prepare do
106-
files.each { |file, path| File.cp path, templates_root }
107-
end
10824
end

0 commit comments

Comments
 (0)