Class: Stylist::Configuration
- Inherits:
-
Object
- Object
- Stylist::Configuration
- Defined in:
- lib/stylist/configuration.rb
Instance Attribute Summary collapse
-
#default_media ⇒ Object
Returns the value of attribute default_media.
-
#processors ⇒ Object
readonly
Returns the value of attribute processors.
-
#public_stylesheets_path ⇒ Object
Returns the value of attribute public_stylesheets_path.
Instance Method Summary collapse
- #add_option(key, default_value = nil) ⇒ Object
- #add_option_group(group_name, options = {}) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #metaclass ⇒ Object
- #process_with(*processors) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
15 16 17 18 19 |
# File 'lib/stylist/configuration.rb', line 15 def initialize @default_media = :all @processors = [] @public_stylesheets_path = "#{defined?(Rails.public_path) ? Rails.public_path : 'public'}/stylesheets" end |
Instance Attribute Details
#default_media ⇒ Object
Returns the value of attribute default_media.
13 14 15 |
# File 'lib/stylist/configuration.rb', line 13 def default_media @default_media end |
#processors ⇒ Object (readonly)
Returns the value of attribute processors.
12 13 14 |
# File 'lib/stylist/configuration.rb', line 12 def processors @processors end |
#public_stylesheets_path ⇒ Object
Returns the value of attribute public_stylesheets_path.
13 14 15 |
# File 'lib/stylist/configuration.rb', line 13 def public_stylesheets_path @public_stylesheets_path end |
Instance Method Details
#add_option(key, default_value = nil) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/stylist/configuration.rb', line 34 def add_option(key, default_value=nil) .class_eval <<-EOC attr_accessor :#{key} EOC instance_variable_set "@#{key}", default_value end |
#add_option_group(group_name, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/stylist/configuration.rb', line 25 def add_option_group(group_name, ={}) group = instance_variable_set "@#{group_name}", Configuration.new .class_eval <<-EOC attr_reader :#{group_name} EOC .each_pair { |key, value| group.add_option(key, value) } end |
#metaclass ⇒ Object
21 22 23 |
# File 'lib/stylist/configuration.rb', line 21 def class << self; self; end end |
#process_with(*processors) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/stylist/configuration.rb', line 42 def process_with(*processors) @processors = processors.collect do |processor| if processor.is_a? Class processor_class = processor else possible_processor_path = File.join(File.dirname(__FILE__), "processors/#{processor}_processor.rb") require possible_processor_path if File.exists?(possible_processor_path) class_name = processor.to_s.strip.camelize.sub(/(Processor)?$/, 'Processor') processor_class = class_name.constantize rescue "::Stylist::Processors::#{class_name}".constantize end end.compact @processors.each { |processor| processor.configure if processor.respond_to?(:configure) } end |