class Sass::Selector::Element
An element selector (e.g. ‘h1`).
Attributes
The element name.
@return [String]
The selector namespace. ‘nil` means the default namespace, `“”` means no namespace, `“*”` means any namespace.
@return [String, nil]
Public Class Methods
@param name [String] The element name @param namespace [String, nil] See {#namespace}
# File lib/sass/selector.rb, line 220 def initialize(name, namespace) @name = name @namespace = namespace end
Public Instance Methods
@see AbstractSequence#specificity
# File lib/sass/selector.rb, line 265 def specificity 1 end
@see Selector#to_s
# File lib/sass/selector.rb, line 226 def to_s(opts = {}) @namespace ? "#{@namespace}|#{@name}" : @name end
Unification of an element selector is somewhat complicated, especially when a namespace is specified. First, if ‘sel` contains another {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.
@todo There are lots of cases that this documentation specifies;
make sure we thoroughly test **all of them**.
@todo Keep track of whether a default namespace has been declared
and handle namespace-unspecified selectors accordingly.
@see Selector#unify
# File lib/sass/selector.rb, line 252 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