Sha256: cfcada499717c7e5f4548ada7508028e6bdb44f6759f619265697783f4f9b5a0

Contents?: true

Size: 1.8 KB

Versions: 1

Compression:

Stored size: 1.8 KB

Contents

# encoding: utf-8

module ClassyAssets
  class Configuration
    def self.configure
      yield self
    end
    
    def self.asset_digest
      @asset_digest.nil? ? false : @asset_digest
    end

    def self.asset_digest=(digest)
      @asset_digest = digest
    end

    def self.asset_host
      @asset_host
    end

    def self.asset_host=(host)
      @asset_host = host
    end

    def self.asset_paths
      @asset_paths || build_asset_paths
    end

    def self.asset_paths=(paths)
      @asset_paths = paths.to_a
    end

    def self.asset_prefix
      @asset_prefix || 'assets'
    end

    def self.asset_prefix=(prefix)
      @asset_prefix = prefix
    end

    def self.debug_mode
      @debug_mode.nil? ? (ENV['RACK_ENV'] == 'development') : @debug_mode
    end

    def self.debug_mode=(debug)
      @debug_mode = debug
    end

    def self.public_path
      @public_path || File.join(root_path, 'public')
    end
    
    def self.public_path=(path)
      @public_path = path
    end

    def self.root_path
      @root_path || '.'
    end
    
    def self.root_path=(path)
      @root_path = path
    end

    def self.sprockets
      new_sprockets_environment
    end

    private

    def self.build_asset_paths
      Dir.glob(File.join(root_path, asset_prefix, '*'))
    end

    def self.new_sprockets_environment
      @sprockets = ::Sprockets::Environment.new(root_path)
      asset_paths.each do |asset_path|
        unless @sprockets.paths.include?(asset_path)
          @sprockets.append_path asset_path
        end
      end

      @sprockets.context_class.class_eval do
        def asset_path(path, options = {})
          depend_on_asset(path)
          asset = environment.find_asset(path)
          ClassyAssets.asset_url_for(asset.logical_path)
        end
      end

      @sprockets
    end
  end
end  

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
classy_assets-0.4.0 lib/classy_assets/configuration.rb