Summary | Generate arbitrary output using plain Ruby |
---|---|
Short name | ruby |
Content type | text |
Provided by bundle | built-in |
API doc | Webgen::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>: {"defaults"=>{"pipeline"=>["erb", "tags", "kramdown", "blocks", "fragments"]}, "example"=>{"pipeline"=>"ruby"}}</li>
<li><b>meta</b>: {"twitter:card"=>"summary_large_image", "twitter:site"=>"@_gettalong", "twitter:creator"=>"@_gettalong", "twitter:title"=>"webgen - fast, powerful and extensible static website generator", "twitter:description"=>"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!", "twitter:image"=>"https://webgen.gettalong.org/css/images/logo.png"}</li>
<li><b>meta_property</b>: {"og:locale"=>"en_US", "og:type"=>"article", "og:title"=>"webgen - fast, powerful and extensible static website generator", "og:description"=>"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!", "og:image"=>"https://webgen.gettalong.org/css/images/logo.png", "og:url"=>"https://webgen.gettalong.org", "og:site_name"=>"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!"}</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>: <parent><basename>(-<version>)(-<modified_at>)(.<lang>)<ext></li>
<li><b>template</b>: /templates/documentation/content_processor.template</li>
<li><b>link</b>: {"prev"=>"/documentation/reference/extensions/content_processor/redcloth.en.html", "next"=>"/documentation/reference/extensions/content_processor/sass.en.html"}</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!