Class: UnderOs::Page::Stylesheet
- Defined in:
- lib/under_os/page/stylesheet.rb
Instance Attribute Summary collapse
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
- #+(another_stylesheet) ⇒ Object
- #<<(another_stylesheet) ⇒ Object
- #[](rule) ⇒ Object
- #[]=(rule, values) ⇒ Object
-
#initialize(styles = {}) ⇒ Stylesheet
constructor
A new instance of Stylesheet.
- #load(filename) ⇒ Object
- #styles_for(view) ⇒ Object
Constructor Details
#initialize(styles = {}) ⇒ Stylesheet
Returns a new instance of Stylesheet.
4 5 6 7 8 9 10 |
# File 'lib/under_os/page/stylesheet.rb', line 4 def initialize(styles={}) @rules = {} styles.each do |rule, style| self[rule] = style end end |
Instance Attribute Details
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
2 3 4 |
# File 'lib/under_os/page/stylesheet.rb', line 2 def rules @rules end |
Instance Method Details
#+(another_stylesheet) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/under_os/page/stylesheet.rb', line 37 def +(another_stylesheet) self.class.new.tap do |combined_sheet| combined_sheet << self combined_sheet << another_stylesheet end end |
#<<(another_stylesheet) ⇒ Object
31 32 33 34 35 |
# File 'lib/under_os/page/stylesheet.rb', line 31 def <<(another_stylesheet) another_stylesheet.rules.each do |rule, styles| self[rule] = styles end end |
#[](rule) ⇒ Object
22 23 24 |
# File 'lib/under_os/page/stylesheet.rb', line 22 def [](rule) @rules[rule.to_s] end |
#[]=(rule, values) ⇒ Object
26 27 28 29 |
# File 'lib/under_os/page/stylesheet.rb', line 26 def []=(rule, values) @rules[rule.to_s] ||= {} @rules[rule.to_s].merge! values end |
#load(filename) ⇒ Object
44 45 46 47 48 |
# File 'lib/under_os/page/stylesheet.rb', line 44 def load(filename) UnderOs::Parser.parse(filename).each do |rule, styles| self[rule] = styles end end |
#styles_for(view) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/under_os/page/stylesheet.rb', line 12 def styles_for(view) {}.tap do |styles| weighted_styles_for(view).each do |hash| hash.each do |key, value| styles[key] = value end end end end |