jammit 0.5.3 → 0.5.4

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.5.3' # Keep version in sync with jammit.rb
4
- s.date = '2010-9-15'
3
+ s.version = '0.5.4' # Keep version in sync with jammit.rb
4
+ s.date = '2010-11-8'
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.5.3"
7
+ VERSION = "0.5.4"
8
8
 
9
9
  ROOT = File.expand_path(File.dirname(__FILE__) + '/..')
10
10
 
@@ -58,8 +58,10 @@ module Jammit
58
58
  @package_path = DEFAULT_PACKAGE_PATH
59
59
 
60
60
  # Load the complete asset configuration from the specified @config_path@.
61
- def self.load_configuration(config_path)
61
+ # If we're loading softly, don't let missing configuration error out.
62
+ def self.load_configuration(config_path, soft=false)
62
63
  exists = config_path && File.exists?(config_path)
64
+ return false if soft && !exists
63
65
  raise ConfigurationNotFound, "could not find the \"#{config_path}\" configuration file" unless exists
64
66
  conf = YAML.load(ERB.new(File.read(config_path)).result)
65
67
  @config_path = config_path
@@ -108,6 +110,18 @@ module Jammit
108
110
  "/#{package_path}/#{filename(package, extension, suffix)}#{timestamp}"
109
111
  end
110
112
 
113
+ # Convenience method for packaging up Jammit, using the default options.
114
+ def self.package!(options={})
115
+ options = {
116
+ :config_path => Jammit::DEFAULT_CONFIG_PATH,
117
+ :output_folder => nil,
118
+ :base_url => nil,
119
+ :force => false
120
+ }.merge(options)
121
+ load_configuration(options[:config_path])
122
+ packager.force = options[:force]
123
+ packager.precache_all(options[:output_folder], options[:base_url])
124
+ end
111
125
 
112
126
  private
113
127
 
@@ -119,7 +133,7 @@ module Jammit
119
133
 
120
134
  # Turn asset packaging on or off, depending on configuration and environment.
121
135
  def self.set_package_assets(value)
122
- package_env = !defined?(Rails) || !Rails.env.development?
136
+ package_env = !defined?(Rails) || (!Rails.env.development? && !Rails.env.test?)
123
137
  @package_assets = value == true || value.nil? ? package_env :
124
138
  value == 'always' ? true : false
125
139
  end
@@ -26,9 +26,7 @@ Options:
26
26
  def initialize
27
27
  parse_options
28
28
  ensure_configuration_file
29
- Jammit.load_configuration(@options[:config_path])
30
- Jammit.packager.force = @options[:force]
31
- Jammit.packager.precache_all(@options[:output_folder], @options[:base_url])
29
+ Jammit.package!(@options)
32
30
  end
33
31
 
34
32
 
@@ -97,12 +97,12 @@ module Jammit
97
97
  paths = paths.grep(Jammit.template_extension_matcher).sort
98
98
  base_path = find_base_path(paths)
99
99
  compiled = paths.map do |path|
100
- contents = File.open(path, 'r:binary') {|f| f.read }
100
+ contents = read_binary_file(path)
101
101
  contents = contents.gsub(/\n/, '').gsub("'", '\\\\\'')
102
102
  name = template_name(path, base_path)
103
103
  "#{namespace}['#{name}'] = #{Jammit.template_function}('#{contents}');"
104
104
  end
105
- compiler = Jammit.include_jst_script ? File.read(DEFAULT_JST_SCRIPT) : '';
105
+ compiler = Jammit.include_jst_script ? read_binary_file(DEFAULT_JST_SCRIPT) : '';
106
106
  setup_namespace = "#{namespace} = #{namespace} || {};"
107
107
  [JST_START, setup_namespace, compiler, compiled, JST_END].flatten.join("\n")
108
108
  end
@@ -137,7 +137,7 @@ module Jammit
137
137
  # at it.
138
138
  def concatenate_and_tag_assets(paths, variant=nil)
139
139
  stylesheets = [paths].flatten.map do |css_path|
140
- contents = File.open(css_path, 'r:binary') {|f| f.read }
140
+ contents = read_binary_file(css_path)
141
141
  contents.gsub(EMBED_DETECTOR) do |url|
142
142
  ipath, cpath = Pathname.new($1), Pathname.new(File.expand_path(css_path))
143
143
  is_url = URI.parse($1).absolute?
@@ -228,7 +228,7 @@ module Jammit
228
228
  # Return the Base64-encoded contents of an asset on a single line.
229
229
  def encoded_contents(asset_path)
230
230
  return @asset_contents[asset_path] if @asset_contents[asset_path]
231
- data = File.open(asset_path, 'rb') {|f| f.read }
231
+ data = read_binary_file(asset_path)
232
232
  @asset_contents[asset_path] = Base64.encode64(data).gsub(/\n/, '')
233
233
  end
234
234
 
@@ -239,9 +239,13 @@ module Jammit
239
239
 
240
240
  # Concatenate together a list of asset files.
241
241
  def concatenate(paths)
242
- [paths].flatten.map {|p| File.read(p) }.join("\n")
242
+ [paths].flatten.map {|p| read_binary_file(p) }.join("\n")
243
243
  end
244
244
 
245
+ # `File.read`, but in "binary" mode.
246
+ def read_binary_file(path)
247
+ File.open(path, 'r:binary') {|f| f.read }
248
+ end
245
249
  end
246
250
 
247
251
  end
@@ -53,7 +53,7 @@ module Jammit
53
53
  def generate_stylesheets
54
54
  return @contents = Jammit.packager.pack_stylesheets(@package, @variant) unless @variant == :mhtml
55
55
  @mtime = Time.now
56
- request_url = prefix_url(request.request_uri)
56
+ request_url = prefix_url(request.fullpath)
57
57
  cached_url = prefix_url(Jammit.asset_url(@package, @extension, @variant, @mtime))
58
58
  css = Jammit.packager.pack_stylesheets(@package, @variant, request_url)
59
59
  @contents = css.gsub(request_url, cached_url) if perform_caching
@@ -87,7 +87,7 @@ end
87
87
  # Make the Jammit::Controller available to Rails as a top-level controller.
88
88
  ::JammitController = Jammit::Controller
89
89
 
90
- if defined?(Rails) && Rails.env.development?
90
+ if defined?(Rails) && (Rails.env.development? || Rails.env.test?)
91
91
  ActionController::Base.class_eval do
92
92
  append_before_filter { Jammit.reload! }
93
93
  end
@@ -12,7 +12,7 @@ require 'yui/compressor'
12
12
  require 'closure-compiler'
13
13
 
14
14
  # Load initial configuration before the rest of Jammit.
15
- Jammit.load_configuration(Jammit::DEFAULT_CONFIG_PATH) if defined?(Rails)
15
+ Jammit.load_configuration(Jammit::DEFAULT_CONFIG_PATH, true) if defined?(Rails)
16
16
 
17
17
  # Jammit Core:
18
18
  require 'jammit/compressor'
@@ -2,6 +2,9 @@ if defined?(Rails::Application)
2
2
  # Rails3 routes
3
3
  Rails.application.routes.draw do
4
4
  match "/#{Jammit.package_path}/:package.:extension",
5
- :to => 'jammit#package', :as => :jammit
5
+ :to => 'jammit#package', :as => :jammit, :constraints => {
6
+ # A hack to allow extension to include "."
7
+ :extension => /.+/
8
+ }
6
9
  end
7
10
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jammit
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 3
10
- version: 0.5.3
9
+ - 4
10
+ version: 0.5.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeremy Ashkenas
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-15 00:00:00 -04:00
18
+ date: 2010-11-08 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency