Class: UnderOs::Page::Stylesheet

Inherits:
Object
  • Object
show all
Defined in:
lib/under_os/page/stylesheet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#rulesObject (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