Created
April 6, 2010 17:34
-
-
Save asmala/357852 to your computer and use it in GitHub Desktop.
Refactored JS caching tasks for easier reuse and added it to the gem task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 480099452f61b360bd637b1e095eafcf3407a29b Mon Sep 17 00:00:00 2001 | |
From: Janne Asmala <janne@asmala.name> | |
Date: Tue, 6 Apr 2010 20:31:52 +0300 | |
Subject: [PATCH] Refactored JS caching tasks for easier reuse and added it to the gem task. | |
--- | |
lib/task_support.rb | 7 ++++++- | |
lib/tasks/framework.rake | 3 +-- | |
lib/tasks/release.rake | 7 +++++++ | |
spec/lib/task_support_spec.rb | 14 ++++++++++++++ | |
4 files changed, 28 insertions(+), 3 deletions(-) | |
diff --git a/lib/task_support.rb b/lib/task_support.rb | |
index bbaad39..c8406ac 100644 | |
--- a/lib/task_support.rb | |
+++ b/lib/task_support.rb | |
@@ -44,10 +44,15 @@ class TaskSupport | |
# 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 | |
diff --git a/lib/tasks/framework.rake b/lib/tasks/framework.rake | |
index 3650a97..e537a3f 100644 | |
--- a/lib/tasks/framework.rake | |
+++ b/lib/tasks/framework.rake | |
@@ -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" | |
diff --git a/lib/tasks/release.rake b/lib/tasks/release.rake | |
index d5513e5..3f75ef1 100644 | |
--- a/lib/tasks/release.rake | |
+++ b/lib/tasks/release.rake | |
@@ -96,6 +96,13 @@ namespace 'radiant' do | |
end | |
end | |
+ task :gem => [ :generate_cached_assets ] | |
+ | |
+ desc "Generates cached assets from source files" | |
+ task :generate_cached_assets | |
+ 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}" } | |
diff --git a/spec/lib/task_support_spec.rb b/spec/lib/task_support_spec.rb | |
index 773f2c8..a0ff705 100644 | |
--- a/spec/lib/task_support_spec.rb | |
+++ b/spec/lib/task_support_spec.rb | |
@@ -70,4 +70,18 @@ describe TaskSupport do | |
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 | |
\ No newline at end of file | |
-- | |
1.6.1.3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment