help-recutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [help-recutils] looping constructs for templating


From: Jose E. Marchesi
Subject: Re: [help-recutils] looping constructs for templating
Date: Mon, 16 May 2011 14:14:38 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Hi David.
    
    -{{ingredient_amount[1]}} {{ingredient_unit[1]}} {{ingredient[1]}}
    -{{ingredient_amount[2]}} {{ingredient_unit[2]}} {{ingredient[2]}}
    -{{ingredient_amount[3]}} {{ingredient_unit[3]}} {{ingredient[3]}}

    [...]
    
    but obviously, this is less than ideal.

    What has been suggested to me (by someone who really knows databases
    and such) is that recfmt and the associated templates are missing
    looping constructs that would allow templated output of multiply
    occurring fields without resorting to external scripted kludges or
    using uniq..
    
    Any ideas on how I might address this, or how recfmt might be
    modified to handle it ?

I agree in that an iterative construction in recfmt would be very
useful.  Currently the contents of the template slots are just selection
expressions.  The expressions get evaluated and its returned value is
converted into a string, which is used to replace the slot in the
template.

I was thinking about adding support for "indented" slots, using the
following syntax:

     {{i| expression}}

expression would be evaluated and its value inserted in the position
occupied by the slot, as usual, but if the value has multiple lines then
they will be indented to the relative position of the slot regarding the
beginning of the first line.  For example:

/
| Description: {{i| Description}}
\

would get replaced by something like:

/
| Description: This is a description with
|              multiple lines indented at the
|              same place.
\

instead of

/
| Description: This is a description with
|multiple lines indented at the same
|place
\

We could use more flags to specify more options when it comes to expand
a template slot:

     {{isf| expression}}

where 's' and 'f' would be flags changing the slot expansion mechanism.
For example, 's' could command recfmt to 'strip' blanks from the
beginning and the end of the expression expansion.  In this way, we
would not need to alter the semantics of 'expression' in order to tailor
the slot expansion.

Regarding the iterative support, IMHO we have two options:

1. We add a loop construction to the selection expressions.  Something
   like:

      for i in 0..#ingredient
        "-" & ingredient_amount[1] & ingredient_unit[1] & ingredient[1]

   I don't like this solution, because i) this loop construction would
   not be very useful in selection expressions when it comes to select a
   record and ii) how to specify that we want to indent the list
   entries, for example?

2. We add support for looping template slots introducing variables.
   Something like:

   {{N=0..#ingredient|
     - {{i| ingredient_amount[$N] & ingredient_unit[$N] & ingredient[$N]}}
   }}

I would much prefer the second option.  More ideas?

-- 
Jose E. Marchesi    address@hidden
GNU Project         http://www.gnu.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]