content_processor.erubis

SummaryAllows one to use ERB (embedded Ruby) in the content (faster than the erb processor)
Short nameerubis
Content typetext
Provided by bundlebuilt-in
API docWebgen::ContentProcessor::Erubis

Description

This processor uses the Erubis library to process embedded Ruby statements. Erubis is quite a bit faster than the standard ERB library that is shipped with Ruby and provides many other useful options.

This extension is only available if you have installed the Erubis library. The preferred way to do this is via Rubygems:

$ gem install erubis

Usage

As with the content processor erb you can use the special context object in your ERB code which is an instance of Webgen::Context and provides the rendering context and many useful methods.

The default mode of Erubis works like ERB. So everything said on the content processor erb page is also true for Erubis. Additionally, you can customize how this processor works by using the following configuration options:

 content_processor.erubis.use_pi
Use processing instructions instead of ERB like instructions. Normally you use statements like <% result = some_method_call(opts) %> or <%= context.content_node.alcn %> in your content. When setting this option to true, you can use XML processing instructions instead, for example <?rb result = some_method_call(opts) ?> or @{context.node.alcn}@.
 content_processor.erubis.options
This is a hash which is passed to the Erubis interpreter and which can be used to set additional options.

For more information on the additional options or on how to use the processing instructions mode of Erubis, have a look at the Erubis User Guide!

Example

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

Counting 5 items dynamically:
<% for i in 1..5 %>
* item <%= i %>
<% end %>

Outputting all meta information:
<% context.node.meta_info.each do |k,v| %>
* <%= k %> = <%= v %>
<% end %>

… it will give this result:

Counting 5 items dynamically:
* item 1
* item 2
* item 3
* item 4
* item 5

Outputting all meta information:
* handler = page
* blocks = {"defaults"=>{"pipeline"=>["erb", "tags", "kramdown", "blocks", "fragments"]}, "example"=>{"pipeline"=>"erubis"}}
* meta = {"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"}
* meta_property = {"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!"}
* modified_at = 2013-01-27 11:32:14 +0100
* title = content_processor.erubis
* version = default
* node_class = Webgen::PathHandler::PageUtils::Node
* dest_path = <parent><basename>(-<version>)(-<modified_at>)(.<lang>)<ext>
* template = /templates/documentation/content_processor.template
* link = {"prev"=>"/documentation/reference/extensions/content_processor/erb.en.html", "next"=>"/documentation/reference/extensions/content_processor/fragments.en.html"}

If you compare this result with that from the content processor erb you see that spaces around ERB tags are automatically trimmed in the correct way (i.e. spaces around ERB tags without output is trimmed while spaces around those with output are not).