[daisy] Context Sensitive Variables

Bruno Dumon bruno at outerthought.org
Thu May 15 22:36:20 CEST 2008


On Thu, 2008-05-15 at 13:06 -0700, Nick M. wrote:
> In some documentation I'm writing, I have a set of instructions that looks
> something like this:
> 
> <p>Perform the following steps</p>
>   <ol>
>     <li>
>       Step 1: Click button "A"
>     </li>
>     <li>
>       Step 2: Browse to directory "C:\somedirectory"
>     </li>
>     <li>
>       Step 3: Open the file "somefile.txt"
>     </li>
>   </ol>
> <p>Now you're done</p>
> 
> This set of instructions is repeated almost exactly in about 30 documents,
> but the directory in step 2 and the file in step 3 change in each document.
> 
> So my question is: would it be possible to set these instructions as a
> single variable, but still be able to change the directory and filename on
> each document? I considered setting it up as three separate variables, where
> I could then manually insert the directory and filename, but ideally I would
> like to be able to keep the directory and filename within the same set of
> <li> tags that they're currently.
> 
> Any help on this issue would be greatly appreciated.

Daisy HTML parts are basically static content, besides the possibility
for document includes, embedded queries and variables.

One possible improvement in Daisy (didn't think too deeply about this)
might be to allow variables to a per-document-include level, allowing
you to put the above blurb in a separate Daisy document and including it
at various locations with the variable values specified as part of the
include instruction.

Since this is not possible today in Daisy, an alternative is to do
something similar by building a Daisy Wiki extension
( http://cocoondev.org/daisydocs-2_2/374-cd/60-cd.html ).

You could call the extension by adding include instructions in documents
with an URL like:

cocoon:/ext/my-extension?directory=c:\somedirectory&file=somefile.txt

The extension itself doesn't need to contain any code, just a
sitemap.xmap file and a template file.

There's some tutorial-style docs here:
http://cocoondev.org/daisydocs-2_2/374-cd/60-cd/204-cd.html

To give you a hand, your sitemap could look like this:

<?xml version="1.0"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">

  <map:components>
  </map:components>

  <map:views>
  </map:views>

  <map:resources>
  </map:resources>

  <map:pipelines>

   <map:pipeline type="noncaching">
     <map:parameter name="outputBufferSize" value="8192"/>

     <map:match pattern="">
       <map:generate type="jx" src="template.xml"/>
       <map:serialize type="xml"/>
     </map:match>

   </map:pipeline>

 </map:pipelines>
</map:sitemap>


With the template.xml file looking like this:

<div>

<p>Perform the following steps</p>
  <ol>
    <li>
      Step 1: Click button "A"
    </li>
    <li>
      Step 2: Browse to directory
"${cocoon.request.getParameter("directory")}"
    </li>
    <li>
      Step 3: Open the file "${cocoon.request.getParameter("file")}"
    </li>
  </ol>
<p>Now you're done</p>
</div>

You could read the actual template content from a Daisy document if you
want authors to be able to read it.

(note: this solution will only work in the Wiki HTML publishing, not
PDFs)

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought                            http://www.daisycms.org/
bruno at outerthought.org              http://www.kauriproject.org/



More information about the daisy mailing list