Merge: Byte data type
[nit.git] / src / doc / console_templates / console_templates.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 # Introduces templates that compose the documentation in console rendering.
16 module console_templates
17
18 import console_model
19 import doc_phases::doc_structure
20
21 # Renders the page displayable as ASCII.
22 redef class DocPage
23 super Template
24
25 # Renders the footer and content.
26 private fun render_content do add root
27
28 # Renders the whole page
29 redef fun rendering do render_content
30 end
31
32 redef class DocComposite
33 super Template
34
35 # Title that can be decorated for console display.
36 #
37 # Set as `null` if you don't want to display a title.
38 var cs_title: nullable String is noinit, writable
39
40 # Subtitle that can be decorated for console display.
41 #
42 # Set as `null` if you don't want to display a subtitle.
43 var cs_subtitle: nullable String is noinit, writable
44
45 # Renders the element `cs_title` and `cs_subtitle` as any.
46 fun render_title do
47 if cs_title != null then
48 add "{"#" * depth} ".blue.bold
49 addn cs_title.blue.bold
50 end
51 if cs_subtitle != null then
52 addn cs_subtitle.gray.bold
53 end
54 if cs_title != null or cs_subtitle != null then addn ""
55 end
56
57 # Renders the element body.
58 fun render_body do for child in children do add child.write_to_string
59
60 redef fun rendering do
61 render_title
62 render_body
63 end
64 end
65
66 redef class DocRoot
67 redef fun rendering do render_body
68 end
69
70 redef class ConcernSection
71 redef var cs_title is lazy do return "in {mentity.cs_namespace}"
72 redef var cs_subtitle is lazy do return mentity.cs_declaration
73
74 redef fun rendering do
75 var mentity = self.mentity
76 if mentity isa MGroup and mentity.mproject.root == mentity then
77 render_body
78 else
79 super
80 end
81 end
82 end
83
84 redef class MEntityComposite
85 redef var cs_title is lazy do return mentity.cs_name
86 redef var cs_subtitle is lazy do return mentity.cs_namespace
87 end
88
89 redef class IntroArticle
90 redef var cs_title = null
91 redef var cs_subtitle = null
92
93 redef fun render_body do
94 addn " {mentity.cs_declaration.bold}"
95 addn " {mentity.cs_location.gray.bold}"
96 addn ""
97 var comment = mentity.cs_comment
98 if comment != null then
99 add comment
100 end
101 addn ""
102 super
103 end
104 end
105
106 redef class ConcernsArticle
107 redef var cs_title = "Concerns"
108 redef var cs_subtitle = null
109
110 redef fun render_body do
111 var w = new StringWriter
112 concerns.write_to(w)
113 addn w.to_s
114 end
115 end
116
117 redef class DefinitionArticle
118 # If short, displays only synopsyses.
119 var is_short = false is writable
120
121 redef fun render_body do
122 addn " {mentity.cs_visibility_color(mentity.cs_declaration).bold}"
123 addn " {mentity.cs_location.gray.bold}"
124 addn ""
125 var comment
126 if is_short then
127 comment = mentity.cs_short_comment
128 else
129 comment = mentity.cs_comment
130 end
131 if comment != null then
132 add comment
133 end
134 addn ""
135 super
136 end
137 end