Class: CSSNative
- Inherits:
-
Object
show all
- Defined in:
- lib/css-native.rb,
lib/css-native/rule.rb,
lib/css-native/errors.rb,
lib/css-native/rule/constants.rb,
lib/css-native/rule/stylesheet.rb
Defined Under Namespace
Classes: AttributeComparisonError, AttributeError, CSSError, JoinError, PseudoClassError, PseudoElementError, Rule, RuleError, SelectorError
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#attribute(name, operation = :none, value = nil, case_sensitive: true, &block) ⇒ Object
-
#class(name = nil, &block) ⇒ Object
-
#element(name, &block) ⇒ Object
-
#id(name, &block) ⇒ Object
-
#initialize ⇒ CSSNative
constructor
A new instance of CSSNative.
-
#klass ⇒ Object
-
#select(name, *args, type: :element, &block) ⇒ Object
-
#to_s ⇒ Object
Constructor Details
Returns a new instance of CSSNative.
13
14
15
|
# File 'lib/css-native.rb', line 13
def initialize
@rules = []
end
|
Instance Attribute Details
#rules ⇒ Object
Returns the value of attribute rules.
12
13
14
|
# File 'lib/css-native.rb', line 12
def rules
@rules
end
|
Class Method Details
.stylesheet(&block) ⇒ Object
6
7
8
9
10
|
# File 'lib/css-native.rb', line 6
def self.stylesheet(&block)
sheet = new
sheet.instance_eval(&block)
sheet
end
|
Instance Method Details
#attribute(name, operation = :none, value = nil, case_sensitive: true, &block) ⇒ Object
34
35
36
|
# File 'lib/css-native.rb', line 34
def attribute(name, operation = :none, value = nil, case_sensitive: true, &block)
Rule.new(self).with_attribute(name, operation, value, case_sensitive: case_sensitive, &block)
end
|
#class(name = nil, &block) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/css-native.rb', line 22
def class(name = nil, &block)
if name.nil?
klass
else
Rule.new(self).with_class(name, &block)
end
end
|
#element(name, &block) ⇒ Object
17
18
19
|
# File 'lib/css-native.rb', line 17
def element(name, &block)
Rule.new(self).with_element(name, &block)
end
|
#id(name, &block) ⇒ Object
30
31
32
|
# File 'lib/css-native.rb', line 30
def id(name, &block)
Rule.new(self).with_id(name, &block)
end
|
#klass ⇒ Object
21
|
# File 'lib/css-native.rb', line 21
alias_method :klass, :class
|
#select(name, *args, type: :element, &block) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/css-native.rb', line 38
def select(name, *args, type: :element, &block)
case type
when :element
Rule.new(self).with(name, &block)
when :class
self.class(name, &block)
when :id
id(name, &block)
when :attribute
attribute(name, *args, &block)
else
raise RuleError.new(rule: type)
end
end
|
#to_s ⇒ Object
53
54
55
|
# File 'lib/css-native.rb', line 53
def to_s
@rules.join("\n")
end
|