Class: Roadie::StyleBlock Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/roadie/style_block.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A style block is the combination of a Selector and a list of StyleProperty.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(selector, properties, media) ⇒ StyleBlock

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of StyleBlock.

Parameters:

  • selector (Selector)
  • properties (Array<StyleProperty>)
  • media (Array<String>)

    Array of media types, e.g. @media screen, print and (max-width 800px) will become

    ‘screen’, ‘print and (max-width 800px)’


17
18
19
20
21
# File 'lib/roadie/style_block.rb', line 17

def initialize(selector, properties, media)
  @selector = selector
  @properties = properties
  @media = media.map(&:to_s)
end

Instance Attribute Details

#mediaObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/roadie/style_block.rb', line 10

def media
  @media
end

#propertiesObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/roadie/style_block.rb', line 10

def properties
  @properties
end

#selectorObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/roadie/style_block.rb', line 10

def selector
  @selector
end

Instance Method Details

#inlinable?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks whether the media query can be inlined

Returns:

  • (Boolean)

See Also:

  • inlineable_media


33
34
35
# File 'lib/roadie/style_block.rb', line 33

def inlinable?
  inlinable_media? && selector.inlinable?
end

#selector_stringObject



28
# File 'lib/roadie/style_block.rb', line 28

def_delegator :selector, :to_s, :selector_string

#specificityObject



25
# File 'lib/roadie/style_block.rb', line 25

def_delegators :selector, :specificity

#to_sString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

String representation of the style block. This is valid CSS and can be used in the DOM.

Returns:

  • (String)


40
41
42
43
# File 'lib/roadie/style_block.rb', line 40

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