Merge: doc: fixed some typos and other misc. corrections
[nit.git] / lib / template / examples / tmpl_composer.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 module tmpl_composer is example
16
17 import template
18
19 ### Here, definition of the specific templates
20
21 # The root template for composers
22 class TmplComposers
23 super Template
24
25 # Short list of composers
26 var composers = new Array[TmplComposer]
27
28 # Detailled list of composers
29 var composer_details = new Array[TmplComposerDetail]
30
31 # Add a composer in both lists
32 fun add_composer(firstname, lastname: String, birth, death: Int)
33 do
34 composers.add(new TmplComposer(lastname))
35 composer_details.add(new TmplComposerDetail(firstname, lastname, birth, death))
36 end
37
38 redef fun rendering do
39 add """
40 COMPOSERS
41 =========
42 """
43 add_all composers
44 add """
45
46 DETAILS
47 =======
48 """
49 add_all composer_details
50 end
51 end
52
53 # A composer in the short list of composers
54 class TmplComposer
55 super Template
56
57 # Short name
58 var name: String
59
60 redef fun rendering do add "- {name}\n"
61 end
62
63 # A composer in the detailled list of composers
64 class TmplComposerDetail
65 super Template
66
67 var firstname: String
68 var lastname: String
69 var birth: Int
70 var death: Int
71
72 redef fun rendering do add """
73
74 COMPOSER: {{{firstname}}} {{{lastname}}}
75 BIRTH...: {{{birth}}}
76 DEATH...: {{{death}}}
77 """
78
79 end
80
81 ### Here a simple usage of the templates
82
83 var f = new TmplComposers
84 f.add_composer("Johann Sebastian", "Bach", 1685, 1750)
85 f.add_composer("George Frideric", "Handel", 1685, 1759)
86 f.add_composer("Wolfgang Amadeus", "Mozart", 1756, 1791)
87 f.write_to(stdout)