<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jayway Team Blog &#187; documentation</title>
	<atom:link href="http://blog.jayway.com/tag/documentation/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jayway.com</link>
	<description>Sharing Experience</description>
	<lastBuildDate>Sat, 11 Feb 2012 10:33:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Generating diagrams in Asciidoc using Dia</title>
		<link>http://blog.jayway.com/2010/03/24/dia-diagrams-in-asciidoc/</link>
		<comments>http://blog.jayway.com/2010/03/24/dia-diagrams-in-asciidoc/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 19:59:52 +0000</pubDate>
		<dc:creator>Tobias Södergren</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[asciidoc]]></category>
		<category><![CDATA[dia]]></category>
		<category><![CDATA[diagram]]></category>
		<category><![CDATA[documentation]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=5140</guid>
		<description><![CDATA[This article describes how Dia can be used to generate diagrams for the Asciidoc documentation toolkit. For those of you that have never worked with these products, I have added some short descriptions: This text is taken from the Asciidoc home page. Asciidoc is a text document format for writing short documents, articles, books and [...]]]></description>
			<content:encoded><![CDATA[<p>This article describes how Dia can be used to generate diagrams for the Asciidoc documentation toolkit. For those of you that have never worked with these products, I have added some short descriptions:</p>
<p>This text is taken from the <a href="http://www.methods.co.nz/asciidoc/index.html">Asciidoc home page</a>.</p>
<blockquote><p>
Asciidoc is a text document format for writing short documents, articles, books and UNIX man pages. AsciiDoc files can be translated to HTML and DocBook markups using the asciidoc(1) command.
</p></blockquote>
<p>This text is taken from the <a href="http://live.gnome.org/Dia">Dia home page</a>.</p>
<blockquote><p>
Dia is a GTK+ based diagram creation program for GNU/Linux, Unix and Windows released under the GPL license. Dia is roughly inspired by the commercial Windows program 'Visio', though more geared towards informal diagrams for casual use.
</p></blockquote>
<p><a href="http://live.gnome.org/Dia/Screenshots">Screenshots</a> for the Dia program.</p>
<p>Dia and Asciidoc is available for different linux distributions, I installed them in Ubuntu using</p>
<pre class="bash/script">
$ sudo aptitude install asciidoc dia
</pre>
<p>They can also be installed on OS X using, for example, the <a href="http://www.macports.org/">MacPorts</a> project, in which case you write:</p>
<pre class="bash/script">
$ sudo port install asciidoc
$ sudo port install dia
</pre>
<p>And then wait for a while when everything compiles..</p>
<h1>The solution</h1>
<p>Asciidoc has the possibility to import files when generating the documentation, which is a nice feature when you don't want to duplicate information and have it up-to-date. For example, it can import images, show the content of XML files, generate diagrams using various <a href="http://www.graphviz.org/">graphviz</a> syntax and so on. </p>
<p>Dia can export its diagrams to various image formats and this can be done on the command line. Using this feature of Dia it is actually possible to have Asciidoc generating image files from Dia's file format, here is how to do it:</p>
<h2>Step one, creating the Asciidoc plugin</h2>
<p>As asciidoc cannot read the native Dia's file format, it needs to trigger the export functionality of Dia. It is possible to extend Asciidoc by writing a filter, which is just a shell command reading from standard input and writing to standard output. In this specific case, the parameters to the shell process will be used and the image template functionality existing in Asciidoc will take care of reading from the generated image.</p>
<p>Asciidoc reads filter configuration files from four different locations in the following order:</p>
<ol>
<li> It looks in the user’s $HOME/.asciidoc/filters directory. </li>
<li> The global filters directory (usually /etc/asciidoc/filters or /usr/local/etc/asciidoc) directory is searched.</li>
<li> It looks in the asciidoc(1) ./filters directory. </li>
<li> It relies on the executing shell to search the environment search path ($PATH). </li>
</ol>
<p>Here I will put the filter in my home directory. Start with creating the document structure:</p>
<pre class="shell">
   $HOME/.asciidoc/filters/dia
</pre>
<p>In the <em>dia</em> directory, create the file <em>dia-filter.conf</em> with the following content:</p>
<pre class="plain">
#
# AsciiDoc Dia filter configuration file.
#
# Version: 0.1

[blockdef-listing]
dia-style=template="dia-block",subs=(),posattrs=("style","file","target","size"),filter='dia -t png -e "{outdir={indir}}/{imagesdir=}{imagesdir?/}{target}" "{outdir}/{file}" {size?-s {size}} > /dev/null'

[dia-block]
template::[image-blockmacro]
</pre>
<p>Now Asciidoc has been extended with a filter that takes the parameters <strong>file</strong>, <strong>target</strong> and <strong>size</strong> where the last parameter is optional. The next section describes how to use this filter in Asciidoc.</p>
<h2>Step two, Import Dia diagram files in Asciidoc</h2>
<p>To use the dia filter in Asciidoc, the following syntax is used:</p>
<pre class="plain text">
[dia "infile.dia", "outfile.png", "x480"]
-------------------------------
-------------------------------
</pre>
<p>The syntax above will trigger the filter and provide 'infile.dia' as source which should be a diagram saved in Dia, 'outfile.png' is the image file to be generated and create a 480 pixels wide image. Writing the size as '480x' will specify the height of the image.<br />
Don't forget the dashes, otherwise the filter will not be triggered.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2010/03/24/dia-diagrams-in-asciidoc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

