File: sample.lua

package info (click to toggle)
lua-cosmo 13.01.30-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 248 kB
  • sloc: makefile: 33; sh: 28
file content (75 lines) | stat: -rw-r--r-- 1,824 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
local cosmo = require "cosmo"

template = [==[ 
<h1>$list_name</h1>
<ul>
 $do_items[=[<li>$item</li>]=]
</ul>
]==]

print(cosmo.fill(template,
           { list_name = "My List",
             do_items  = function()
                for i=1,5 do
                   cosmo.yield { item = i }
                end
             end
           }
          ))

print(cosmo.fill(template,
           { list_name = "My List",
             do_items  = function()
                for i=1,5 do
                   cosmo.yield { item = i }
                end
             end
           }
          ))

warn_about_alligators = true

print(cosmo.fill ( "-- $if_warning[=[<b>Beware of $warning!<b>]=] --",
             { if_warning = cosmo.cond(warn_about_alligators,
                                       { warning = "ALLIGATORS" }
                                      )
             }
           ))

warn_about_alligators = false

print(cosmo.fill ( "-- $if_warning[=[<b>Beware of $warning!<b>]=] --",
             { if_warning = cosmo.cond(warn_about_alligators,
                                       { warning = "ALLIGATORS" }
                                      )
             }
           ))

template = [==[ 
<h1>$list_name</h1>
<ul>
$do_items{ $foo }[=[<li>$item</li>]=]
</ul>
]==]

print(cosmo.fill(template,
           { list_name = "My List",
	     foo = "Hello ",
             do_items  = function(args)
                for i=1,5 do
                   cosmo.yield { item = args[1] .. i }
                end
             end
           }
          ))

print(cosmo.fill(template,
           { list_name = "My List",
	     foo = "Hello ",
             do_items  = function(args)
                for i=1,5 do
                   cosmo.yield { item = args[1] .. i }
                end
             end
           }
          ))