Module: ClassyAssets
- Defined in:
- lib/classy_assets.rb,
lib/classy_assets/cli.rb,
lib/classy_assets/tasks.rb,
lib/classy_assets/config.rb,
lib/classy_assets/version.rb,
lib/classy_assets/sprockets.rb,
lib/classy_assets/errors/nil_asset_root.rb
Defined Under Namespace
Modules: Errors Classes: CLI, Config, Sprockets, Tasks
Constant Summary collapse
- VERSION =
"0.14.5"
Class Method Summary collapse
- .asset_data_uri_for(asset) ⇒ Object
-
.asset_manifest ⇒ Object
utility methods.
- .asset_tag_from(sources, ext) ⇒ Object
- .asset_url_for(asset) ⇒ Object
-
.config {|ClassyAssets::Config.instance| ... } ⇒ Object
singleton configuration.
-
.sprockets ⇒ Object
sprockets environment.
Class Method Details
.asset_data_uri_for(asset) ⇒ Object
51 52 53 54 55 |
# File 'lib/classy_assets.rb', line 51 def self.asset_data_uri_for(asset) asset = sprockets[asset] base64 = Base64.encode64(asset.to_s).gsub(/\s+/, "") "data:#{asset.content_type};base64,#{EscapeUtils.escape_url(base64)}" end |
.asset_manifest ⇒ Object
utility methods
39 40 41 |
# File 'lib/classy_assets.rb', line 39 def self.asset_manifest Oj.load(File.open(config.asset_manifest_path, 'r')) end |
.asset_tag_from(sources, ext) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/classy_assets.rb', line 57 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 : asset_url_for(source) yield(asset_url) end.join('') end |
.asset_url_for(asset) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/classy_assets.rb', line 43 def self.asset_url_for(asset) if config.asset_digest asset = (manifest_exists?) ? asset_manifest['assets'][asset] : sprockets[asset].digest_path end debug = (config.asset_debug) ? '?body=1' : '' "#{config.asset_host}/#{config.asset_prefix}/#{asset}#{debug}" end |
.config {|ClassyAssets::Config.instance| ... } ⇒ Object
singleton configuration
32 33 34 35 |
# File 'lib/classy_assets.rb', line 32 def self.config(&block) yield ClassyAssets::Config.instance if block_given? ClassyAssets::Config.instance end |
.sprockets ⇒ Object
sprockets environment
23 24 25 26 27 28 29 |
# File 'lib/classy_assets.rb', line 23 def self.sprockets if ClassyAssets.config.asset_cache ClassyAssets::Sprockets.new.environment.index else ClassyAssets::Sprockets.new.environment end end |