Sha256: 9356f87c1ca69b9c31ddc16a6f2ccf7a185ca9516ddc62c2440390dd1eb2a94b

Contents?: true

Size: 1.58 KB

Versions: 5

Compression:

Stored size: 1.58 KB

Contents

# encoding: utf-8

# ensure these come first to avoid tilt warnings
require 'compass'
require 'sass'
require 'coffee_script'

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

# classy assets components
require 'classy_assets/config'
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'

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 = 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

5 entries across 5 versions & 1 rubygems

Version Path
classy_assets-0.8.2 lib/classy_assets.rb
classy_assets-0.8.1 lib/classy_assets.rb
classy_assets-0.8.0 lib/classy_assets.rb
classy_assets-0.7.2 lib/classy_assets.rb
classy_assets-0.7.1 lib/classy_assets.rb