src: mass rename project->package
[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 writable, lazy do return title
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.mpackage.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 fun render_body do
91 addn " {mentity.cs_declaration.bold}"
92 addn " {mentity.cs_location.gray.bold}"
93 addn ""
94 var comment = mentity.cs_comment
95 if comment != null then
96 add comment
97 end
98 addn ""
99 super
100 end
101 end
102
103 redef class ConcernsArticle
104 redef fun render_body do
105 var w = new StringWriter
106 concerns.write_to(w)
107 addn w.to_s
108 end
109 end
110
111 redef class DefinitionArticle
112 # If short, displays only synopsyses.
113 var is_short = false is writable
114
115 redef fun render_body do
116 addn " {mentity.cs_visibility_color(mentity.cs_declaration).bold}"
117 addn " {mentity.cs_location.gray.bold}"
118 addn ""
119 var comment
120 if is_short then
121 comment = mentity.cs_short_comment
122 else
123 comment = mentity.cs_comment
124 end
125 if comment != null then
126 add comment
127 end
128 addn ""
129 super
130 end
131 end
132
133 redef class MEntitiesListArticle
134 redef fun render_body do
135 for mentity in mentities do
136 addn mentity.cs_short_list_item
137 end
138 end
139 end