Back to the extension listing.
Webgen::ContentProcessor::Erb
Summary
As short name for the content processor (used, for example, in the pipeline
option of a block in a
file in Webgen Page Format) one of the following can be
used: erb
.
Description
This processer uses ERB (embedded Ruby) to process content. For detailed information about ERB have
a look at its documentation by executing ri ERB
or the ruby documentation
site!
You can use the special object context
in your ERB code which provides the whole rendering context
and, for example, the following useful methods:
-
website
: Provides access to theWebgen::Website
object which can be used to access all aspects of the currently rendered website. -
node
(orcontent_node
): The node that gets currently rendered. Should be used for retrieving meta information. -
ref_node
: The reference node which is the source of the ERB code that is executed. Should be used, for example, for resolving paths. -
dest_node
: The node in which the result gets inserted. Should be used for calculating relative paths.
For a complete list of supported methods have a look at the API documentation for Webgen::Context.
Here is a small usage example. The following 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 %>
… will give the result:
Counting 5 items dynamically:
* item 1
* item 2
* item 3
* item 4
* item 5
Outputting all meta information:
* sort_info =
* title = Webgen::ContentProcessor::Erb
* modified_at = 2010-07-15 07:31:56 +0200
* output_path = standard
* output_path_style = [:parent, :basename, [".", :lang], :ext]
* kind = page
* fragments_in_menu = true
* template = ../contentprocessor.template
The second line shows the first form of the ERB tags which executes Ruby code but does not output
anything: it just starts a for
loop. On the third line the second form of ERB tags is used to
output the result of the Ruby code (note the equation sign!). And the fourth line completes the
for
loop by adding the needed end
keyword.
You may need to ensure that the ERB start and end tags are not processed by the content processor. For example, when using the RedCloth content processor, you may need to surround the ERB code with
<notextile>
tags!
Back to the extension listing.