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 # Base entities shared by all the nitdoc code
21 intrude import markdown
::wikilinks
23 # The model of a Nitdoc documentation
26 # Model used to select entities
29 # Mainmodule to resolve linearization
30 var mainmodule
: MModule
32 # ModelBuilder used to retrieve AST nodes
33 var modelbuilder
: ModelBuilder
35 # Catalog for building the homepage
38 # Model filters applied to the whole documentation
39 var filter
: ModelFilter
41 # Specific Markdown processor to use within Nitdoc
42 var md_processor
: MarkdownProcessor is lazy
do
43 var parser
= new CommandParser(model
, mainmodule
, modelbuilder
, catalog
)
44 var proc
= new CmdMarkdownProcessor(parser
)
45 proc
.decorator
= new CmdDecorator(model
)
49 # Specific Markdown processor to use within Nitdoc
50 var inline_processor
: MarkdownProcessor is lazy
do
51 var parser
= new CommandParser(model
, mainmodule
, modelbuilder
, catalog
)
52 var proc
= new CmdMarkdownProcessor(parser
)
53 proc
.decorator
= new CmdInlineDecorator(model
)
57 # Do not generate dot graphs
58 var no_dot
= false is writable
60 # Do not generate higlighted code
61 var no_code
= false is writable
63 # Url to code when `no_code` is true
64 var code_url
: nullable String = null is writable
67 var share_url
: nullable String = null is writable
70 var custom_brand
: nullable String = null is writable
72 # Custom homepage title
73 var custom_title
: nullable String = null is writable
76 var custom_footer
: nullable String = null is writable
78 # Custom homepage intro text
79 var custom_intro
: nullable String = null is writable
81 # Optional tracker url
82 var tracker_url
: nullable String = null is writable
84 # Optional tracker site id
85 var piwik_site_id
: nullable String = null is writable
87 # Used to sort sidebar elements by name.
88 var name_sorter
= new MEntityNameSorter
93 # A documentation page abstraction
97 var title
: String is writable
101 # Nitdoc pages are tabulated.
102 # If a page has only one tab, it is presented as a single page.
103 # With more than one tab, the HTML rendering process adds tab headers and
105 var tabs
: Array[DocTab] = [main_tab
] is lazy
109 # For most pages this tab is suffisent.
110 # Subclasses can add more tabs.
111 var main_tab
= new DocTab("main", "Main")
113 redef fun to_s
do return title
116 # The Nitdoc overview page that displays the nit packages catalog
121 # A DocPage documenting a MEntity
122 abstract class PageMEntity
126 new(mentity
: MEntity) do
127 if mentity
isa MPackage then
128 return new PageMPackage(mentity
)
129 else if mentity
isa MGroup then
130 return new PageMGroup(mentity
)
131 else if mentity
isa MModule then
132 return new PageMModule(mentity
)
133 else if mentity
isa MClass then
134 return new PageMClass(mentity
)
135 else if mentity
isa MProperty then
136 return new PageMProperty(mentity
)
138 print
"Not yet implemented: Page for {mentity.full_name} ({mentity.class_name})"
143 # Type of MEntity documented by this page
144 type MENTITY: MEntity
146 # MEntity documented by this page
149 # For mentities the main tab is the doc tab
150 redef var main_tab
= new DocTab("doc", "Doc", true, "book")
154 # Where the MEntity API (groups, modules, classes, props) is displayed
155 var api_tab
= new DocTab("api", "API", false, "list")
159 # Where the MEntity importation or inheritance is displayed
160 var dep_tab
= new DocTab("inh", "Dependencies", false, "object-align-vertical")
164 # Since all mentities does not have code, this tab in not in the `tabs` list
166 var code_tab
= new DocTab("code", "Code", false, "console")
170 # Since all mentities does not have a linearization, this tab in not in the
171 # `tabs` list by default.
172 var lin_tab
= new DocTab("lin", "Linearization", false, "arrow-down")
174 redef var tabs
= [main_tab
, api_tab
, dep_tab
] is lazy
175 redef var title
is lazy
do return mentity
.name
178 # A documentation page for a MPackage
182 redef type MENTITY: MPackage
183 redef var api_tab
= new DocTab("api", "Groups & Modules", false, "list")
186 # A documentation page about a MGroup
190 redef type MENTITY: MGroup
191 redef var api_tab
= new DocTab("api", "Subgroups & Modules", false, "list")
194 # A documentation page about a MModule
198 redef type MENTITY: MModule
199 redef var api_tab
= new DocTab("api", "Classes", false, "list")
200 redef var dep_tab
= new DocTab("inh", "Importation", false, "object-align-vertical")
201 redef var tabs
= [main_tab
, api_tab
, dep_tab
, code_tab
] is lazy
204 # A documentation page about a MClass
208 redef type MENTITY: MClass
209 redef var api_tab
= new DocTab("api", "All properties", false, "list")
210 redef var dep_tab
= new DocTab("inh", "Inheritance", false, "object-align-vertical")
211 redef var tabs
= [main_tab
, api_tab
, dep_tab
, lin_tab
] is lazy
214 # A documentation page about a MProperty
218 redef type MENTITY: MProperty
219 redef var tabs
= [main_tab
, lin_tab
] is lazy
222 # A page that lists the packages maintained and contributed by a person
227 # Person displayed in this page
230 redef var title
is lazy
do return person
.name
233 # A page that lists the packages related to a tab
238 # Tag displayed in this page
241 redef var title
is lazy
do return tag
247 # MEntities composing the breadcrumbs of a nitdoc page
248 fun nitdoc_breadcrumbs
: Array[MEntity] is abstract
252 redef var nitdoc_breadcrumbs
= [self: MEntity] is lazy
256 redef var nitdoc_breadcrumbs
is lazy
do
257 var parent
= self.parent
258 if parent
!= null then
259 return parent
.nitdoc_breadcrumbs
+ [self]
261 return mpackage
.nitdoc_breadcrumbs
266 redef var nitdoc_breadcrumbs
is lazy
do
267 var mgroup
= self.mgroup
268 if mgroup
!= null then
269 return mgroup
.nitdoc_breadcrumbs
+ [self]
276 redef var nitdoc_breadcrumbs
is lazy
do
277 return intro_mmodule
.nitdoc_breadcrumbs
+ [self]
281 redef class MClassDef
282 redef var nitdoc_breadcrumbs
is lazy
do
283 var res
= new Array[MEntity].from
(mmodule
.nitdoc_breadcrumbs
)
289 redef class MProperty
290 redef var nitdoc_breadcrumbs
is lazy
do
291 var res
= new Array[MEntity].from
(intro_mclassdef
.mclass
.nitdoc_breadcrumbs
)
298 redef var nitdoc_breadcrumbs
is lazy
do
299 var res
= new Array[MEntity].from
(mclassdef
.nitdoc_breadcrumbs
)
305 # Documentation base elements
307 # A documentation tabulated view
310 # Tab uniq id in the page
311 var id
: String is writable
314 var title
: String is writable
316 # Is this tab displayed by default?
317 var is_active
= false is optional
, writable
320 var icon
: nullable String = null is optional
, writable
323 var content
= new Array[StaticCard]
326 var sidebar
= new DocSidebar
328 # Tab metadata sidebar
329 var metadata
= new DocSidebar
332 fun is_empty
: Bool do return content
.is_empty
335 # A fictive tab used to display a link
338 autoinit
(id
, title
, icon
, url
)
340 # Link to open when the tab is clicked
344 # Nitdoc sidebar abstraction
347 # A sidebar contains `StaticCard`
348 var cards
= new Array[StaticCard]
350 # Is this sidebar empty?
351 fun is_empty
: Bool do return cards
.is_empty