Class: Webgen::Page

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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(meta_info = {}, blocks = {})
  @meta_info = meta_info
  @blocks = blocks
end

Instance Attribute Details

#blocksObject (readonly)

The hash of blocks for the page.



142
143
144
# File 'lib/webgen/page.rb', line 142

def blocks
  @blocks
end

#meta_infoObject (readonly)

The contents of the meta information block.



139
140
141
# File 'lib/webgen/page.rb', line 139

def meta_info
  @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, meta_info = {})
  md = /(#{RE_META_INFO})?(.*)/m.match(normalize_eol(data))
  meta_info = meta_info.merge(parse_meta_info(md[1], data))
  blocks = parse_blocks(md[2] || '', meta_info)
  new(meta_info, 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 meta_info_from_data(data)
  md = /(#{RE_META_INFO})?/m.match(normalize_eol(data))
  parse_meta_info(md[1], data)
end