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