Class Webgen::ContentProcessor::Blocks
In: lib/webgen/contentprocessor/blocks.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

Replaces special xml tags with the rendered content of a node.

Methods

call   render_block  

Included Modules

Webgen::Loggable

Constants

BLOCK_RE = /<webgen:block\s*?((?:\s\w+=('|")[^'"]+\2)+)\s*\/>/
BLOCK_ATTR_RE = /(\w+)=('|")([^'"]+)\2/

Public Instance methods

Replace the webgen:block xml tags with the rendered content of the specified node.

[Source]

    # File lib/webgen/contentprocessor/blocks.rb, line 14
14:     def call(context)
15:       context.content.gsub!(BLOCK_RE) do |match|
16:         attr = {}
17:         match_object = $~
18:         attr[:line_nr_proc] = lambda { match_object.pre_match.scan("\n").size + 1 }
19:         match.scan(BLOCK_ATTR_RE) {|name, sep, content| attr[name.to_sym] = content}
20:         render_block(context, attr)
21:       end
22:       context
23:     end

Render a block of a page node and return the result.

The Webgen::Context object context is used as the render context and the options hash needs to hold all relevant information, that is:

:name (mandatory)
The name of the block that should be used.
:chain
The node chain used for rendering. If this is not specified, the node chain from the context is used. It needs to be a String in the format (A)LCN;(A)LCN;… or an array of nodes.
:node
Defines which node in the node chain should be used. Valid values are next (= default value; the next node in the node chain), first (the first node in the node chain with a block called name) or current (the currently rendered node, ignores the chain option).
:notfound
If this property is set to ignore, a missing block will not raise an error. It is unset by default, so missing blocks will raise errors.

[Source]

    # File lib/webgen/contentprocessor/blocks.rb, line 43
43:     def render_block(context, options)
44:       if options[:chain].nil?
45:         used_chain = (context[:chain].length > 1 ? context[:chain][1..-1] : context[:chain]).dup
46:       elsif options[:chain].kind_of?(Array)
47:         used_chain = options[:chain]
48:         dest_node = context.content_node
49:       else
50:         paths = options[:chain].split(';')
51:         used_chain = paths.collect do |path|
52:           temp_node = context.ref_node.resolve(path.strip, context.dest_node.lang)
53:           if temp_node.nil?
54:             raise Webgen::RenderError.new("Could not resolve <#{path.strip}>",
55:                                           self.class.name, context.dest_node,
56:                                           context.ref_node, (options[:line_nr_proc].call if options[:line_nr_proc]))
57:           end
58:           temp_node
59:         end.compact
60:         return '' if used_chain.length != paths.length
61:         dest_node = context.content_node
62:       end
63: 
64:       if options[:node] == 'first'
65:         used_chain.shift while used_chain.length > 0 && !used_chain.first.node_info[:page].blocks.has_key?(options[:name])
66:       elsif options[:node] == 'current'
67:         used_chain = context[:chain].dup
68:       end
69:       block_node = used_chain.first
70: 
71:       if !block_node || !block_node.node_info[:page].blocks.has_key?(options[:name])
72:         if options[:notfound] == 'ignore'
73:           return ''
74:         elsif block_node
75:           raise Webgen::RenderError.new("No block named '#{options[:name]}' found in <#{block_node}>",
76:                                         self.class.name, context.dest_node,
77:                                         context.ref_node, (options[:line_nr_proc].call if options[:line_nr_proc]))
78:         else
79:           raise Webgen::RenderError.new("No node in the render chain has a block named '#{options[:name]}'",
80:                                         self.class.name, context.dest_node,
81:                                         context.ref_node, (options[:line_nr_proc].call if options[:line_nr_proc]))
82:         end
83:       end
84: 
85:       context.dest_node.node_info[:used_nodes] << block_node.alcn
86:       tmp_context = block_node.node_info[:page].blocks[options[:name]].render(context.clone(:chain => used_chain, :dest_node => dest_node))
87:       tmp_context.content
88:     end

[Validate]