Permalink
Browse files

Added minification

  • Loading branch information...
1 parent aece73e commit 8c38d00039f48ce78fa689459dcb85111c0f9636 @jnicklas committed Jan 3, 2010
Showing with 18 additions and 3 deletions.
  1. +8 −0 README.rdoc
  2. +1 −0 Rakefile
  3. +4 −2 lib/bistro_car.rb
  4. +5 −1 lib/bistro_car/bundle.rb
View
@@ -42,6 +42,14 @@ Now you can require both bundles like this:
<%= coffee_script_bundle :admin %>
+== Minification:
+
+You can make BistroCar minify your JavaScript bundles using JSMin by setting:
+
+ BistroCar.minify = true
+
+This is done automatically for the production environment.
+
== License:
(The MIT License)
View
@@ -12,5 +12,6 @@ Hoe.spec 'bistro_car' do
self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
self.rubyforge_name = self.name # TODO this is default value
self.extra_deps = [['coffee-script','>= 0.1.6']]
+ self.extra_deps = [['jsmin','>= 1.0.1']]
self.version = BistroCar::VERSION
end
View
@@ -1,13 +1,15 @@
require 'coffee-script'
+require 'jsmin'
require 'bistro_car/bundle'
require 'bistro_car/helpers'
module BistroCar
VERSION = "0.1"
class << self
- attr_accessor :mode
+ attr_accessor :mode, :minify
end
end
-BistroCar.mode = :bundled
+BistroCar.mode = :bundled
+BistroCar.minify = true if defined?(Rails) and Rails.env.production?
View
@@ -15,11 +15,15 @@ def render(mode)
end
def to_javascript
- file_paths.map { |path| CoffeeScript.compile(File.read(path)) }.join
+ minify(file_paths.map { |path| CoffeeScript.compile(File.read(path)) }.join)
end
private
+ def minify(javascript)
+ if BistroCar.minify then JSMin.minify(javascript) else javascript end
+ end
+
def javascript_url
"/javascripts/bundle/#{name}.js"
end

0 comments on commit 8c38d00

Please sign in to comment.