Changeset 45af145fba9488de1cc9d7106aaa6061d101fe2b for doc
- Timestamp:
- 01/02/10 18:28:55 (2 years ago)
- Children:
- cc0a570a9262613f7046938be649f27646987cb8
- Parents:
- 71574e315e6b251c23a07e6e591cec8ddbc01261
- git-committer:
- Antti-Juhani Kaijanaho <antti-juhani@…> (01/02/10 18:28:55)
- Files:
-
- 1 modified
-
doc/alue.texinfo (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/alue.texinfo
r71574e3 r45af145 264 264 * Conditionals:: 265 265 * Definitions:: 266 * File inclusion:: 266 267 @end menu 267 268 … … 316 317 directives, a template block is saved (uninterpreted) for late use. 317 318 319 The following example demonstrates the interplay between literal 320 material, 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 328 Note that there is no whitespace between curly brackets and the dollar 329 signs. Since the curly brackets are in literal material, any 330 surrounding whitespace is significant, and thus writing 331 @c 332 @samp{$ @{} 333 @c 334 would break the syntax. 335 336 In 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 345 as well as all the line breaks and all the indenting whitespace. 346 The 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 356 Technically, the dollar signs and the curly brackets ought to be 357 categorized as well, but that would be a rather pointless exercise in 358 pedantry.@footnote{The dollar signs belong in whatever material that 359 precedes them, and the curly brackets are literal. ---Yes, I'm a 360 pedant. Why do you ask?} 361 318 362 @node Values, Expressions, Lexical considerations, The template language 319 363 @subsection Values 320 364 321 Alue provides toa template @dfn{values} in named @dfn{attributes}. The365 Alue provides a template @dfn{values} in named @dfn{attributes}. The 322 366 attributes that are defined, and the structure of their values, depends 323 367 on what document the template is producing. The following kinds of … … 340 384 Also, a @dfn{closure} is a value (whose textual representation is 341 385 empty), but it arises only from a definition in the template itself. 386 387 For examples of the various types, please refer to the sections 388 describing individual templates. 342 389 343 390 @node Expressions, Iterations, Values, The template language … … 348 395 @dfn{expressions}, and each of them results in a @dfn{value}. When an 349 396 expression occurs alone, a textual representation of its value is copied 350 to the output. The following kinds of expressions exist. 397 to the output. 398 399 The following kinds of expressions exist. 351 400 @itemize @bullet 352 401 @item … … 372 421 @end itemize 373 422 423 For example, to refer to the display name of the currently logged in 424 user, one would write (in any template) @samp{authn.user.display-name}. 425 Here, @samp{authn} is an attribute reference, while @samp{authn.user} 426 and @samp{auth.user.display-name} are subattribute references. The 427 expression should be surrounded by dollar signs if it occurs by itself 428 among literal material. 429 430 For an example of an invocation, @xref{Definitions}. 431 374 432 @node Iterations, Conditionals, Expressions, The template language 375 433 @subsection Iterations … … 388 446 a template block (the @dfn{body}). 389 447 @end itemize 390 Note that the template block's opening curly bracket must come391 immediately after the sequence expression, save for only the dollar392 sign, if one is needed to switch from directive to literal material.393 Specifically, no whitespace is allowed between the dollar sign (or, if394 absent, the end of the expression) and the opening curly bracket.395 448 396 449 If the sequence has a sequential value, the behaviour of an iteration … … 399 452 Otherwise, the iteration directive is ignored. 400 453 454 In the index template, one would produce a listing of all groups with 455 something like this: 456 @example 457 <ul> 458 $for group in groups$@{ 459 <li>$group.name$ – $group.description$</li> 460 @} 461 </ul> 462 @end example 463 Note well: there is no (and should never be any) whitespace between the 464 dollar sign and the opening curly bracket. 465 401 466 @node Conditionals, Definitions, Iterations, The template language 402 467 @subsection Conditionals … … 423 488 @end itemize 424 489 @end itemize 425 Note that each template block's opening curly bracket must come426 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 the429 opening curly bracket.430 490 431 491 The behaviour of a conditional directive is determined by the value of … … 440 500 @end itemize 441 501 442 @node Definitions, , Conditionals, The template language 502 The template fragment 503 @example 504 $if authn.user$@{ 505 Welcome, $authn.user.display-name$! 506 @}$else$@{ 507 Please log in. 508 @} 509 @end example 510 will copy @samp{Welcome, Antti-Juhani Kaijanaho!} to the output if I am 511 logged in, and @samp{Please log in.} if nobody is logged in. 512 513 Note well: there is no (and should never be any) whitespace between the 514 dollar sign and the curly bracket. 515 516 @node Definitions, File inclusion, Conditionals, The template language 443 517 @subsection Definitions 444 518 445 A @dfn{ conditionaldirective} consists of519 A @dfn{definition directive} consists of 446 520 @itemize @bullet 447 521 @item … … 458 532 a template block (the @dfn{body}). 459 533 @end itemize 460 Note that the template block's opening curly bracket must come461 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 the464 opening curly bracket.465 534 466 535 A definition makes the function name be defined for the remainder of the … … 479 548 Definitions may be self-recursive; mutual recursion is not possible. 480 549 550 For example, one might define a function to produce one item in a list 551 of messages, including a sublist of the message's follow-ups, as 552 follows: 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 481 568 Note that the body of the definition sees the environment of the 482 569 definition, not the environment of the invocation. Thus, definitions 483 follow the lexical (aka static) scoping discipline. 570 follow the lexical (aka static) scoping discipline. In the example, 571 this means that a recursive invocation of @samp{show_article} never has 572 direct access to its invoker's @samp{art}. 573 574 Note well: there is no (and should never be any) whitespace between the 575 dollar sign and the curly bracket. 576 577 @node File inclusion, , Definitions, The template language 578 @subsection File inclusion 579 580 A @dfn{file inclusion directive} consists of 581 @itemize @bullet 582 @item 583 the reserved word @code{include}, followed by 584 @item 585 a sequence consisting of ASCII letters (in either case), ASCII decimal 586 digits, the dash, the underscore and the period (the @dfn{file name}). 587 @end itemize 588 589 The effect of a file inclusion directive is to read the named file and 590 process it as if it had occurred immediately after the inclusion 591 directive, with one difference: the file will be assumed to start with 592 literal material. Once the included file has been processed, the 593 including file will continue to be processed as directive material. 594 595 File inclusion is a powerful method for structuring templates. It is, 596 for example, useful to write a single file containing the HTML 597 preliminaries, and include it in every template. The included file can 598 be parametrized by defining functions in the including file. For 599 example: 600 @example 601 $def title()$@{$group.name$ threads@} 602 $include prelim.inc$ 603 @end example 604 The @file{prelim.inc} file can access the defined title by invoking the 605 defined 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 484 618 485 619 @node GNU General Public License, , Templates, Top
