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.11.1"

Class Method Summary collapse

Class Method Details

.asset_data_uri_for(asset) ⇒ Object



40
41
42
43
44
# File 'lib/classy_assets.rb', line 40

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_tag_from(sources, ext) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/classy_assets.rb', line 46

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

utility methods



34
35
36
37
38
# File 'lib/classy_assets.rb', line 34

def self.asset_url_for(asset)
  asset = sprockets[asset].send(determine_path_type)
  debug = (config.asset_debug) ? '?body=1' : ''
  "#{config.asset_host}/#{config.asset_prefix}/#{asset}#{debug}"
end

.config {|ClassyAssets::Config.instance| ... } ⇒ Object

singleton configuration

Yields:



27
28
29
30
# File 'lib/classy_assets.rb', line 27

def self.config(&block)
  yield ClassyAssets::Config.instance if block_given?
  ClassyAssets::Config.instance
end

.sprocketsObject

sprockets environment



18
19
20
21
22
23
24
# File 'lib/classy_assets.rb', line 18

def self.sprockets
  if ClassyAssets.config.asset_cache
    ClassyAssets::Sprockets.new.environment.index
  else
    ClassyAssets::Sprockets.new.environment
  end
end