Sha256: c871e8423b19ff087eeaed1d1c28e1b215fd3d86e12f4429909dfb9bd32fa239

Contents?: true

Size: 1.52 KB

Versions: 8

Compression:

Stored size: 1.52 KB

Contents

# encoding: utf-8

# stdlib
require 'base64'
require 'escape_utils'
require 'sinatra/base'
require 'sprockets'

# classy assets components
require 'classy_assets/config'
require 'classy_assets/sprockets'
require 'classy_assets/sass/script/functions'
require 'classy_assets/sprockets/sass_importer'
require 'classy_assets/version'

module ClassyAssets
  # sprockets environment
  def self.sprockets
    if ClassyAssets.config.asset_cache
      ClassyAssets::Sprockets.new.environment.index
    else
      ClassyAssets::Sprockets.new.environment
    end
  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 = 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 = 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 : asset_url_for(source)
      yield(asset_url)
    end.join('')
  end

  private

  def self.determine_path_type
    (config.asset_digest) ? :digest_path : :logical_path
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
classy_assets-0.11.1 lib/classy_assets.rb
classy_assets-0.11.0 lib/classy_assets.rb
classy_assets-0.10.0 lib/classy_assets.rb
classy_assets-0.9.4 lib/classy_assets.rb
classy_assets-0.9.3 lib/classy_assets.rb
classy_assets-0.9.2 lib/classy_assets.rb
classy_assets-0.9.1 lib/classy_assets.rb
classy_assets-0.9.0 lib/classy_assets.rb