Sha256: d3d92c2105d91022673080e85155bf0158beaf45864769780ac9311aece1ac23
Contents?: true
Size: 1.71 KB
Versions: 1
Compression:
Stored size: 1.71 KB
Contents
# frozen_string_literal: true require 'forwardable' module Roadie # @api private # A style block is the combination of a {Selector} and a list of {StyleProperty}. class StyleBlock extend Forwardable attr_reader :selector, :properties, :media # @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)'] def initialize(selector, properties, media) @selector = selector @properties = properties @media = media.map(&:to_s) end # @!method specificity # @see Selector#specificity def_delegators :selector, :specificity # @!method selector_string # @see Selector#to_s def_delegator :selector, :to_s, :selector_string # Checks whether the media query can be inlined # @see inlineable_media # @return {Boolean} def inlinable? inlinable_media? && selector.inlinable? end # String representation of the style block. This is valid CSS and can be # used in the DOM. # @return {String} 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 # 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} def inlinable_media? @media.none? { |media_query| media_query.include? '(' } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
roadie-4.0.0 | lib/roadie/style_block.rb |