src/doc/commands: move `render_code` to clients modules
[nit.git] / src / doc / static / static_base.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 # Base entities shared by all the nitdoc code
16 module static_base
17
18 import static_cards
19 import modelize
20
21 intrude import markdown::wikilinks
22
23 # The model of a Nitdoc documentation
24 class DocModel
25
26 # Model used to select entities
27 var model: Model
28
29 # Mainmodule to resolve linearization
30 var mainmodule: MModule
31
32 # ModelBuilder used to retrieve AST nodes
33 var modelbuilder: ModelBuilder
34
35 # Catalog for building the homepage
36 var catalog: Catalog
37
38 # Model filters applied to the whole documentation
39 var filter: ModelFilter
40
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)
46 return proc
47 end
48
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)
54 return proc
55 end
56
57 # Do not generate dot graphs
58 var no_dot = false is writable
59
60 # Do not generate higlighted code
61 var no_code = false is writable
62
63 # Url to code when `no_code` is true
64 var code_url: nullable String = null is writable
65
66 # Url to assets
67 var share_url: nullable String = null is writable
68
69 # Custom menu brand
70 var custom_brand: nullable String = null is writable
71
72 # Custom homepage title
73 var custom_title: nullable String = null is writable
74
75 # Custom page footer
76 var custom_footer: nullable String = null is writable
77
78 # Custom homepage intro text
79 var custom_intro: nullable String = null is writable
80
81 # Optional tracker url
82 var tracker_url: nullable String = null is writable
83
84 # Optional tracker site id
85 var piwik_site_id: nullable String = null is writable
86
87 # Used to sort sidebar elements by name.
88 var name_sorter = new MEntityNameSorter
89 end
90
91 # Documentation pages
92
93 # A documentation page abstraction
94 class DocPage
95
96 # Title of this page
97 var title: String is writable
98
99 # Page tab panels
100 #
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
104 # links.
105 var tabs: Array[DocTab] = [main_tab] is lazy
106
107 # The page main tab
108 #
109 # For most pages this tab is suffisent.
110 # Subclasses can add more tabs.
111 var main_tab = new DocTab("main", "Main")
112
113 redef fun to_s do return title
114 end
115
116 # The Nitdoc overview page that displays the nit packages catalog
117 class PageHome
118 super DocPage
119 end
120
121 # A DocPage documenting a MEntity
122 abstract class PageMEntity
123 super DocPage
124 autoinit mentity
125
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)
137 else
138 print "Not yet implemented: Page for {mentity.full_name} ({mentity.class_name})"
139 abort
140 end
141 end
142
143 # Type of MEntity documented by this page
144 type MENTITY: MEntity
145
146 # MEntity documented by this page
147 var mentity: MENTITY
148
149 # For mentities the main tab is the doc tab
150 redef var main_tab = new DocTab("doc", "Doc", true, "book")
151
152 # API tab
153 #
154 # Where the MEntity API (groups, modules, classes, props) is displayed
155 var api_tab = new DocTab("api", "API", false, "list")
156
157 # Dependencies tab
158 #
159 # Where the MEntity importation or inheritance is displayed
160 var dep_tab = new DocTab("inh", "Dependencies", false, "object-align-vertical")
161
162 # Code tab
163 #
164 # Since all mentities does not have code, this tab in not in the `tabs` list
165 # by default.
166 var code_tab = new DocTab("code", "Code", false, "console")
167
168 # Lienarization tab
169 #
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")
173
174 redef var tabs = [main_tab, api_tab, dep_tab] is lazy
175 redef var title is lazy do return mentity.name
176 end
177
178 # A documentation page for a MPackage
179 class PageMPackage
180 super PageMEntity
181
182 redef type MENTITY: MPackage
183 redef var api_tab = new DocTab("api", "Groups & Modules", false, "list")
184 end
185
186 # A documentation page about a MGroup
187 class PageMGroup
188 super PageMEntity
189
190 redef type MENTITY: MGroup
191 redef var api_tab = new DocTab("api", "Subgroups & Modules", false, "list")
192 end
193
194 # A documentation page about a MModule
195 class PageMModule
196 super PageMEntity
197
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
202 end
203
204 # A documentation page about a MClass
205 class PageMClass
206 super PageMEntity
207
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
212 end
213
214 # A documentation page about a MProperty
215 class PageMProperty
216 super PageMEntity
217
218 redef type MENTITY: MProperty
219 redef var tabs = [main_tab, lin_tab] is lazy
220 end
221
222 # A page that lists the packages maintained and contributed by a person
223 class PagePerson
224 super DocPage
225 autoinit person
226
227 # Person displayed in this page
228 var person: Person
229
230 redef var title is lazy do return person.name
231 end
232
233 # A page that lists the packages related to a tab
234 class PageTag
235 super DocPage
236 autoinit tag
237
238 # Tag displayed in this page
239 var tag: String
240
241 redef var title is lazy do return tag
242 end
243
244 # Breadcrumbs
245
246 redef class MEntity
247 # MEntities composing the breadcrumbs of a nitdoc page
248 fun nitdoc_breadcrumbs: Array[MEntity] is abstract
249 end
250
251 redef class MPackage
252 redef var nitdoc_breadcrumbs = [self: MEntity] is lazy
253 end
254
255 redef class MGroup
256 redef var nitdoc_breadcrumbs is lazy do
257 var parent = self.parent
258 if parent != null then
259 return parent.nitdoc_breadcrumbs + [self]
260 end
261 return mpackage.nitdoc_breadcrumbs
262 end
263 end
264
265 redef class MModule
266 redef var nitdoc_breadcrumbs is lazy do
267 var mgroup = self.mgroup
268 if mgroup != null then
269 return mgroup.nitdoc_breadcrumbs + [self]
270 end
271 return [self]
272 end
273 end
274
275 redef class MClass
276 redef var nitdoc_breadcrumbs is lazy do
277 return intro_mmodule.nitdoc_breadcrumbs + [self]
278 end
279 end
280
281 redef class MClassDef
282 redef var nitdoc_breadcrumbs is lazy do
283 var res = new Array[MEntity].from(mmodule.nitdoc_breadcrumbs)
284 res.add self
285 return res
286 end
287 end
288
289 redef class MProperty
290 redef var nitdoc_breadcrumbs is lazy do
291 var res = new Array[MEntity].from(intro_mclassdef.mclass.nitdoc_breadcrumbs)
292 res.add self
293 return res
294 end
295 end
296
297 redef class MPropDef
298 redef var nitdoc_breadcrumbs is lazy do
299 var res = new Array[MEntity].from(mclassdef.nitdoc_breadcrumbs)
300 res.add self
301 return res
302 end
303 end
304
305 # Documentation base elements
306
307 # A documentation tabulated view
308 class DocTab
309
310 # Tab uniq id in the page
311 var id: String is writable
312
313 # Table title
314 var title: String is writable
315
316 # Is this tab displayed by default?
317 var is_active = false is optional, writable
318
319 # Tab header icon
320 var icon: nullable String = null is optional, writable
321
322 # Tab content
323 var content = new Array[StaticCard]
324
325 # Tab sidebar
326 var sidebar = new DocSidebar
327
328 # Tab metadata sidebar
329 var metadata = new DocSidebar
330
331 # Is this tab empty?
332 fun is_empty: Bool do return content.is_empty
333 end
334
335 # A fictive tab used to display a link
336 class DocTabLink
337 super DocTab
338 autoinit(id, title, icon, url)
339
340 # Link to open when the tab is clicked
341 var url: String
342 end
343
344 # Nitdoc sidebar abstraction
345 class DocSidebar
346
347 # A sidebar contains `StaticCard`
348 var cards = new Array[StaticCard]
349
350 # Is this sidebar empty?
351 fun is_empty: Bool do return cards.is_empty
352 end