Show
Ignore:
Timestamp:
01/02/10 18:28:55 (2 years ago)
Author:
Antti-Juhani Kaijanaho <antti-juhani@…>
Children:
cc0a570a9262613f7046938be649f27646987cb8
Parents:
71574e315e6b251c23a07e6e591cec8ddbc01261
git-committer:
Antti-Juhani Kaijanaho <antti-juhani@…> (01/02/10 18:28:55)
Message:

Work on the manual.

Signed-off-by: Antti-Juhani Kaijanaho <antti-juhani@…>

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • doc/alue.texinfo

    r71574e3 r45af145  
    264264* Conditionals::                 
    265265* Definitions::                  
     266* File inclusion::               
    266267@end menu 
    267268 
     
    316317directives, a template block is saved (uninterpreted) for late use. 
    317318 
     319The following example demonstrates the interplay between literal 
     320material, directive material and template blocks: 
     321@example 
     322$if user.logged_in$@{ 
     323  Welcome, $user.name$! 
     324@}$else$@{ 
     325  Please log in. 
     326@} 
     327@end example 
     328Note that there is no whitespace between curly brackets and the dollar 
     329signs.  Since the curly brackets are in literal material, any 
     330surrounding whitespace is significant, and thus writing 
     331@c 
     332@samp{$ @{} 
     333@c 
     334would break the syntax. 
     335 
     336In the example, the following material is literal: 
     337@itemize @bullet 
     338@item 
     339@samp{Welcome, } 
     340@item 
     341@samp{!} 
     342@item 
     343@samp{Please log in.} 
     344@end itemize 
     345as well as all the line breaks and all the indenting whitespace. 
     346The following material is directive: 
     347@itemize @bullet 
     348@item 
     349@samp{if user.logged_in} 
     350@item 
     351@samp{user.name} 
     352@item 
     353@samp{else} 
     354@end itemize 
     355 
     356Technically, the dollar signs and the curly brackets ought to be 
     357categorized as well, but that would be a rather pointless exercise in 
     358pedantry.@footnote{The dollar signs belong in whatever material that 
     359precedes them, and the curly brackets are literal.  ---Yes, I'm a 
     360pedant. Why do you ask?} 
     361 
    318362@node Values, Expressions, Lexical considerations, The template language 
    319363@subsection Values 
    320364 
    321 Alue provides to a template @dfn{values} in named @dfn{attributes}.  The 
     365Alue provides a template @dfn{values} in named @dfn{attributes}.  The 
    322366attributes that are defined, and the structure of their values, depends 
    323367on what document the template is producing.  The following kinds of 
     
    340384Also, a @dfn{closure} is a value (whose textual representation is 
    341385empty), but it arises only from a definition in the template itself. 
     386 
     387For examples of the various types, please refer to the sections 
     388describing individual templates. 
    342389 
    343390@node Expressions, Iterations, Values, The template language 
     
    348395@dfn{expressions}, and each of them results in a @dfn{value}.  When an 
    349396expression occurs alone, a textual representation of its value is copied 
    350 to the output.  The following kinds of expressions exist. 
     397to the output. 
     398 
     399The following kinds of expressions exist. 
    351400@itemize @bullet 
    352401@item 
     
    372421@end itemize 
    373422 
     423For example, to refer to the display name of the currently logged in 
     424user, one would write (in any template) @samp{authn.user.display-name}. 
     425Here, @samp{authn} is an attribute reference, while @samp{authn.user} 
     426and @samp{auth.user.display-name} are subattribute references. The 
     427expression should be surrounded by dollar signs if it occurs by itself 
     428among literal material. 
     429 
     430For an example of an invocation, @xref{Definitions}. 
     431 
    374432@node Iterations, Conditionals, Expressions, The template language 
    375433@subsection Iterations 
     
    388446a template block (the @dfn{body}). 
    389447@end itemize 
    390 Note that the template block's opening curly bracket must come 
    391 immediately after the sequence expression, save for only the dollar 
    392 sign, if one is needed to switch from directive to literal material. 
    393 Specifically, no whitespace is allowed between the dollar sign (or, if 
    394 absent, the end of the expression) and the opening curly bracket. 
    395448 
    396449If the sequence has a sequential value, the behaviour of an iteration 
     
    399452Otherwise, the iteration directive is ignored. 
    400453 
     454In the index template, one would produce a listing of all groups with 
     455something like this: 
     456@example 
     457<ul> 
     458$for group in groups$@{ 
     459  <li>$group.name$ &ndash; $group.description$</li> 
     460@} 
     461</ul> 
     462@end example 
     463Note well: there is no (and should never be any) whitespace between the 
     464dollar sign and the opening curly bracket. 
     465 
    401466@node Conditionals, Definitions, Iterations, The template language 
    402467@subsection Conditionals 
     
    423488@end itemize 
    424489@end itemize 
    425 Note that each template block's opening curly bracket must come 
    426 immediately after the preceding material, save for only the dollar sign, 
    427 if one is needed to switch from directive to literal material. 
    428 Specifically, no whitespace is allowed between any dollar sign and the 
    429 opening curly bracket. 
    430490 
    431491The behaviour of a conditional directive is determined by the value of 
     
    440500@end itemize 
    441501 
    442 @node Definitions,  , Conditionals, The template language 
     502The template fragment 
     503@example 
     504$if authn.user$@{ 
     505  Welcome, $authn.user.display-name$! 
     506@}$else$@{ 
     507  Please log in. 
     508@} 
     509@end example 
     510will copy @samp{Welcome, Antti-Juhani Kaijanaho!} to the output if I am 
     511logged in, and @samp{Please log in.} if nobody is logged in. 
     512 
     513Note well: there is no (and should never be any) whitespace between the 
     514dollar sign and the curly bracket. 
     515 
     516@node Definitions, File inclusion, Conditionals, The template language 
    443517@subsection Definitions 
    444518 
    445 A @dfn{conditional directive} consists of 
     519A @dfn{definition directive} consists of 
    446520@itemize @bullet 
    447521@item 
     
    458532a template block (the @dfn{body}). 
    459533@end itemize 
    460 Note that the template block's opening curly bracket must come 
    461 immediately after the preceding material, save for only the dollar sign, 
    462 if one is needed to switch from directive to literal material. 
    463 Specifically, no whitespace is allowed between any dollar sign and the 
    464 opening curly bracket. 
    465534 
    466535A definition makes the function name be defined for the remainder of the 
     
    479548Definitions may be self-recursive; mutual recursion is not possible. 
    480549 
     550For example, one might define a function to produce one item in a list 
     551of messages, including a sublist of the message's follow-ups, as 
     552follows: 
     553@example 
     554$def show_article(article)$@{ 
     555  <li> 
     556    $article.subject$ by $article.from$ 
     557    $if article.followups$@{ 
     558      <ul> 
     559        $for art in article.followups$@{ 
     560          $show_article(art)$ 
     561        @} 
     562      </ul> 
     563    @} 
     564  </li> 
     565@} 
     566@end example 
     567 
    481568Note that the body of the definition sees the environment of the 
    482569definition, not the environment of the invocation.  Thus, definitions 
    483 follow the lexical (aka static) scoping discipline. 
     570follow the lexical (aka static) scoping discipline.  In the example, 
     571this means that a recursive invocation of @samp{show_article} never has 
     572direct access to its invoker's @samp{art}. 
     573 
     574Note well: there is no (and should never be any) whitespace between the 
     575dollar sign and the curly bracket. 
     576 
     577@node File inclusion,  , Definitions, The template language 
     578@subsection File inclusion 
     579 
     580A @dfn{file inclusion directive} consists of 
     581@itemize @bullet 
     582@item 
     583the reserved word @code{include}, followed by 
     584@item 
     585a sequence consisting of ASCII letters (in either case), ASCII decimal 
     586digits, the dash, the underscore and the period (the @dfn{file name}). 
     587@end itemize 
     588 
     589The effect of a file inclusion directive is to read the named file and 
     590process it as if it had occurred immediately after the inclusion 
     591directive, with one difference: the file will be assumed to start with 
     592literal material.  Once the included file has been processed, the 
     593including file will continue to be processed as directive material. 
     594 
     595File inclusion is a powerful method for structuring templates.  It is, 
     596for example, useful to write a single file containing the HTML 
     597preliminaries, and include it in every template.  The included file can 
     598be parametrized by defining functions in the including file.  For 
     599example: 
     600@example 
     601$def title()$@{$group.name$ threads@} 
     602$include prelim.inc$ 
     603@end example 
     604The @file{prelim.inc} file can access the defined title by invoking the 
     605defined function: 
     606@example 
     607<?xml version="1.0" encoding="UTF-8"?> 
     608<!DOCTYPE html  
     609     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
     610    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
     611<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
     612  <head> 
     613    <title>$title()$</title> 
     614  </head> 
     615  <body> 
     616  <h1>$title()$</h1> 
     617@end example 
    484618 
    485619@node GNU General Public License,  , Templates, Top