class Roadie::StyleBlock
@api private A style block is the combination of a {Selector} and a list of {StyleProperty}.
Attributes
media[R]
properties[R]
selector[R]
Public Class Methods
new(selector, properties, media)
click to toggle source
@param [Selector] selector @param [Array<StyleProperty>] properties @param [Array<String>] media Array of media types, e.g.
@media screen, print and (max-width 800px) will become ['screen', 'print and (max-width 800px)']
# File lib/roadie/style_block.rb, line 15 def initialize(selector, properties, media) @selector = selector @properties = properties @media = media.map(&:to_s) end
Public Instance Methods
inlinable?()
click to toggle source
Checks whether the media query can be inlined @see inlineable_media @return {Boolean}
# File lib/roadie/style_block.rb, line 31 def inlinable? inlinable_media? && selector.inlinable? end
to_s()
click to toggle source
String representation of the style block. This is valid CSS and can be used in the DOM. @return {String}
# File lib/roadie/style_block.rb, line 38 def to_s # NB - leave off redundant final semicolon - see https://www.w3.org/TR/CSS2/syndata.html#declaration "#{selector}{#{properties.map(&:to_s).join(';')}}" end
Private Instance Methods
inlinable_media?()
click to toggle source
A media query cannot be inlined if it contains any advanced rules e.g. @media only screen {…} is ok to inline but @media only screen and (max-width: 600px) {…} cannot be inlined @return {Boolean}
# File lib/roadie/style_block.rb, line 49 def inlinable_media? @media.none? { |media_query| media_query.include? '(' } end