Back to the extension listing.
Webgen::ContentProcessor::Builder
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: builder
.
Description
This content processor can be used to programatically create XHTML/XML documents
(Reference). The top builder object is provided through the xml
object. There are also other
objects provided by webgen available - have a look at the erb documentation.
This extension is only available if you have installed the builder library. The preferred way to do this is via Rubygems:
gem install builder
Examples
Here is a short sample of content that is valid Ruby and uses the special xml
object:
xml.h1("This a h1 header", :id => 'myid')
xml.p do |p|
p.text! "You can just write "
p.b "your"
p.text! "paragraphs here and"
p.a("link", :href => "http://someurl.com")
p.text! "them below. This is also a"
p.i "nice"
p.text! "format!"
end
xml.blockquote(:class => 'information') do |bq|
bq.text! "Citations are easy too."
bq.text! "Really. And you can assign them attributes."
end
xml.ul do |ul|
ul.li "Lists"
ul.li "aren't"
ul.li "difficult"
ul.li "either."
end
Following is a complete example which shows how to use this extension in a page file which generates
a custom XML document (the content
block has to be valid Ruby!):
---
output_path_style: [:parent, :basename, ['.', :lang], '.xml']
title: Person Object
template: ~
--- pipeline:builder
xml.persons(:path => context.node.alcn) do |p|
p.person do |b|
b.firstname('Thomas')
b.lastname('Leitner')
end
p.person do |b|
b.firstname('Other first')
b.lastname('Other last')
end
end
The above will produce the following output:
<persons path="/test.xml">
<person>
<firstname>Thomas</firstname>
<lastname>Leitner</lastname>
</person>
<person>
<firstname>Other first</firstname>
<lastname>Other last</lastname>
</person>
</persons>
Back to the extension listing.