Class: Roadie::Stylesheet

Inherits:
Object
  • Object
show all
Defined in:
lib/roadie/stylesheet.rb

Overview

Domain object that represents a stylesheet (from disc, perhaps).

It has a name and a list of StyleBlocks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, css) ⇒ Stylesheet

Parses the CSS string into a Roadie::StyleBlocks and stores it.

Parameters:

  • name (String)
  • css (String)


15
16
17
18
# File 'lib/roadie/stylesheet.rb', line 15

def initialize(name, css)
  @name = name
  @blocks = parse_blocks(css)
end

Instance Attribute Details

#blocksArray<StyleBlock> (readonly)

Returns the current value of blocks.

Returns:

  • (Array<StyleBlock>)

    the current value of blocks



8
9
10
# File 'lib/roadie/stylesheet.rb', line 8

def blocks
  @blocks
end

#nameString (readonly)

the name of the stylesheet (“stylesheets/main.css”, “Admin user styles”, etc.). The name of the stylesheet will be visible if any errors occur.

Returns:

  • (String)

    the current value of name



8
9
10
# File 'lib/roadie/stylesheet.rb', line 8

def name
  @name
end

Instance Method Details

#each_inlinable_block {|selector, properties| ... } ⇒ Object

Yields:

  • (selector, properties)

Yield Parameters:



23
24
25
26
27
28
29
# File 'lib/roadie/stylesheet.rb', line 23

def each_inlinable_block(&block)
  # #map and then #each in order to support chained enumerations, etc. if
  # no block is provided
  inlinable_blocks.map { |style_block|
    [style_block.selector, style_block.properties]
  }.each(&block)
end

#to_sObject



31
32
33
# File 'lib/roadie/stylesheet.rb', line 31

def to_s
  blocks.join("\n")
end