Permalink
Browse files

Allow for custom assets in assets.yml, make sure they appear in the p…

…ackger class
  • Loading branch information...
1 parent 2aabccd commit 011618eca7bc12a3484e4178d1aab9b4a8eea241 @dinedal committed Apr 20, 2012
Showing with 18 additions and 2 deletions.
  1. +7 −0 lib/jammit.rb
  2. +11 −2 lib/jammit/packager.rb
View
@@ -145,6 +145,13 @@ def self.package!(options={})
packager.precache_all(options[:output_folder], options[:base_url])
end
+ def self.custom_assets
+ @configuration.select { |key, val|
+ lambda{ |val| val.respond_to?(:keys) rescue false}.call(val) &&
+ ![:javascripts, :stylesheets].include?(key)
+ }
+ end
+
private
# Allows command-line definition of `PUBLIC_ROOT`, for those using Jammit
@@ -19,11 +19,11 @@ def initialize
@config = {
:css => (Jammit.configuration[:stylesheets] || {}),
:js => (Jammit.configuration[:javascripts] || {})
- }
+ }.merge!(Jammit.custom_assets)
@packages = {
:css => create_packages(@config[:css]),
:js => create_packages(@config[:js])
- }
+ }.merge!(create_custom_packages(Jammit.custom_assets))
end
# Ask the packager to precache all defined assets, along with their gzip'd
@@ -46,6 +46,9 @@ def precache_all(output_dir=nil, base_url=nil)
end
end
end
+ @packages.keys.keep_if{|extension| ![:js, :css].include?(extension)}.each do |extension|
+ cacheable(extension, output_dir).each {|p| cache(p, extension.to_s, self.send(:"pack_#{extension}", p), output_dir)}
+ end
end
# Caches a single prebuilt asset package and gzips it at the highest
@@ -169,6 +172,12 @@ def create_packages(config)
packages
end
+ def create_custom_packages(custom_assets)
+ results = {}
+ custom_assets.each { |key, val| results[key] = create_packages(val)}
+ results
+ end
+
# Raise a PackageNotFound exception for missing packages...
def not_found(package, extension)
raise PackageNotFound, "assets.yml does not contain a \"#{package}\" #{extension.to_s.upcase} package"

0 comments on commit 011618e

Please sign in to comment.