jammit 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/jammit.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jammit'
3
- s.version = '0.2.3' # Keep version in sync with jammit.rb
3
+ s.version = '0.2.4' # Keep version in sync with jammit.rb
4
4
  s.date = '2009-11-18'
5
5
 
6
6
  s.homepage = "http://documentcloud.github.com/jammit/"
data/lib/jammit.rb CHANGED
@@ -4,11 +4,13 @@ $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.2.3"
7
+ VERSION = "0.2.4"
8
8
 
9
9
  ROOT = File.expand_path(File.dirname(__FILE__) + '/..')
10
10
 
11
- DEFAULT_CONFIG_PATH = "config/assets.yml"
11
+ ASSET_ROOT = defined?(RAILS_ROOT) ? RAILS_ROOT : "."
12
+
13
+ DEFAULT_CONFIG_PATH = "#{ASSET_ROOT}/config/assets.yml"
12
14
 
13
15
  DEFAULT_PACKAGE_PATH = "assets"
14
16
 
@@ -24,6 +26,10 @@ module Jammit
24
26
  # requested by a browser -- rendering a 404.
25
27
  class PackageNotFound < NameError; end
26
28
 
29
+ # Jammit raises a ConfigurationNotFound exception when you try to load the
30
+ # configuration of an assets.yml file that doesn't exist.
31
+ class ConfigurationNotFound < NameError; end
32
+
27
33
  class << self
28
34
  attr_reader :configuration, :template_function, :embed_images, :package_path,
29
35
  :package_assets, :mhtml_enabled, :include_jst_script,
@@ -36,9 +42,10 @@ module Jammit
36
42
 
37
43
  # Load the complete asset configuration from the specified @config_path@.
38
44
  def self.load_configuration(config_path)
39
- return unless config_path && File.exists?(config_path)
45
+ conf = config_path && File.exists?(config_path) && YAML.load_file(config_path)
46
+ raise ConfigurationNotFound, "could not find the \"#{config_path}\" configuration file" unless conf
40
47
  @config_path = config_path
41
- @configuration = conf = YAML.load_file(@config_path).symbolize_keys
48
+ @configuration = conf = conf.symbolize_keys
42
49
  @package_path = conf[:package_path] || DEFAULT_PACKAGE_PATH
43
50
  @embed_images = conf[:embed_images]
44
51
  @mhtml_enabled = @embed_images && @embed_images != "datauri"
@@ -124,7 +124,7 @@ module Jammit
124
124
  # not be relative, given the path of the stylesheet that contains it.
125
125
  def public_path(image_path, css_path)
126
126
  image_path, css_path = Pathname.new(image_path), Pathname.new(css_path)
127
- (image_path.absolute? ? Pathname.new("public#{image_path}") : css_path.dirname + image_path).cleanpath
127
+ (image_path.absolute? ? Pathname.new("#{ASSET_ROOT}/public#{image_path}") : css_path.dirname + image_path).cleanpath
128
128
  end
129
129
 
130
130
  # An image is valid if it exists, and is less than 32K.
@@ -9,7 +9,7 @@ module Jammit
9
9
 
10
10
  SUFFIX_STRIPPER = /-(datauri|mhtml)\Z/
11
11
 
12
- NOT_FOUND_PATH = "#{RAILS_ROOT}/public/404.html"
12
+ NOT_FOUND_PATH = "#{ASSET_ROOT}/public/404.html"
13
13
 
14
14
  after_filter :cache_package if perform_caching
15
15
 
@@ -30,7 +30,7 @@ module Jammit
30
30
  # versions. In order to prebuild the MHTML stylesheets, we need to know the
31
31
  # base_url, because IE only supports MHTML with absolute references.
32
32
  def precache_all(output_dir=nil, base_url=nil)
33
- output_dir ||= "public/#{Jammit.package_path}"
33
+ output_dir ||= "#{ASSET_ROOT}/public/#{Jammit.package_path}"
34
34
  @config[:js].keys.each {|p| cache(p, 'js', pack_javascripts(p), output_dir) }
35
35
  @config[:jst].keys.each {|p| cache(p, 'jst', pack_templates(p), output_dir) }
36
36
  @config[:css].keys.each do |p|
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.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Ashkenas