content_processor.ruby

SummaryGenerate arbitrary output using plain Ruby
Short nameruby
Content typetext
Provided by bundlebuilt-in
API docWebgen::ContentProcessor::Ruby

Description

This processor assumes that the content is valid Ruby code which means that you have the full power of Ruby available for generating content.

Usage

You can use the special context object in the Ruby code which is an instance of Webgen::Context and provides the rendering context and many useful methods. The methods from the ERB::Utils module are also available.

When using this processor you should set the context.content to the content that you want to generate.

Example

Here is a small example. If this text is put in a page file

data = context.node.meta_info.map do |k,v|
 "<li><b>#{h(k)}</b>: #{h(v)}</li>\n"
end

context.content = "<ul>\n#{data.join("")}</ul>"

… it will give this result:

<ul>
<li><b>handler</b>: page</li>
<li><b>blocks</b>: {&quot;defaults&quot;=&gt;{&quot;pipeline&quot;=&gt;[&quot;erb&quot;, &quot;tags&quot;, &quot;kramdown&quot;, &quot;blocks&quot;, &quot;fragments&quot;]}, &quot;example&quot;=&gt;{&quot;pipeline&quot;=&gt;&quot;ruby&quot;}}</li>
<li><b>meta</b>: {&quot;twitter:card&quot;=&gt;&quot;summary_large_image&quot;, &quot;twitter:site&quot;=&gt;&quot;@_gettalong&quot;, &quot;twitter:creator&quot;=&gt;&quot;@_gettalong&quot;, &quot;twitter:title&quot;=&gt;&quot;webgen - fast, powerful and extensible static website generator&quot;, &quot;twitter:description&quot;=&gt;&quot;webgen is a free, fast, powerful and extensible static website generator. Create a (or re-use an existing) website template, add a bunch of content files (in plain HTML or any markup language), throw in some assets and let webgen do the rest!&quot;, &quot;twitter:image&quot;=&gt;&quot;https://webgen.gettalong.org/css/images/logo.png&quot;}</li>
<li><b>meta_property</b>: {&quot;og:locale&quot;=&gt;&quot;en_US&quot;, &quot;og:type&quot;=&gt;&quot;article&quot;, &quot;og:title&quot;=&gt;&quot;webgen - fast, powerful and extensible static website generator&quot;, &quot;og:description&quot;=&gt;&quot;webgen is a free, fast, powerful and extensible static website generator. Create a (or re-use an existing) website template, add a bunch of content files (in plain HTML or any markup language), throw in some assets and let webgen do the rest!&quot;, &quot;og:image&quot;=&gt;&quot;https://webgen.gettalong.org/css/images/logo.png&quot;, &quot;og:url&quot;=&gt;&quot;https://webgen.gettalong.org&quot;, &quot;og:site_name&quot;=&gt;&quot;webgen is a free, fast, powerful and extensible static website generator. Create a (or re-use an existing) website template, add a bunch of content files (in plain HTML or any markup language), throw in some assets and let webgen do the rest!&quot;}</li>
<li><b>modified_at</b>: 2013-03-03 20:53:24 +0100</li>
<li><b>title</b>: content_processor.ruby</li>
<li><b>version</b>: default</li>
<li><b>node_class</b>: Webgen::PathHandler::PageUtils::Node</li>
<li><b>dest_path</b>: &lt;parent&gt;&lt;basename&gt;(-&lt;version&gt;)(-&lt;modified_at&gt;)(.&lt;lang&gt;)&lt;ext&gt;</li>
<li><b>template</b>: /templates/documentation/content_processor.template</li>
<li><b>link</b>: {&quot;prev&quot;=&gt;&quot;/documentation/reference/extensions/content_processor/redcloth.en.html&quot;, &quot;next&quot;=&gt;&quot;/documentation/reference/extensions/content_processor/sass.en.html&quot;}</li>
</ul>

See how the context.content is assigned the generated content. And how the ERB::Utils#h method is used for escaping special HTML characters!