Skip to content

Commit

Permalink
Fixed rake asset_hat:config error; added msg if config file is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
rondevera committed Jan 30, 2011
1 parent da78096 commit ebdbaa4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
6 changes: 2 additions & 4 deletions config/assets.yml
@@ -1,17 +1,15 @@
# This belongs in your app's `config` directory. Configure your bundles
# below; no `.css` or `.js` suffixes needed. Example:
# Configure your bundles below. No `.css` or `.js` suffixes needed; ERb is
# supported if you need it. Example:
#
# css:
# engine: cssmin
# bundles:
# application:
# - reset
# - application
# - clearfix
# admin:
# - reset
# - admin
# - clearfix
# js:
# engine: jsmin
# vendors:
Expand Down
10 changes: 7 additions & 3 deletions lib/asset_hat.rb
Expand Up @@ -37,6 +37,11 @@ class << self

# Nested-hash version of <code>config/assets.yml</code>.
def self.config
unless File.exists?(CONFIG_FILEPATH)
raise '`config/assets.yml` is missing! ' +
'Run `rake asset_hat:config` to generate it.' and return
end

if !cache? || @config.blank?
@config = YAML.load(ERB.new(File.read(CONFIG_FILEPATH)).result)
end
Expand Down Expand Up @@ -137,7 +142,7 @@ def self.min_filepath(filepath, extension)
# Returns the extension-less names of files in the given bundle:
#
# AssetHat.bundle_filenames('application', :css)
# # => ['reset', 'application', 'clearfix']
# # => ['reset', 'application']
# AssetHat.bundle_filenames('non-existent-file', :css)
# # => nil
def self.bundle_filenames(bundle, type)
Expand All @@ -154,8 +159,7 @@ def self.bundle_filenames(bundle, type)
#
# AssetHat.bundle_filenames('application', :css)
# # => ['/path/to/app/public/stylesheets/reset.css',
# '/path/to/app/public/stylesheets/application.css',
# '/path/to/app/public/stylesheets/clearfix.css']
# '/path/to/app/public/stylesheets/application.css']
# AssetHat.bundle_filenames('non-existent-file', :css)
# # => nil
def self.bundle_filepaths(bundle, type)
Expand Down
2 changes: 1 addition & 1 deletion lib/asset_hat/tasks.rb
Expand Up @@ -26,7 +26,7 @@
end

desc 'Prepare configuration file'
task :config, :needs => :environment do
task :config do
template_filepath = File.join(File.dirname(__FILE__), '..', '..',
AssetHat::RELATIVE_CONFIG_FILEPATH)
target_filepath = AssetHat::CONFIG_FILEPATH
Expand Down
3 changes: 1 addition & 2 deletions lib/asset_hat_helper.rb
Expand Up @@ -118,10 +118,9 @@ def include_assets(type, *args) #:nodoc:
# => <link href="/stylesheets/bundles/application.min.css" ... />
#
# Include multiple stylesheets separately (not as cool):
# include_css 'reset', 'application', 'clearfix'
# include_css 'reset', 'application'
# => <link href="/stylesheets/reset.min.css" ... />
# <link href="/stylesheets/application.min.css" ... />
# <link href="/stylesheets/clearfix.min.css" ... />
#
# Include a stylesheet with extra media types:
# include_css 'mobile', :media => 'handheld,screen,projection'
Expand Down
9 changes: 9 additions & 0 deletions test/asset_hat_test.rb
Expand Up @@ -16,6 +16,15 @@ class AssetHatTest < ActiveSupport::TestCase
AssetHat.bundles_dir(:js, :ssl => true)
end

should 'know whether the config file needs to be generated' do
flexmock(File).should_receive(:exists?).
with(AssetHat::CONFIG_FILEPATH).and_return(false)

assert_raise RuntimeError do
AssetHat.config
end
end

context 'with caching enabled' do
setup do
flexmock(AssetHat, :cache? => true)
Expand Down

0 comments on commit ebdbaa4

Please sign in to comment.