jammit 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jammit'
3
- s.version = '0.1.3' # Keep version in sync with jammit.rb
4
- s.date = '2009-11-17'
3
+ s.version = '0.2.0' # Keep version in sync with jammit.rb
4
+ s.date = '2009-11-18'
5
5
 
6
6
  s.homepage = "http://documentcloud.github.com/jammit/"
7
7
  s.summary = "Industrial Strength Asset Packaging for Rails"
@@ -26,22 +26,9 @@ Gem::Specification.new do |s|
26
26
  '--main' << 'README' <<
27
27
  '--all'
28
28
 
29
- s.add_dependency 'rails', ['>= 2.0.0']
30
- s.add_dependency 'yui-compressor', ['>= 0.9.1']
29
+ s.add_dependency 'rails', ['>= 2.0.0']
30
+ s.add_dependency 'yui-compressor', ['>= 0.9.1']
31
+ s.add_dependency 'closure-compiler', ['>= 0.1.0']
31
32
 
32
- s.files = %w(
33
- bin/jammit
34
- jammit.gemspec
35
- lib/jammit.rb
36
- lib/jammit/command_line.rb
37
- lib/jammit/compressor.rb
38
- lib/jammit/controller.rb
39
- lib/jammit/helper.rb
40
- lib/jammit/jst.js
41
- lib/jammit/packager.rb
42
- lib/jammit/routes.rb
43
- LICENSE
44
- Rakefile
45
- README
46
- )
33
+ s.files = Dir['lib/**/*', 'bin/*', 'jammit.gemspec', 'LICENSE', 'README']
47
34
  end
@@ -4,7 +4,7 @@ $LOAD_PATH.push File.expand_path(File.dirname(__FILE__))
4
4
  # to all of the configuration options.
5
5
  module Jammit
6
6
 
7
- VERSION = "0.1.3"
7
+ VERSION = "0.2.0"
8
8
 
9
9
  ROOT = File.expand_path(File.dirname(__FILE__) + '/..')
10
10
 
@@ -16,13 +16,16 @@ module Jammit
16
16
 
17
17
  DEFAULT_JST_COMPILER = "template"
18
18
 
19
+ DEFAULT_COMPRESSOR = :yui
20
+
19
21
  # Jammit raises a @PackageNotFound@ exception when a non-existent package is
20
22
  # requested by a browser -- rendering a 404.
21
23
  class PackageNotFound < NameError; end
22
24
 
23
25
  class << self
24
26
  attr_reader :configuration, :template_function, :embed_images, :package_path,
25
- :package_assets, :mhtml_enabled, :include_jst_script
27
+ :package_assets, :mhtml_enabled, :include_jst_script,
28
+ :javascript_compressor, :compressor_options
26
29
  end
27
30
 
28
31
  # The minimal required configuration.
@@ -32,11 +35,13 @@ module Jammit
32
35
  # Load the complete asset configuration from the specified @config_path@.
33
36
  def self.load_configuration(config_path)
34
37
  return unless config_path && File.exists?(config_path)
35
- @config_path = config_path
36
- @configuration = conf = YAML.load_file(@config_path).symbolize_keys
37
- @package_path = conf[:package_path] || DEFAULT_PACKAGE_PATH
38
- @embed_images = conf[:embed_images]
39
- @mhtml_enabled = @embed_images && @embed_images != "datauri"
38
+ @config_path = config_path
39
+ @configuration = conf = YAML.load_file(@config_path).symbolize_keys
40
+ @package_path = conf[:package_path] || DEFAULT_PACKAGE_PATH
41
+ @embed_images = conf[:embed_images]
42
+ @mhtml_enabled = @embed_images && @embed_images != "datauri"
43
+ @javascript_compressor = (conf[:javascript_compressor] || DEFAULT_COMPRESSOR).to_sym
44
+ @compressor_options = conf[:compressor_options] || {}
40
45
  set_package_assets(conf[:package_assets])
41
46
  set_template_function(conf[:template_function])
42
47
  self
@@ -101,6 +106,7 @@ require 'fileutils'
101
106
  # Gem Dependencies:
102
107
  require 'rubygems'
103
108
  require 'yui/compressor'
109
+ require 'closure-compiler'
104
110
  require 'activesupport'
105
111
 
106
112
  # Load initial configuration before the rest of Jammit.
@@ -1,7 +1,8 @@
1
1
  module Jammit
2
2
 
3
- # Uses the YUI Compressor to compress JavaScript and CSS. (Which means that
4
- # Java must be installed.) Also knows how to create a concatenated JST file.
3
+ # Uses the YUI Compressor or Closure Compiler to compress JavaScript.
4
+ # Always uses YUI to compress CSS (Which means that Java must be installed.)
5
+ # Also knows how to create a concatenated JST file.
5
6
  # If "embed_images" is turned on, creates "mhtml" and "datauri" versions of
6
7
  # all stylesheets, with all enabled images inlined into the css.
7
8
  class Compressor
@@ -29,25 +30,35 @@ module Jammit
29
30
  JST_START = "(function(){window.JST = window.JST || {};"
30
31
  JST_END = "})();"
31
32
 
33
+ DEFAULT_OPTIONS = {
34
+ :yui => {:munge => true},
35
+ :closure => {}
36
+ }
37
+
32
38
  # Creating a compressor initializes the internal YUI Compressor from
33
- # the "yui-compressor" gem.
39
+ # the "yui-compressor" gem, or the internal Closure Compiler from the
40
+ # "closure-compiler" gem.
34
41
  def initialize
35
- @yui_js = YUI::JavaScriptCompressor.new(:munge => true)
36
- @yui_css = YUI::CssCompressor.new
42
+ @css_compressor = YUI::CssCompressor.new
43
+ flavor = Jammit.javascript_compressor
44
+ js_options = DEFAULT_OPTIONS[flavor].merge(Jammit.compressor_options)
45
+ @js_compressor = flavor == :closure ?
46
+ Closure::Compiler.new(js_options) :
47
+ YUI::JavaScriptCompressor.new(js_options)
37
48
  end
38
49
 
39
50
  # Concatenate together a list of JavaScript paths, and pass them through the
40
51
  # YUI Compressor (with munging enabled).
41
52
  def compress_js(paths)
42
- @yui_js.compress(concatenate(paths))
53
+ @js_compressor.compress(concatenate(paths))
43
54
  end
44
55
 
45
56
  # Concatenate and compress a list of CSS stylesheets. When compressing a
46
57
  # :datauri or :mhtml variant, post-processes the result to embed
47
58
  # referenced images.
48
59
  def compress_css(paths, variant=nil, asset_url=nil)
49
- return @yui_css.compress(concatenate(paths)) if variant.nil?
50
- compressed_css = @yui_css.compress(concatenate_and_tag_images(paths))
60
+ return @css_compressor.compress(concatenate(paths)) if variant.nil?
61
+ compressed_css = @css_compressor.compress(concatenate_and_tag_images(paths))
51
62
  return with_data_uris(compressed_css) if variant == :datauri
52
63
  return with_mhtml(compressed_css, asset_url) if variant == :mhtml
53
64
  raise PackageNotFound, "\"#{variant}\" is not a valid stylesheet variant"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jammit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Ashkenas
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-17 00:00:00 -05:00
12
+ date: 2009-11-18 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -32,6 +32,16 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.9.1
34
34
  version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: closure-compiler
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.1.0
44
+ version:
35
45
  description: " Jammit is an industrial strength asset packaging library for Rails,\n providing both the CSS and JavaScript concatenation and compression\n that you'd expect, as well as ahead-of-time gzipping, built-in JavaScript\n template support, and optional Data-URI / MHTML image embedding.\n"
36
46
  email: jeremy@documentcloud.org
37
47
  executables:
@@ -41,9 +51,6 @@ extensions: []
41
51
  extra_rdoc_files:
42
52
  - README
43
53
  files:
44
- - bin/jammit
45
- - jammit.gemspec
46
- - lib/jammit.rb
47
54
  - lib/jammit/command_line.rb
48
55
  - lib/jammit/compressor.rb
49
56
  - lib/jammit/controller.rb
@@ -51,8 +58,10 @@ files:
51
58
  - lib/jammit/jst.js
52
59
  - lib/jammit/packager.rb
53
60
  - lib/jammit/routes.rb
61
+ - lib/jammit.rb
62
+ - bin/jammit
63
+ - jammit.gemspec
54
64
  - LICENSE
55
- - Rakefile
56
65
  - README
57
66
  has_rdoc: true
58
67
  homepage: http://documentcloud.github.com/jammit/
data/Rakefile DELETED
@@ -1,40 +0,0 @@
1
- require 'rake/testtask'
2
-
3
- desc 'Run all tests'
4
- task :test do
5
- $LOAD_PATH.unshift(File.expand_path('test'))
6
- require 'redgreen' if Gem.available?('redgreen')
7
- require 'test/unit'
8
- Dir.chdir('test')
9
- Dir['./**/test_*.rb'].each {|test| require test }
10
- end
11
-
12
- desc 'Generate YARD Documentation'
13
- task :doc do
14
- sh "mv README TEMPME"
15
- sh "rm -rf doc"
16
- sh "yardoc"
17
- sh "mv TEMPME README"
18
- end
19
-
20
- desc "Deploy the Github Page"
21
- task :deploy do
22
- sh "git co gh-pages && git merge master && git push github gh-pages && git co master"
23
- end
24
-
25
- namespace :gem do
26
-
27
- desc 'Build and install the jammit gem'
28
- task :install do
29
- sh "gem build jammit.gemspec"
30
- sh "sudo gem install #{Dir['*.gem'].join(' ')} --local --no-ri --no-rdoc"
31
- end
32
-
33
- desc 'Uninstall the jammit gem'
34
- task :uninstall do
35
- sh "sudo gem uninstall -x jammit"
36
- end
37
-
38
- end
39
-
40
- task :default => :test