Class Webgen::SourceHandler::Fragment
In: lib/webgen/sourcehandler/fragment.rb
Parent: Object
Error RenderError CommandNotFoundError LoadError NodeCreationError ::Rake::TaskLib WebgenTask Context\n[lib/webgen/context.rb\nlib/webgen/context/nodes.rb\nlib/webgen/context/render.rb\nlib/webgen/context/tags.rb] Node Tree FileSystem Sitemap Coderay Sitemap IncludeFile Langbar BreadcrumbTrail TikZ Menu Feed Copy Virtual Sitemap Directory Page Fragment Template Metainfo Memory Resource Tags Fragments Website Tidy Head Kramdown Less Xmllint Blocks Helpers Configuration Comparable Language Path StandardError CmdParse::CommandParser CommandParser CmdParse::Command RunCommand WebguiCommand CreateCommand ApplyCommand ExecuteCommand Link Date Relocatable Metainfo WebsiteAccess Main Loggable OutputPathHelpers ::Kramdown::Converter::Html KramdownHtmlConverter Cache Blackboard WebsiteManager Logger Page ProxyNode Utils TarArchive Stacked FileSystem RDoc Sass Erb RDiscount Erubis Haml Maruku Builder RedCloth AccessHash lib/webgen/cache.rb lib/webgen/error.rb lib/webgen/languages.rb lib/webgen/blackboard.rb lib/webgen/website.rb lib/webgen/tree.rb lib/webgen/websitemanager.rb lib/webgen/logger.rb lib/webgen/configuration.rb lib/webgen/context/tags.rb lib/webgen/path.rb lib/webgen/webgentask.rb lib/webgen/page.rb lib/webgen/node.rb 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 ClassMethods WebsiteAccess LanguageManager lib/webgen/output/filesystem.rb Output lib/webgen/common/sitemap.rb Common 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/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/source/tararchive.rb lib/webgen/source/stacked.rb lib/webgen/source/resource.rb lib/webgen/source/filesystem.rb Source lib/webgen/contentprocessor/less.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 Loggable Webgen dot/m_81_0.png

Handles page fragment nodes and provides utility methods for parsing HTML headers and generating fragment nodes from them.

Methods

Included Modules

Base Webgen::WebsiteAccess

Constants

HTML_HEADER_REGEXP = /<h([123456])(?:>|\s([^>]*)>)(.*?)<\/h\1\s*>/i
HTML_ATTR_REGEXP = /\s*(\w+)\s*=\s*('|")(.+?)\2\s*/

Public Instance methods

Create nested fragment nodes under parent from sections (which can be created using parse_html_headers). path is the source path that defines the fragments (which is not the same as the creation path for parent). The meta information in_menu of the fragment nodes is set to the parameter in_menu and the meta info sort_info is calculated from the base si value.

[Source]

    # File lib/webgen/sourcehandler/fragment.rb, line 53
53:     def create_fragment_nodes(sections, parent, path, in_menu, si = 1000)
54:       sections.each do |level, id, title, sub_sections|
55:         fragment_path = parent.alcn.sub(/#.*$/, '') + '#' + id
56:         node = website.blackboard.invoke(:create_nodes,
57:                                          Webgen::Path.new(fragment_path, path.source_path),
58:                                          self) do |cn_path|
59:           cn_path.meta_info['title'] = title
60:           cn_path.meta_info['in_menu'] = in_menu
61:           cn_path.meta_info['sort_info'] = si = si.succ
62:           create_node(cn_path, :parent => parent)
63:         end.first
64:         create_fragment_nodes(sub_sections, node, path, in_menu, si.succ)
65:       end
66:     end

Parse the string content for headers +h1+, …, +h6+ and return the found, nested sections.

Only those headers are used which have an id attribute set. The method returns a list of arrays with entries level, id, title, sub sections where sub sections is such a list again.

[Source]

    # File lib/webgen/sourcehandler/fragment.rb, line 20
20:     def parse_html_headers(content)
21:       sections = []
22:       stack = []
23:       content.scan(HTML_HEADER_REGEXP).each do |level,attrs,title|
24:         next if attrs.nil?
25:         id_attr = attrs.scan(HTML_ATTR_REGEXP).find {|name,sep,value| name == 'id'}
26:         next if id_attr.nil?
27:         id = id_attr[2]
28: 
29:         section = [level.to_i, id, title, []]
30:         success = false
31:         while !success
32:           if stack.empty?
33:             sections << section
34:             stack << section
35:             success = true
36:           elsif stack.last.first < section.first
37:             stack.last.last << section
38:             stack << section
39:             success = true
40:           else
41:             stack.pop
42:           end
43:         end
44:       end
45:       sections
46:     end

[Validate]