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/stylesheet.rb
Defined Under Namespace
Classes: AttributeError, CSSError, GrammarError, PseudoClassError, PseudoElementError, Rule, RuleError
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
36
37
38
|
# File 'lib/css-native.rb', line 36
def initialize
@rules = []
end
|
Instance Attribute Details
#rules ⇒ Object
Returns the value of attribute rules.
35
36
37
|
# File 'lib/css-native.rb', line 35
def rules
@rules
end
|
Class Method Details
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/css-native.rb', line 20
def self.format_attribute(name, operation = :none, value = nil, case_sensitive: true)
op = case operation.to_sym
when :none then ""
when :equals then "="
when :include then "~="
when :matches then "|="
when :starts_with then "^="
when :ends_with then "$="
when :contains then "*="
else
raise AttributeError.new("undefined comparison '#{operation}' for css attribute selector")
end
"[#{name}#{op}#{value.nil? ? "" : "\"#{value}\""}#{case_sensitive ? "" : " i"}]"
end
|
12
13
14
|
# File 'lib/css-native.rb', line 12
def self.format_class(name)
".#{name}"
end
|
16
17
18
|
# File 'lib/css-native.rb', line 16
def self.format_id(name)
"##{name}"
end
|
.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) ⇒ Object
53
54
55
|
# File 'lib/css-native.rb', line 53
def attribute(name, operation = :none, value = nil, case_sensitive: true)
Rule.new(self).with_attribute(name, *args)
end
|
#class(name = nil) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/css-native.rb', line 41
def class(name = nil)
if name.nil?
klass
else
Rule.new(self).with_class(name)
end
end
|
#id(name) ⇒ Object
49
50
51
|
# File 'lib/css-native.rb', line 49
def id(name)
Rule.new(self).with_id(name)
end
|
#klass ⇒ Object
40
|
# File 'lib/css-native.rb', line 40
alias_method :klass, :class
|
#select(name, *args, type: :element) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/css-native.rb', line 57
def select(name, *args, type: :element)
case type
when :element
Rule.new(self).with(name)
when :class
self.class(name)
when :id
id(name)
when :attribute
attribute(name, *args)
else
raise RuleError.new("undefined rule type '#{type}' for css selector")
end
end
|
#to_s ⇒ Object
72
73
74
|
# File 'lib/css-native.rb', line 72
def to_s
@rules.join("\n")
end
|