Class Webgen::Page
In: lib/webgen/page.rb
Parent: Object
Error RenderError CommandNotFoundError LoadError NodeCreationError ::Rake::TaskLib WebgenTask Helpers Configuration Node Context\n[lib/webgen/context.rb\nlib/webgen/context/nodes.rb\nlib/webgen/context/render.rb\nlib/webgen/context/tags.rb] Tree FileSystem Sitemap Copy Feed Virtual Sitemap Directory Page Fragment Template Metainfo Memory Coderay Sitemap IncludeFile BreadcrumbTrail Langbar TikZ Menu Tags Fragments Resource Website Tidy Head Kramdown Less Xmllint Blocks Comparable Language Path StandardError CmdParse::CommandParser CommandParser CmdParse::Command RunCommand WebguiCommand CreateCommand ApplyCommand WebsiteAccess Main Loggable OutputPathHelpers ExecuteCommand Link Date Relocatable Metainfo ::Kramdown::Converter::Html KramdownHtmlConverter Cache Blackboard WebsiteManager Logger Page ProxyNode Utils Scss RDoc Sass Erb RDiscount Erubis Haml Maruku Builder RedCloth AccessHash TarArchive Stacked FileSystem lib/webgen/cache.rb lib/webgen/error.rb lib/webgen/languages.rb lib/webgen/context/render.rb lib/webgen/website.rb lib/webgen/blackboard.rb lib/webgen/tree.rb lib/webgen/websitemanager.rb lib/webgen/logger.rb lib/webgen/configuration.rb lib/webgen/path.rb lib/webgen/webgentask.rb lib/webgen/page.rb lib/webgen/node.rb ClassMethods WebsiteAccess lib/webgen/cli/run_command.rb lib/webgen/cli/utils.rb lib/webgen/cli/apply_command.rb lib/webgen/cli/webgui_command.rb lib/webgen/cli.rb lib/webgen/cli/create_command.rb Color CLI LanguageManager lib/webgen/output/filesystem.rb Output lib/webgen/common/sitemap.rb Common lib/webgen/sourcehandler/memory.rb lib/webgen/sourcehandler/metainfo.rb lib/webgen/sourcehandler/copy.rb lib/webgen/sourcehandler/directory.rb lib/webgen/sourcehandler.rb lib/webgen/sourcehandler/page.rb lib/webgen/sourcehandler/template.rb lib/webgen/sourcehandler/fragment.rb lib/webgen/sourcehandler/sitemap.rb lib/webgen/sourcehandler/virtual.rb lib/webgen/sourcehandler/feed.rb OutputPathHelpers Base SourceHandler lib/webgen/tag/coderay.rb lib/webgen/tag/relocatable.rb lib/webgen/tag/menu.rb lib/webgen/tag/langbar.rb lib/webgen/tag/executecommand.rb lib/webgen/tag/breadcrumbtrail.rb lib/webgen/tag/metainfo.rb lib/webgen/tag/includefile.rb lib/webgen/tag/link.rb lib/webgen/tag/date.rb lib/webgen/tag/tikz.rb lib/webgen/tag/sitemap.rb Base Tag lib/webgen/contentprocessor/less.rb lib/webgen/contentprocessor/scss.rb lib/webgen/contentprocessor/blocks.rb lib/webgen/contentprocessor/rdoc.rb lib/webgen/contentprocessor/sass.rb lib/webgen/contentprocessor/erb.rb lib/webgen/contentprocessor/rdiscount.rb lib/webgen/contentprocessor/tags.rb lib/webgen/contentprocessor/erubis.rb lib/webgen/contentprocessor/kramdown/html.rb lib/webgen/contentprocessor/haml.rb lib/webgen/contentprocessor/maruku.rb lib/webgen/contentprocessor/xmllint.rb lib/webgen/contentprocessor/kramdown.rb lib/webgen/contentprocessor/head.rb lib/webgen/contentprocessor/builder.rb lib/webgen/contentprocessor/tidy.rb lib/webgen/contentprocessor/redcloth.rb lib/webgen/contentprocessor/fragments.rb lib/webgen/contentprocessor.rb ContentProcessor lib/webgen/source/tararchive.rb lib/webgen/source/stacked.rb lib/webgen/source/resource.rb lib/webgen/source/filesystem.rb Source Loggable Webgen dot/m_82_0.png

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.

Methods

Classes and Modules

Class Webgen::Page::Block
Class Webgen::Page::FormatError

Attributes

blocks  [R]  The hash of blocks for the page.
meta_info  [R]  The contents of the meta information block.

Public Class methods

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.

[Source]

    # File lib/webgen/page.rb, line 67
67:       def from_data(data, meta_info = {})
68:         md = /(#{RE_META_INFO})?(.*)/m.match(normalize_eol(data))
69:         meta_info = meta_info.merge(parse_meta_info(md[1], data))
70:         blocks = parse_blocks(md[2] || '', meta_info)
71:         new(meta_info, blocks)
72:       end

Parse the given string data in Webgen Page Format and return the found meta information.

[Source]

    # File lib/webgen/page.rb, line 75
75:       def meta_info_from_data(data)
76:         md = /(#{RE_META_INFO})?/m.match(normalize_eol(data))
77:         parse_meta_info(md[1], data)
78:       end

Create a new Page object with the meta information provided in meta_info and the given blocks.

[Source]

     # File lib/webgen/page.rb, line 147
147:     def initialize(meta_info = {}, blocks = {})
148:       @meta_info = meta_info
149:       @blocks = blocks
150:     end

Private Class methods

Normalize the end-of-line encodings to Unix style.

[Source]

    # File lib/webgen/page.rb, line 85
85:       def normalize_eol(data)
86:         data.gsub(/\r\n?/, "\n")
87:       end

Parse all blocks in data and return them. Meta information can be provided in meta_info which is used for setting the block names and options.

[Source]

     # File lib/webgen/page.rb, line 111
111:       def parse_blocks(data, meta_info)
112:         scanned = data.scan(RE_BLOCKS)
113:         raise(FormatError, 'No content blocks specified') if scanned.length == 0
114: 
115:         blocks = {}
116:         scanned.each_with_index do |block_data, index|
117:           options, content = *block_data
118:           md = RE_BLOCKS_OPTIONS.match(options.to_s)
119:           raise(FormatError, "Found invalid blocks starting line for block #{index+1}: #{options}") if content =~ /\A---/ || md.nil?
120:           options = Hash[*md[1].to_s.scan(/(\w+):([^\s]*)/).map {|k,v| [k, (v == '' ? nil : YAML::load(v))]}.flatten]
121:           options = (meta_info['blocks']['default'] || {} rescue {}).
122:             merge((meta_info['blocks'][index+1] || {} rescue {})).
123:             merge(options)
124: 
125:           name = options.delete('name') || (index == 0 ? 'content' : 'block' + (index + 1).to_s)
126:           raise(FormatError, "Previously used name '#{name}' also used for block #{index+1}") if blocks.has_key?(name)
127:           content ||= ''
128:           content.gsub!(/^(\\+)(---.*?)$/) {|m| "\\" * ($1.length / 2) + $2}
129:           content.chomp!("\n") unless index + 1 == scanned.length
130:           blocks[name] = blocks[index+1] = Block.new(name, content, options)
131:         end
132:         meta_info.delete('blocks')
133:         blocks
134:       end

Parse the meta info string in mi_data and return the hash with the meta information. The original data is used for checking the validness of the meta information block.

[Source]

     # File lib/webgen/page.rb, line 91
 91:       def parse_meta_info(mi_data, data)
 92:         if mi_data.nil? && data =~ RE_META_INFO_START
 93:           raise FormatError, 'Found start line for meta information block but no valid meta information block'
 94:         elsif mi_data.nil?
 95:           {}
 96:         else
 97:           begin
 98:             meta_info = YAML::load(mi_data.to_s)
 99:             unless meta_info.kind_of?(Hash)
100:               raise FormatError, "Invalid structure of meta information block: expected YAML hash but found #{meta_info.class}"
101:             end
102:           rescue ArgumentError => e
103:             raise FormatError, "Invalid YAML syntax in meta information block: #{e.message}"
104:           end
105:           meta_info
106:         end
107:       end

[Validate]