Skip to content

Instantly share code, notes, and snippets.

@asmala
Created March 30, 2010 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asmala/349507 to your computer and use it in GitHub Desktop.
Save asmala/349507 to your computer and use it in GitHub Desktop.
From be6bf883b665ae5cf6f27d03290c9e8d92d566c2 Mon Sep 17 00:00:00 2001
From: Janne Asmala <janne@asmala.name>
Date: Tue, 30 Mar 2010 22:42:43 +0300
Subject: [PATCH] Added rake task to pre-cache admin UI Javascripts when updating Radiant assets. This removes a pain encountered when deploying on read-only filesystems such as the one used on Heroku.
---
lib/tasks/framework.rake | 22 +++++++++++++++++++++-
1 files changed, 21 insertions(+), 1 deletions(-)
diff --git a/lib/tasks/framework.rake b/lib/tasks/framework.rake
index 50a3971..5bd4205 100644
--- a/lib/tasks/framework.rake
+++ b/lib/tasks/framework.rake
@@ -62,7 +62,7 @@ unless File.directory? "#{RAILS_ROOT}/app"
end
desc "Update both configs, sass and public/javascripts from Radiant"
- task :update => [ "update:scripts", "update:javascripts", "update:configs", "update:images", "update:sass" ]
+ task :update => [ "update:scripts", "update:javascripts", "update:configs", "update:images", "update:sass", "update:cached_assets" ]
namespace :update do
desc "Add new scripts to the instance script/ directory"
@@ -96,6 +96,26 @@ unless File.directory? "#{RAILS_ROOT}/app"
copy_javascripts[RAILS_ROOT + '/public/javascripts/admin/', Dir["#{File.dirname(__FILE__)}/../../public/javascripts/admin/*.js"]]
end
+ desc "Update the cached assets for the admin UI"
+ task :cached_assets do
+ js_dir = File.join(Rails.root, 'public', 'javascripts')
+ layout = File.join(RADIANT_ROOT, 'app', 'views', 'layouts', 'application.html.haml')
+
+ js_files = File.open(layout) do |f|
+ f.read.match(/javascript_include_tag %w\((.*)\), :cache => 'admin\/all/)[1].split
+ end
+
+ js_paths = js_files.collect { |f| File.join(js_dir, f + '.js') }
+ js_cache = File.join(js_dir, 'admin', 'all.js')
+ rm(js_cache) if File.exists?(js_cache)
+
+ cached_js = js_paths.collect { |js| File.read(js) }.join("\n\n")
+
+ File.open(js_cache, "w+") do |f|
+ f.write(cached_js)
+ end
+ end
+
desc "Update config/boot.rb from your current radiant install"
task :configs do
require 'erb'
--
1.6.1.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment