]> mj.ucw.cz Git - temple.git/blob - test
Added tracking of dependencies from MJ's web
[temple.git] / test
1 @# A test program for Temple
2 @# starts with a couple of comments
3
4 @# The language is very simple -- everything except the "@" character
5 @# gets passed to the output verbatim:
6 Verbatim.
7
8 @# The "@" starts a control sequence. Arguments of control sequences
9 @# are either everything to the end of the current line (as in case
10 @# of the comment command you are looking at) balanced parenthesized
11 @# string.
12 @#
13
14 @# If we want to ignore and end of line character, just prefix it by "@":
15 This line @
16 won't be broken@
17 .
18
19 @# If you want to write the "@" character, just write it twice:
20 @@
21
22 @# You can embed any perl code in your text (use the "out" function to
23 @# write to the templater's output):
24 @[foreach $x (1..10) { out "$x "; } ]
25
26 @# Or if you use @{...}, then the value of the last expression executed
27 @# gets printed automatically:
28 @{"1+2+3 = " . (1+2+3)}
29
30 @# You can also interpolate perl variables in the T:: namespace by using @$variable:
31 I was run as @$0.
32
33 @# It is possible to call any perl functions
34 @# (any result other than undef will be printed automatically)
35 @# Use `out' to write to the output stream
36 @out("One", "Two", "Three\n")
37
38 @# Or do the same with parameters running up to the end of the line:
39 @out "Four", "Five", "Six\n"
40
41 @# Of course you can define your own functions (they live in the T:: namespace)
42 @[ sub quork($) { my ($arg) = @_; return "Thus quoth the Penguin: $arg"; } ]
43 @quork("404!")
44
45 @# There are also some conditionals (you can use any perl expressions):
46 @if 1
47 @if 0
48 one
49 @elif 0
50 two
51 @elif 1
52 three
53 @fi
54 @else
55 four
56 @fi
57
58 @# Or you can use the parenthesized form:
59 @if(0)ONE@else()TWO@fi()THREE
60
61 @# To include another file (and possibly change some variables), use:
62 @include("test2", "a" => "HOWDY", "b" => "HULLO", "c" => "AHOY")
63 @include "test2", "a" => "howdy", "b" => "hullo", "c" => "ahoy"
64
65 @# And to load a perl file:
66 @load "test3"
67
68 @# This one is tricky:
69 @out("z\n", <<EOF
70 a
71 b
72 c
73 EOF
74 )
75
76 @# The template engine can be run from any Perl code (including Perl embedded
77 @# in another template), e.g., in a templated CGI script.
78 @[
79         UCW::Temple::process_string('I still see I was run as @$0');
80 ]
81
82 @# Additionally, you can pass a hash of arguments to process_string() and use
83 @# the @(name) construct to expand them:
84 @[
85         UCW::Temple::process_string('@(count) upon a @(time) dreary...',
86                 { 'count' => 'Once', 'time' => 'midnight' } );
87 ]
88
89 @# We are done:
90 Finis.