Sha256: 60121448e51c8a1bcb4239e1555fdb45d9b70defa3893052a8045a3902fbef99
Contents?: true
Size: 1.43 KB
Versions: 1
Compression:
Stored size: 1.43 KB
Contents
module Compressible module Configurable def self.included(base) base.extend ClassMethods end module ClassMethods attr_reader :config def configure(value = nil) raise "invalid config" unless (value.is_a?(String) || value.is_a?(Hash)) @config = value.is_a?(String) ? YAML.load_file(value) : value @config.recursively_symbolize_keys! @config = defaults.merge(@config) # normalize everything to an array [:js, :css].each do |type| @config[type] = [@config[type]] unless @config[type].is_a?(Array) end @config end def defaults { :js => [], :css => [], :stylesheet_path => defined?(Rails) ? "#{Rails.root}/public/stylesheets" : nil, :javascript_path => defined?(Rails) ? "#{Rails.root}/public/javascripts" : nil, :read_only => false } end def config @config ||= defaults end def add_to_config(type, key, value) item = find_or_create(type, key) item[:paths] = value.collect {|i| asset_name(i)} item end def find_or_create(type, key) result = config[type].detect {|i| i[:to].to_s == key.to_s} unless result result = {:to => key.to_s} config[type] << result end result end def reset @config = defaults end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
compressible-0.0.2.3 | lib/compressible/configurable.rb |