lib/classy_assets.rb in classy_assets-0.5.0 vs lib/classy_assets.rb in classy_assets-0.6.0

- old
+ new

@@ -10,37 +10,54 @@ require 'escape_utils' require 'sinatra/base' require 'sprockets' # classy assets components +require 'classy_assets/config' require 'classy_assets/configuration' +require 'classy_assets/errors/nil_asset_root' require 'classy_assets/sass/script/functions' +require 'classy_assets/sprockets' require 'classy_assets/sprockets/sass_importer' require 'classy_assets/version' -# Utility methods module ClassyAssets + # singleton sprockets environment + def self.sprockets + ClassyAssets::Sprockets.instance.environment + end + + # singleton configuration + def self.config(&block) + yield ClassyAssets::Config.instance if block_given? + ClassyAssets::Config.instance + end + + # utility methods + def self.asset_url_for(asset) - asset = Configuration.sprockets[asset].send(determine_path_type) - debug = (Configuration.debug_mode) ? '?body=1' : '' - "#{Configuration.asset_host}/#{Configuration.asset_prefix}/#{asset}#{debug}" + asset = sprockets[asset].send(determine_path_type) + debug = (config.asset_debug) ? '?body=1' : '' + "#{config.asset_host}/#{config.asset_prefix}/#{asset}#{debug}" end def self.asset_data_uri_for(asset) - asset = Configuration.sprockets[asset] + asset = sprockets[asset] base64 = Base64.encode64(asset.to_s).gsub(/\s+/, "") "data:#{asset.content_type};base64,#{EscapeUtils.escape_url(base64)}" end def self.asset_tag_from(sources, ext) sources = [sources] unless sources.is_a? Array sources.map do |source| source = "#{source}.#{ext}" unless source =~ /\.#{ext}$/ - asset_url = (source =~ /\/|http/) ? source : ::ClassyAssets.asset_url_for(source) + asset_url = (source =~ /\/|http/) ? source : asset_url_for(source) yield(asset_url) end.join('') end + private + def self.determine_path_type - (Configuration.asset_digest) ? :digest_path : :logical_path + (config.asset_digest) ? :digest_path : :logical_path end end