Class: InlineStyle::Selector
- Inherits:
-
Struct
- Object
- Struct
- InlineStyle::Selector
- Defined in:
- lib/inline-style/selector.rb
Instance Attribute Summary collapse
-
#declarations ⇒ Object
Returns the value of attribute declarations.
-
#selector_text ⇒ Object
Returns the value of attribute selector_text.
-
#specificity ⇒ Object
Returns the value of attribute specificity.
Instance Method Summary collapse
-
#inline_declarations ⇒ Object
For the most part is just declarations unless a pseudo selector.
-
#pseudo? ⇒ Boolean
Is this selector using a pseudo class?.
-
#search ⇒ Object
A slightly adjusted version of the selector_text that should be used for finding nodes.
-
#state_based_pseudo_selectors ⇒ Object
A list of state based pseudo selectors (like hover) that should be handled based on the pseudo option.
Instance Attribute Details
#declarations ⇒ Object
Returns the value of attribute declarations
7 8 9 |
# File 'lib/inline-style/selector.rb', line 7 def declarations @declarations end |
#selector_text ⇒ Object
Returns the value of attribute selector_text
7 8 9 |
# File 'lib/inline-style/selector.rb', line 7 def selector_text @selector_text end |
#specificity ⇒ Object
Returns the value of attribute specificity
7 8 9 |
# File 'lib/inline-style/selector.rb', line 7 def specificity @specificity end |
Instance Method Details
#inline_declarations ⇒ Object
For the most part is just declarations unless a pseudo selector. Then it uses the inline pseudo declarations
20 21 22 23 24 25 26 |
# File 'lib/inline-style/selector.rb', line 20 def inline_declarations if pseudo? "\n#{ selector_text.gsub /\w(?=:)/, '' } {#{ declarations }}" else declarations end end |
#pseudo? ⇒ Boolean
Is this selector using a pseudo class?
29 30 31 |
# File 'lib/inline-style/selector.rb', line 29 def pseudo? state_based_pseudo_selectors.any? {|p| selector_text.end_with? ":#{p}"} end |
#search ⇒ Object
A slightly adjusted version of the selector_text that should be used for finding nodes. Will remove the pseudo selector and prepend ‘body ’.
11 12 13 14 15 16 |
# File 'lib/inline-style/selector.rb', line 11 def search selector_text.dup.tap do |s| state_based_pseudo_selectors.each {|p| s.gsub! /:#{p}$/, ''} s.insert(0, 'body ') unless s =~ /^body/ end end |
#state_based_pseudo_selectors ⇒ Object
A list of state based pseudo selectors (like hover) that should be handled based on the pseudo option. Unlike position-based pseudo selectors (like :first-child) which once resolved to the correct node effectively get inlined like a normal selector.
37 38 39 |
# File 'lib/inline-style/selector.rb', line 37 def state_based_pseudo_selectors %w(link visited active hover focus target enabled disabled checked) end |