Class: Webgen::Page
- Inherits:
-
Object
- Object
- Webgen::Page
- Defined in:
- lib/webgen/page.rb
Overview
A Page object wraps a meta information hash and an array of Block objects. It is normally generated from a file or string in Webgen Page Format using the provided class methods.
Constant Summary collapse
- RE_META_INFO_START =
/\A---\s*(?:\n|\r|\r\n)/m
- RE_META_INFO =
/\A---\s*(?:\n|\r|\r\n).*?(?:\n|\r|\r\n)(?=---.*?(?:\n|\r|\r\n)|\Z)/m
- RE_BLOCKS_OPTIONS =
/^--- *?(?: *((?:\w+:[^\s]* *)*))?$|^$/- RE_BLOCKS_START =
/^--- .*?$|^--- *$/- RE_BLOCKS =
/(?:(#{RE_BLOCKS_START})|\A)(.*?)(?:(?=#{RE_BLOCKS_START})|\Z)/m
Instance Attribute Summary collapse
-
#blocks ⇒ Object
readonly
The array of blocks for the page.
-
#meta_info ⇒ Object
readonly
The contents of the meta information block.
Class Method Summary collapse
-
.from_data(data, meta_info = {}) ⇒ Object
Parse the given string
datain Webgen Page Format and initialize a new Page object with the information.
Instance Method Summary collapse
-
#initialize(meta_info = {}, blocks = nil) ⇒ Page
constructor
Create a new Page object with the meta information provided in
meta_infoand the givenblocks.
Constructor Details
#initialize(meta_info = {}, blocks = nil) ⇒ Page
Create a new Page object with the meta information provided in meta_info and the given blocks.
126 127 128 129 |
# File 'lib/webgen/page.rb', line 126 def initialize( = {}, blocks = nil) = @blocks = blocks end |
Instance Attribute Details
#blocks ⇒ Object (readonly)
The array of blocks for the page.
122 123 124 |
# File 'lib/webgen/page.rb', line 122 def blocks @blocks end |
#meta_info ⇒ Object (readonly)
The contents of the meta information block.
119 120 121 |
# File 'lib/webgen/page.rb', line 119 def end |
Class Method Details
.from_data(data, meta_info = {}) ⇒ Object
Parse the given string data in Webgen Page Format and initialize a new Page object with the information. The meta_info parameter can be used to provide default meta information.
56 57 58 59 60 61 62 63 64 |
# File 'lib/webgen/page.rb', line 56 def from_data(data, = {}) md = /(#{RE_META_INFO})?(.*)/m.match(normalize_eol(data)) if md[1].nil? && data =~ RE_META_INFO_START raise WebgenPageFormatError, 'Found start line for meta information block but no valid meta information block' end = .merge(md[1].nil? ? {} : (md[1])) blocks = parse_blocks(md[2] || '', ) new(, blocks) end |