Class: CSSNative::Rule::Stylesheet
- Inherits:
-
Object
- Object
- CSSNative::Rule::Stylesheet
show all
- Defined in:
- lib/css-native/rule/stylesheet.rb
Instance Method Summary
collapse
Constructor Details
#initialize(controller) ⇒ Stylesheet
Returns a new instance of Stylesheet.
5
6
7
8
|
# File 'lib/css-native/rule/stylesheet.rb', line 5
def initialize(controller)
@properties = {}
@controller = controller
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/css-native/rule/stylesheet.rb', line 26
def method_missing(m, *args, &block)
if m.to_s.end_with? "="
props = args[0]
props = props.join(" ") if props.kind_of?(Array)
@properties[m.to_s.gsub("_", "-")[...-1]] = props.to_s
else
super(m, *args, &block)
end
end
|
Instance Method Details
#subrule ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/css-native/rule/stylesheet.rb', line 10
def subrule
parent = @controller.instance_variable_get(:@parent)
selector = @controller.instance_variable_get(:@selector)
previous = @controller.instance_variable_get(:@previous)
Rule.new(parent, selector, previous: previous)
end
|
#to_s ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/css-native/rule/stylesheet.rb', line 18
def to_s
"{\n" +
@properties.map do |k, v|
" #{k}: #{v};"
end.join("\n") +
"\n}"
end
|