Permalink
Browse files

Added a rake task to compile js for non Asset Pipeline users

  • Loading branch information...
1 parent 1538d08 commit 916ecdd04e3cabbe266eb04d78cf96fe40fa561d @gregbell gregbell committed May 3, 2012
View
@@ -26,7 +26,7 @@ group :development, :test do
gem 'haml', '~> 3.1.1', :require => false
gem 'yard'
gem 'rdiscount' # For yard
- gem "guard-sprockets"
+ gem "sprockets"
gem 'rails-i18n' # Gives us default i18n for many languages
end
@@ -0,0 +1,4 @@
+//= require_tree ./lib/
+//= require_tree ./components/
+//= require_tree ./pages/
+//= require_directory ./
@@ -2,7 +2,4 @@
//= require jquery-ui
//= require jquery_ujs
-//= require_tree ./lib/
-//= require_tree ./components/
-//= require_tree ./pages/
-//= require_directory ./
+//= require active_admin/application
@@ -20,7 +20,7 @@ def install_assets
template '3.1/active_admin.js', 'app/assets/javascripts/active_admin.js'
template '3.1/active_admin.css.scss', 'app/assets/stylesheets/active_admin.css.scss'
else
- template '../../../../../app/assets/javascripts/active_admin/application.js', 'public/javascripts/active_admin.js'
+ template '3.0/active_admin.js', 'public/javascripts/active_admin.js'
directory '../../../../../app/assets/images/active_admin', 'public/images/active_admin'
generate "jquery:install --ui" if options.jquery?
install_bourbon if options.bourbon?

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -0,0 +1,32 @@
+namespace :js do
+
+ desc "Compile the JS for Rails apps without Asset Pipeline"
+ task :compile do
+ require 'sprockets'
+ require 'uglifier'
+ require 'fileutils'
+
+ root_dir = File.expand_path(File.join("..", ".."), __FILE__)
+ js_dir = File.join(root_dir, "app", "assets", "javascripts", "active_admin")
+ generated_file = File.join(root_dir, 'lib', 'generators', 'active_admin', 'assets', 'templates', '3.0', 'active_admin.js')
+
+ # The base.js file requires jquery. We don't need jquery to
+ # compile the assets, however Sprockets will try to look it up
+ # and raise an exception. Insteaad, we move the file out of the directory
+ # then put it back after we compile.
+ base_js = File.join(js_dir, "base.js")
+ tmp_base_js = File.join(root_dir, "base.js")
+ FileUtils.mv base_js, tmp_base_js
+
+ env = Sprockets::Environment.new
+ env.js_compressor = ::Uglifier.new
+ env.append_path js_dir
+
+ File.open generated_file, "w+" do |f|
+ f << env["application"]
+ end
+
+ FileUtils.mv tmp_base_js, base_js
+ end
+
+end

0 comments on commit 916ecdd

Please sign in to comment.