Permalink
Browse files

generate all.js from `rake radiant:gem` task. closes #90

  • Loading branch information...
1 parent 00a5f68 commit 86bea012e643d2bccb84c1a501e556dc9167fe4a @johnmuhl johnmuhl committed Jun 24, 2010
Showing with 28 additions and 3 deletions.
  1. +6 −1 lib/task_support.rb
  2. +1 −2 lib/tasks/framework.rake
  3. +7 −0 lib/tasks/release.rake
  4. +14 −0 spec/lib/task_support_spec.rb
View
@@ -44,10 +44,15 @@ def cache_files(dir, files, cache_file)
# Reads through the layout file and returns an array of JS filenames
#
def find_admin_js
- layout = File.join(RADIANT_ROOT, 'app', 'views', 'layouts', 'application.html.haml')
+ layout = "#{RADIANT_ROOT}/app/views/layouts/application.html.haml"
js_regexp = /javascript_include_tag %w\((.*)\), :cache => 'admin\/all/
files = File.open(layout) { |f| f.read.match(js_regexp)[1].split }
files.collect { |f| f.split('/').last + '.js' }
end
+
+ def cache_admin_js
+ dir = "#{Rails.root}/public/javascripts/admin"
+ cache_files(dir, find_admin_js, 'all.js')
+ end
end
end
View
@@ -106,8 +106,7 @@ unless File.directory? "#{RAILS_ROOT}/app"
desc "Update the cached assets for the admin UI"
task :cached_assets do
- dir = File.join(Rails.root, 'public', 'javascripts', 'admin')
- TaskSupport.cache_files(dir, TaskSupport.find_admin_js, 'all.js')
+ TaskSupport.cache_admin_js
end
desc "Update config/boot.rb from your current radiant install"
View
@@ -97,6 +97,13 @@ namespace 'radiant' do
end
end
+ task :gem => [ :generate_cached_assets ]
+
+ desc "Generates cached assets from source files"
+ task :generate_cached_assets do
+ TaskSupport.cache_admin_js
+ end
+
desc "Publish the release files to RubyForge."
task :release => [:gem, :package] do
files = ["gem", "tgz", "zip"].map { |ext| "pkg/#{PKG_FILE_NAME}.#{ext}" }
@@ -70,4 +70,18 @@
js_files.each { |f| f.should =~ /^[^\/]+.js$/ }
end
end
+
+ describe "self.cache_admin_js" do
+ before do
+ @js_files = [ 'a.js','b.js' ]
+ TaskSupport.stub!(:find_admin_js).and_return(@js_files)
+ TaskSupport.stub!(:cache_files)
+ end
+
+ it "should cache all admin JS files as 'all.js'" do
+ TaskSupport.should_receive(:cache_files).with(
+ "#{Rails.root}/public/javascripts/admin", @js_files, 'all.js')
+ TaskSupport.cache_admin_js
+ end
+ end
end

0 comments on commit 86bea01

Please sign in to comment.