Class: Sass::Selector::Element
Overview
An element selector (e.g. h1
).
Instance Attribute Summary collapse
-
#name ⇒ Array<String, Sass::Script::Node>
readonly
The element name.
-
#namespace ⇒ Array<String, Sass::Script::Node>?
readonly
The selector namespace.
Attributes inherited from Simple
Instance Method Summary collapse
-
#initialize(name, namespace) ⇒ Element
constructor
A new instance of Element.
- #specificity
- #to_a
-
#unify(sels)
Unification of an element selector is somewhat complicated, especially when a namespace is specified.
Methods inherited from Simple
#eql?, #hash, #inspect, #to_s, #unify_namespaces
Constructor Details
#initialize(name, namespace) ⇒ Element
Returns a new instance of Element.
211 212 213 214 |
# File 'lib/sass/selector.rb', line 211
def initialize(name, namespace)
@name = name
@namespace = namespace
end
|
Instance Attribute Details
#name ⇒ Array<String, Sass::Script::Node> (readonly)
The element name.
199 200 201 |
# File 'lib/sass/selector.rb', line 199
def name
@name
end
|
#namespace ⇒ Array<String, Sass::Script::Node>? (readonly)
The selector namespace. nil
means the default namespace, [""]
means no namespace, ["*"]
means any namespace.
207 208 209 |
# File 'lib/sass/selector.rb', line 207
def namespace
@namespace
end
|
Instance Method Details
#specificity
256 257 258 |
# File 'lib/sass/selector.rb', line 256
def specificity
1
end
|
#to_a
217 218 219 |
# File 'lib/sass/selector.rb', line 217
def to_a
@namespace ? @namespace + ["|"] + @name : @name
end
|
#unify(sels)
There are lots of cases that this documentation specifies; make sure we thoroughly test all of them.
Keep track of whether a default namespace has been declared and handle namespace-unspecified selectors accordingly.
Unification of an element selector is somewhat complicated, especially when a namespace is specified. First, if sel
contains another Sass::Selector::Element with a different #name, then the selectors can’t be unified and nil
is returned.
Otherwise, if sel
doesn’t specify a namespace, or it specifies any namespace (via "*"
), then it’s returned with this element selector (e.g. .foo
becomes a.foo
or svg|a.foo
). Similarly, if this selector doesn’t specify a namespace, the namespace from sel
is used.
If both this selector and sel
specify namespaces, those namespaces are unified via Simple#unify_namespaces and the unified namespace is used, if possible.
243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/sass/selector.rb', line 243
def unify(sels)
case sels.first
when Universal;
when Element; return unless name == sels.first.name
else return [self] + sels
end
ns, accept = unify_namespaces(namespace, sels.first.namespace)
return unless accept
[Element.new(name, ns)] + sels[1..-1]
end
|