Class: Webgen::Block
- Inherits:
-
Object
- Object
- Webgen::Block
- Defined in:
- lib/webgen/page.rb
Overview
A single block within a Page object. The content of the block can be rendered using the #render method.
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
The content of the block.
-
#name ⇒ Object
readonly
The name of the block.
-
#options ⇒ Object
readonly
The options set specifically for this block.
Instance Method Summary collapse
-
#initialize(name, content, options) ⇒ Block
constructor
Create a new block with the name
nameand the givencontentandoptions. -
#render(context) ⇒ Object
Render the block using the provided context object.
Constructor Details
#initialize(name, content, options) ⇒ Block
Create a new block with the name name and the given content and options.
18 19 20 |
# File 'lib/webgen/page.rb', line 18 def initialize(name, content, ) @name, @content, = name, content, end |
Instance Attribute Details
#content ⇒ Object (readonly)
The content of the block.
12 13 14 |
# File 'lib/webgen/page.rb', line 12 def content @content end |
#name ⇒ Object (readonly)
The name of the block.
9 10 11 |
# File 'lib/webgen/page.rb', line 9 def name @name end |
#options ⇒ Object (readonly)
The options set specifically for this block.
15 16 17 |
# File 'lib/webgen/page.rb', line 15 def end |
Instance Method Details
#render(context) ⇒ Object
Render the block using the provided context object. Uses the content processors specified in the pipeline key of the options attribute to do the actual rendering.
Returns the given context with the rendered content.
26 27 28 29 30 31 32 33 34 |
# File 'lib/webgen/page.rb', line 26 def render(context) context[:content] = @content.dup context[:block] = self ['pipeline'].to_s.split(/,/).each do |processor| raise "No such content processor available: #{processor}" unless context[:processors].has_key?(processor) context[:processors][processor].call(context) end context end |