jammit 0.3.0 → 0.3.1

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.3.0' # Keep version in sync with jammit.rb
4
- s.date = '2009-11-24'
3
+ s.version = '0.3.1' # Keep version in sync with jammit.rb
4
+ s.date = '2009-11-29'
5
5
 
6
6
  s.homepage = "http://documentcloud.github.com/jammit/"
7
7
  s.summary = "Industrial Strength Asset Packaging for Rails"
@@ -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.3.0"
7
+ VERSION = "0.3.1"
8
8
 
9
9
  ROOT = File.expand_path(File.dirname(__FILE__) + '/..')
10
10
 
@@ -36,6 +36,10 @@ module Jammit
36
36
  # not a recent enough version to run the JavaScript compressor.
37
37
  class JavaNotFound < StandardError; end
38
38
 
39
+ # Jammit raises an OutputNotWritable exception if the output directory for
40
+ # cached packages is locked.
41
+ class OutputNotWritable < StandardError; end
42
+
39
43
  class << self
40
44
  attr_reader :configuration, :template_function, :embed_images, :package_path,
41
45
  :package_assets, :mhtml_enabled, :include_jst_script,
@@ -99,7 +103,7 @@ module Jammit
99
103
 
100
104
  # Turn asset packaging on or off, depending on configuration and environment.
101
105
  def self.set_package_assets(value)
102
- package_env = !defined?(RAILS_ENV) || RAILS_ENV != 'development'
106
+ package_env = !defined?(Rails) || !Rails.env.development?
103
107
  @package_assets = value == true || value.nil? ? package_env :
104
108
  value == 'always' ? true : false
105
109
  end
@@ -122,28 +126,4 @@ module Jammit
122
126
 
123
127
  end
124
128
 
125
- # Standard Library Dependencies:
126
- require 'uri'
127
- require 'zlib'
128
- require 'base64'
129
- require 'pathname'
130
- require 'fileutils'
131
-
132
- # Gem Dependencies:
133
- require 'rubygems'
134
- require 'yui/compressor'
135
- require 'closure-compiler'
136
- require 'activesupport'
137
-
138
- # Load initial configuration before the rest of Jammit.
139
- Jammit.load_configuration(Jammit::DEFAULT_CONFIG_PATH) if defined?(RAILS_ENV)
140
-
141
- # Jammit Core:
142
- require 'jammit/compressor'
143
- require 'jammit/packager'
144
-
145
- # Jammit Rails Integration:
146
- if defined?(RAILS_ENV)
147
- require 'jammit/controller' # Rails will auto-load 'jammit/helper' for us.
148
- require 'jammit/routes'
149
- end
129
+ require 'jammit/dependencies'
@@ -11,17 +11,16 @@ module Jammit
11
11
 
12
12
  NOT_FOUND_PATH = "#{PUBLIC_ROOT}/404.html"
13
13
 
14
- after_filter :cache_package if perform_caching
15
-
16
14
  # The "package" action receives all requests for asset packages that haven't
17
15
  # yet been cached. The package will be built, cached, and gzipped.
18
16
  def package
19
17
  parse_request
20
18
  case @extension
21
- when :js then render :js => Jammit.packager.pack_javascripts(@package)
19
+ when :js then render :js => (@contents = Jammit.packager.pack_javascripts(@package))
22
20
  when :css then render :text => generate_stylesheets, :content_type => 'text/css'
23
- when :jst then render :js => Jammit.packager.pack_templates(@package)
21
+ when :jst then render :js => (@contents = Jammit.packager.pack_templates(@package))
24
22
  end
23
+ cache_package if perform_caching
25
24
  rescue Jammit::PackageNotFound
26
25
  package_not_found
27
26
  end
@@ -34,7 +33,7 @@ module Jammit
34
33
  # the timestamp that ends up in the MHTML is also on the cached file.
35
34
  def cache_package
36
35
  dir = File.join(page_cache_directory, Jammit.package_path)
37
- Jammit.packager.cache(@package, @extension, @contents || response.body, dir, @variant, @mtime)
36
+ Jammit.packager.cache(@package, @extension, @contents, dir, @variant, @mtime)
38
37
  end
39
38
 
40
39
  # Generate the complete, timestamped, MHTML url -- if we're rendering a
@@ -49,7 +48,7 @@ module Jammit
49
48
  # request URL to the client, and cache a version with the timestamped cache
50
49
  # URL swapped in.
51
50
  def generate_stylesheets
52
- return Jammit.packager.pack_stylesheets(@package, @variant) unless @variant == :mhtml
51
+ return @contents = Jammit.packager.pack_stylesheets(@package, @variant) unless @variant == :mhtml
53
52
  @mtime = Time.now
54
53
  request_url = prefix_url(request.request_uri)
55
54
  cached_url = prefix_url(Jammit.asset_url(@package, @extension, @variant, @mtime))
@@ -85,7 +84,7 @@ end
85
84
  # Make the Jammit::Controller available to Rails as a top-level controller.
86
85
  ::JammitController = Jammit::Controller
87
86
 
88
- if RAILS_ENV == 'development'
87
+ if Rails.env.development?
89
88
  ActionController::Base.class_eval do
90
89
  append_before_filter { Jammit.reload! }
91
90
  end
@@ -0,0 +1,25 @@
1
+ # Standard Library Dependencies:
2
+ require 'uri'
3
+ require 'zlib'
4
+ require 'base64'
5
+ require 'pathname'
6
+ require 'fileutils'
7
+
8
+ # Gem Dependencies:
9
+ require 'rubygems'
10
+ require 'yui/compressor'
11
+ require 'closure-compiler'
12
+ require 'active_support'
13
+
14
+ # Load initial configuration before the rest of Jammit.
15
+ Jammit.load_configuration(Jammit::DEFAULT_CONFIG_PATH) if defined?(Rails)
16
+
17
+ # Jammit Core:
18
+ require 'jammit/compressor'
19
+ require 'jammit/packager'
20
+
21
+ # Jammit Rails Integration:
22
+ if defined?(Rails)
23
+ require 'jammit/controller' # Rails will auto-load 'jammit/helper' for us.
24
+ require 'jammit/routes'
25
+ end
@@ -58,6 +58,7 @@ module Jammit
58
58
  # variants is identical, for web server caching modules, as well as MHTML.
59
59
  def cache(package, extension, contents, output_dir, suffix=nil, mtime=Time.now)
60
60
  FileUtils.mkdir_p(output_dir) unless File.exists?(output_dir)
61
+ raise OutputNotWritable, "Jammit doesn't have permission to write to \"#{output_dir}\"" unless File.writable?(output_dir)
61
62
  filename = File.join(output_dir, Jammit.filename(package, extension, suffix))
62
63
  zip_name = "#{filename}.gz"
63
64
  File.open(filename, 'wb+') {|f| f.write(contents) }
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.3.0
4
+ version: 0.3.1
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-24 00:00:00 -05:00
12
+ date: 2009-11-29 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -54,6 +54,7 @@ files:
54
54
  - lib/jammit/command_line.rb
55
55
  - lib/jammit/compressor.rb
56
56
  - lib/jammit/controller.rb
57
+ - lib/jammit/dependencies.rb
57
58
  - lib/jammit/helper.rb
58
59
  - lib/jammit/jst.js
59
60
  - lib/jammit/packager.rb