Sha256: 516940aa01e8606b8a094a1faf53322855669d0b637aec066bbd2a9f662076c3

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

# encoding: utf-8

require 'compass'
require 'sass'
require 'coffee_script'
require 'sprockets'
require 'sprockets-sass'
require 'sinatra/base'
require 'classy_assets/configuration'
require 'classy_assets/version'

module ClassyAssets
  def self.asset_url_for(asset)
    asset = asset.instance_of?(::Sprockets::BundledAsset) ? asset : Configuration.sprockets[asset].logical_path
    asset = build_digest_filename(asset) if Configuration.asset_digest
    debug = (Configuration.debug_mode) ? '?body=1' : ''
    "#{Configuration.asset_host}/#{Configuration.asset_prefix}/#{asset}#{debug}"
  end

  def self.build_digest_filename(asset)
    filename = asset.split(".")
    ext = filename.pop
    "#{filename.join('.')}-#{Configuration.sprockets.digest}.#{ext}"
  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)
      yield(asset_url)
    end.join('')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
classy_assets-0.4.0 lib/classy_assets.rb