Skip to content

Instantly share code, notes, and snippets.

@asmala
Created March 30, 2010 06:28
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/348832 to your computer and use it in GitHub Desktop.
Save asmala/348832 to your computer and use it in GitHub Desktop.
A patch to add a rake task that creates the cached admin JS
From c59555cc08ccdcf668c96a7ccf4e06a2aa6a9b9f Mon Sep 17 00:00:00 2001
From: Janne Asmala <janne@asmala.name>
Date: Sun, 28 Mar 2010 08:55:52 +0300
Subject: [PATCH] Added script 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 | 17 ++++++++++++++++-
1 files changed, 16 insertions(+), 1 deletions(-)
diff --git a/lib/tasks/framework.rake b/lib/tasks/framework.rake
index ac9dfb3..606b1e5 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, scripts and public/javascripts from Radiant"
- task :update => [ "update:scripts", "update:javascripts", "update:configs", "update:images", "update:stylesheets" ]
+ task :update => [ "update:scripts", "update:javascripts", "update:configs", "update:images", "update:stylesheets", "update:cached_assets" ]
namespace :update do
desc "Add new scripts to the instance script/ directory"
@@ -96,6 +96,21 @@ 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', 'admin')
+ js_files = %w(prototype effects lowpro dateinput pagestatus cookie popup status utility codearea tabcontrol ruledtable sitemap shortcuts toggle application)
+ js_paths = js_files.collect { |f| File.join(js_dir, f + '.js') }
+ js_cache = File.join(js_dir, '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