Skip to content

Commit

Permalink
Added minification
Browse files Browse the repository at this point in the history
  • Loading branch information
jnicklas committed Jan 3, 2010
1 parent aece73e commit 8c38d00
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions lib/bistro_car.rb
Original file line number Diff line number Diff line change
@@ -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?
6 changes: 5 additions & 1 deletion lib/bistro_car/bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8c38d00

Please sign in to comment.