1 # This file is part of NIT ( http://www.nitlanguage.org ).
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 # Introduces templates that compose the documentation in console rendering.
16 module console_templates
19 import doc_phases
::doc_structure
21 # Renders the page displayable as ASCII.
25 # Renders the footer and content.
26 private fun render_content
do add root
28 # Renders the whole page
29 redef fun rendering
do render_content
32 redef class DocComposite
35 # Title that can be decorated for console display.
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
40 # Subtitle that can be decorated for console display.
42 # Set as `null` if you don't want to display a subtitle.
43 var cs_subtitle
: nullable String is noinit
, writable
45 # Renders the element `cs_title` and `cs_subtitle` as any.
47 if cs_title
!= null then
48 add
"{"#" * depth} ".blue
.bold
49 addn cs_title
.blue
.bold
51 if cs_subtitle
!= null then
52 addn cs_subtitle
.gray
.bold
54 if cs_title
!= null or cs_subtitle
!= null then addn
""
57 # Renders the element body.
58 fun render_body
do for child
in children
do add child
.write_to_string
60 redef fun rendering
do
67 redef fun rendering
do render_body
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
74 redef fun rendering
do
75 var mentity
= self.mentity
76 if mentity
isa MGroup and mentity
.mpackage
.root
== mentity
then
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
89 redef class IntroArticle
90 redef fun render_body
do
91 addn
" {mentity.cs_declaration.bold}"
92 addn
" {mentity.cs_location.gray.bold}"
94 var comment
= mentity
.cs_comment
95 if comment
!= null then
103 redef class ConcernsArticle
104 redef fun render_body
do
105 var w
= new StringWriter
111 redef class DefinitionArticle
112 # If short, displays only synopsyses.
113 var is_short
= false is writable
115 redef fun render_body
do
116 addn
" {mentity.cs_visibility_color(mentity.cs_declaration).bold}"
117 addn
" {mentity.cs_location.gray.bold}"
121 comment
= mentity
.cs_short_comment
123 comment
= mentity
.cs_comment
125 if comment
!= null then
133 redef class MEntitiesListArticle
134 redef fun render_body
do
135 for mentity
in mentities
do
136 addn mentity
.cs_short_list_item