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 =
:stopdoc:
/\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 hash 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
data
in Webgen Page Format and initialize a new Page object with the information. -
.meta_info_from_data(data) ⇒ Object
Parse the given string
data
in Webgen Page Format and return the found meta information.
Instance Method Summary collapse
-
#initialize(meta_info = {}, blocks = {}) ⇒ Page
constructor
Create a new Page object with the meta information provided in
meta_info
and the givenblocks
.
Constructor Details
#initialize(meta_info = {}, blocks = {}) ⇒ Page
Create a new Page object with the meta information provided in meta_info
and the given blocks
.
146 147 148 149 |
# File 'lib/webgen/page.rb', line 146 def initialize( = {}, blocks = {}) @meta_info = @blocks = blocks end |
Instance Attribute Details
#blocks ⇒ Object (readonly)
The hash of blocks for the page.
142 143 144 |
# File 'lib/webgen/page.rb', line 142 def blocks @blocks end |
#meta_info ⇒ Object (readonly)
The contents of the meta information block.
139 140 141 |
# File 'lib/webgen/page.rb', line 139 def @meta_info 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.
66 67 68 69 70 71 |
# File 'lib/webgen/page.rb', line 66 def from_data(data, = {}) md = /(#{RE_META_INFO})?(.*)/m.match(normalize_eol(data)) = .merge((md[1], data)) blocks = parse_blocks(md[2] || '', ) new(, blocks) end |
.meta_info_from_data(data) ⇒ Object
Parse the given string data
in Webgen Page Format and return the found meta information.
74 75 76 77 |
# File 'lib/webgen/page.rb', line 74 def (data) md = /(#{RE_META_INFO})?/m.match(normalize_eol(data)) (md[1], data) end |