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 # Documentation generator for the nit language.
16 # Generate API documentation in HTML format from nit source code.
20 import modelize_property
24 # The NitdocContext contains all the knowledge used for doc generation
27 private var toolcontext
= new ToolContext
28 private var mbuilder
: ModelBuilder
29 private var mainmodule
: MModule
30 private var output_dir
: String
31 private var min_visibility
: MVisibility
33 private var opt_dir
= new OptionString("output directory", "-d", "--dir")
34 private var opt_source
= new OptionString("link for source (%f for filename, %l for first line, %L for last line)", "--source")
35 private var opt_sharedir
= new OptionString("directory containing nitdoc assets", "--sharedir")
36 private var opt_shareurl
= new OptionString("use shareurl instead of copy shared files", "--shareurl")
37 private var opt_nodot
= new OptionBool("do not generate graphes with graphviz", "--no-dot")
38 private var opt_private
= new OptionBool("also generate private API", "--private")
40 private var opt_custom_title
= new OptionString("custom title for homepage", "--custom-title")
41 private var opt_custom_menu
= new OptionString("custom items added in top menu (each item must be enclosed in 'li' tags)", "--custom-menu-items")
42 private var opt_custom_intro
= new OptionString("custom intro text for homepage", "--custom-overview-text")
43 private var opt_custom_footer
= new OptionString("custom footer text", "--custom-footer-text")
45 private var opt_github_upstream
= new OptionString("Git branch where edited commits will be pulled into (ex: user:repo:branch)", "--github-upstream")
46 private var opt_github_base_sha1
= new OptionString("Git sha1 of base commit used to create pull request", "--github-base-sha1")
47 private var opt_github_gitdir
= new OptionString("Git working directory used to resolve path name (ex: /home/me/myproject/)", "--github-gitdir")
49 private var opt_piwik_tracker
= new OptionString("Piwik tracker URL (ex: nitlanguage.org/piwik/)", "--piwik-tracker")
50 private var opt_piwik_site_id
= new OptionString("Piwik site ID", "--piwik-site-id")
53 var opts
= toolcontext
.option_context
54 opts
.add_option
(opt_dir
, opt_source
, opt_sharedir
, opt_shareurl
, opt_nodot
, opt_private
)
55 opts
.add_option
(opt_custom_title
, opt_custom_footer
, opt_custom_intro
, opt_custom_menu
)
56 opts
.add_option
(opt_github_upstream
, opt_github_base_sha1
, opt_github_gitdir
)
57 opts
.add_option
(opt_piwik_tracker
, opt_piwik_site_id
)
59 var tpl
= new Template
60 tpl
.add
"Usage: nitdoc [OPTION]... <file.nit>...\n"
61 tpl
.add
"Generates HTML pages of API documentation from Nit source files."
62 toolcontext
.tooldescription
= tpl
.write_to_string
63 toolcontext
.process_options
(args
)
66 self.parse
(toolcontext
.option_context
.rest
)
69 private fun process_options
do
70 if opt_private
.value
then
71 min_visibility
= none_visibility
73 min_visibility
= protected_visibility
75 var gh_upstream
= opt_github_upstream
.value
76 var gh_base_sha
= opt_github_base_sha1
.value
77 var gh_gitdir
= opt_github_gitdir
.value
78 if not gh_upstream
== null or not gh_base_sha
== null or not gh_gitdir
== null then
79 if gh_upstream
== null or gh_base_sha
== null or gh_gitdir
== null then
80 print
"Error: Options {opt_github_upstream.names.first}, {opt_github_base_sha1.names.first} and {opt_github_gitdir.names.first} are required to enable the GitHub plugin"
86 private fun parse
(arguments
: Array[String]) do
88 mbuilder
= new ModelBuilder(model
, toolcontext
)
89 var mmodules
= mbuilder
.parse
(arguments
)
90 if mmodules
.is_empty
then return
92 if mmodules
.length
== 1 then
93 mainmodule
= mmodules
.first
95 mainmodule
= new MModule(model
, null, "<main>", new Location(null, 0, 0, 0, 0))
96 mainmodule
.set_imported_mmodules
(mmodules
)
100 private fun generate_nitdoc
do
109 private fun init_output_dir
do
110 # location output dir
111 var output_dir
= opt_dir
.value
112 if output_dir
== null then
115 self.output_dir
= output_dir
116 # create destination dir if it's necessary
117 if not output_dir
.file_exists
then output_dir
.mkdir
119 var sharedir
= opt_sharedir
.value
120 if sharedir
== null then
121 var dir
= toolcontext
.nit_dir
123 print
"Error: Cannot locate nitdoc share files. Uses --sharedir or envvar NIT_DIR"
126 sharedir
= "{dir}/share/nitdoc"
127 if not sharedir
.file_exists
then
128 print
"Error: Cannot locate nitdoc share files. Uses --sharedir or envvar NIT_DIR"
133 if opt_shareurl
.value
== null then
134 sys
.system
("cp -r {sharedir.to_s}/* {output_dir.to_s}/")
136 sys
.system
("cp -r {sharedir.to_s}/resources/ {output_dir.to_s}/resources/")
141 private fun overview
do
142 var overviewpage
= new NitdocOverview(self)
143 overviewpage
.render
.write_to_file
("{output_dir.to_s}/index.html")
146 private fun search
do
147 var searchpage
= new NitdocSearch(self)
148 searchpage
.render
.write_to_file
("{output_dir.to_s}/search.html")
151 private fun modules
do
152 for mmodule
in mbuilder
.model
.mmodules
do
153 if mmodule
.name
== "<main>" then continue
154 var modulepage
= new NitdocModule(mmodule
, self)
155 modulepage
.render
.write_to_file
("{output_dir.to_s}/{mmodule.nitdoc_url}")
159 private fun classes
do
160 for mclass
in mbuilder
.model
.mclasses
do
161 var classpage
= new NitdocClass(mclass
, self)
162 classpage
.render
.write_to_file
("{output_dir.to_s}/{mclass.nitdoc_url}")
166 private fun quicksearch_list
do
167 var quicksearch
= new QuickSearch(self)
168 quicksearch
.render
.write_to_file
("{output_dir.to_s}/quicksearch-list.js")
172 # Nitdoc QuickSearch list generator
174 # Create a JSON object containing links to:
178 # All entities are grouped by name to make the research easier.
181 private var mmodules
= new HashSet[MModule]
182 private var mclasses
= new HashSet[MClass]
183 private var mpropdefs
= new HashMap[String, Set[MPropDef]]
185 init(ctx
: NitdocContext) do
186 for mmodule
in ctx
.mbuilder
.model
.mmodules
do
187 if mmodule
.name
== "<main>" then continue
190 for mclass
in ctx
.mbuilder
.model
.mclasses
do
191 if mclass
.visibility
< ctx
.min_visibility
then continue
194 for mproperty
in ctx
.mbuilder
.model
.mproperties
do
195 if mproperty
.visibility
< ctx
.min_visibility
then continue
196 if mproperty
isa MAttribute then continue
197 if not mpropdefs
.has_key
(mproperty
.name
) then
198 mpropdefs
[mproperty
.name
] = new HashSet[MPropDef]
200 mpropdefs
[mproperty
.name
].add_all
(mproperty
.mpropdefs
)
204 fun render
: Template do
205 var tpl
= new Template
206 tpl
.add
"var nitdocQuickSearchRawList=\{ "
207 for mmodule
in mmodules
do
208 tpl
.add
"\"{mmodule.name}\
":["
209 tpl
.add
"\{txt:\"{mmodule.full_name}\",url
:\
"{mmodule.nitdoc_url}\"\
},"
212 for mclass in mclasses do
213 var full_name = mclass.intro.mmodule.full_name
214 tpl.add "\
"{mclass.name}\":["
215 tpl.add "\
{txt:\"{full_name}\
",url:\"{mclass.nitdoc_url}\
"\},"
218 for mproperty
, mprops
in mpropdefs
do
219 tpl
.add
"\"{mproperty}\
":["
220 for mpropdef
in mprops
do
221 var full_name
= mpropdef
.mclassdef
.mclass
.full_name
222 tpl
.add
"\{txt:\"{full_name}\",url
:\
"{mpropdef.nitdoc_url}\"\
},"
232 # Define page structure and properties
233 abstract class NitdocPage
235 private var ctx: NitdocContext
236 private var shareurl = "."
238 init(ctx: NitdocContext) do
240 if ctx.opt_shareurl.value != null then shareurl = ctx.opt_shareurl.value.as(not null)
243 # Render the page as a html template
244 fun render: Template do
245 var tpl = new TplNitdocPage
247 tpl.topmenu = tpl_topmenu
248 tpl.sidebar = tpl_sidebar
249 tpl.content = tpl_content
250 tpl.footer = tpl_footer
252 tpl.body_attrs.add(new TagAttribute("data-bootstrap-share
", shareurl))
253 if ctx.opt_github_upstream.value != null and ctx.opt_github_base_sha1.value != null then
254 tpl.body_attrs.add(new TagAttribute("data-github-upstream
", ctx.opt_github_upstream.value))
255 tpl.body_attrs.add(new TagAttribute("data-github-base-sha1
", ctx.opt_github_base_sha1.value))
257 var requirejs = new TplScript
258 requirejs.attrs.add(new TagAttribute("data-main
", "{shareurl}/js
/nitdoc
"))
259 requirejs.attrs.add(new TagAttribute("src
", "{shareurl}/js
/lib
/require
.js
"))
260 tpl.scripts.add requirejs
263 var tracker_url = ctx.opt_piwik_tracker.value
264 var site_id = ctx.opt_piwik_site_id.value
265 if tracker_url != null and site_id != null then
266 tpl.scripts.add new TplPiwikScript(tracker_url, site_id)
272 fun tpl_title: String do
273 if ctx.opt_custom_title.value != null then
274 return ctx.opt_custom_title.value.to_s
280 # Page <head> template
281 fun tpl_head: TplHead do return new TplHead(tpl_title, shareurl)
284 fun tpl_topmenu: TplTopMenu do
285 var topmenu = new TplTopMenu
286 var custom_elt = ctx.opt_custom_menu.value
287 if custom_elt != null then topmenu.add_raw(custom_elt)
291 # Page sidebar template
292 # return null if no sidebar for this page
293 fun tpl_sidebar: nullable TplSidebar do return null
295 # Page content template
296 fun tpl_content: Template is abstract
298 # Page footer template
299 # return null if no footer for this page
300 fun tpl_footer: nullable TplFooter do
301 if ctx.opt_custom_footer.value != null then
302 return new TplFooter(ctx.opt_custom_footer.value.to_s)
307 # Clickable graphviz image using dot format
308 # return null if no graph for this page
309 fun tpl_graph(dot: FlatBuffer, name: String, alt: String): nullable TplGraph do
310 if ctx.opt_nodot.value then return null
311 var output_dir = ctx.output_dir
312 var file = new OFStream.open("{output_dir}/{name}.dot
")
315 sys.system("\
{ test -f {output_dir}/{name}.png
&& test
-f
{output_dir}/{name}.s
.dot
&& diff
{output_dir}/{name}.dot
{output_dir}/{name}.s
.dot
>/dev
/null 2>&1 ; \
} || \
{ cp {output_dir}/{name}.dot
{output_dir}/{name}.s
.dot
&& dot
-Tpng -o
{output_dir}/{name}.png
-Tcmapx -o
{output_dir}/{name}.map
{output_dir}/{name}.s
.dot
; \
}")
316 var fmap = new IFStream.open("{output_dir}/{name}.map
")
317 var map = fmap.read_all
319 return new TplGraph(name, alt, map)
322 # A (source) link template for a given location
323 fun tpl_showsource(location: nullable Location): nullable String
325 if location == null then return null
326 var source = ctx.opt_source.value
327 if source == null then return "({location.file.filename.simplify_path})"
328 # THIS IS JUST UGLY ! (but there is no replace yet)
329 var x = source.split_with("%f
")
330 source = x.join(location.file.filename.simplify_path)
331 x = source.split_with("%l
")
332 source = x.join(location.line_start.to_s)
333 x = source.split_with("%L
")
334 source = x.join(location.line_end.to_s)
335 source = source.simplify_path
336 return " (<a target
='_blank' title
='Show source' href
=\
"{source.to_s}\">source
</a
>)"
339 # MClassDef description template
340 fun tpl_mclassdef_article(mclassdef: MClassDef): TplArticle do
341 var article = mclassdef.tpl_article
342 article.content = new Template
343 if not mclassdef.is_intro then
345 var intro = mclassdef.mclass.intro
346 var location = intro.location
347 var sourcelink = tpl_showsource(location)
348 var intro_def = intro.tpl_short_definition
349 intro_def.location = sourcelink
350 intro_def.github_area = tpl_github(intro.full_namespace, intro.mdoc, location)
351 article.content.add intro_def
353 # add mclassdef full description
354 var location = mclassdef.location
355 var sourcelink = tpl_showsource(location)
356 var prop_def = mclassdef.tpl_definition
357 prop_def.location = sourcelink
358 prop_def.github_area = tpl_github(mclassdef.full_namespace, mclassdef.mdoc, location)
359 article.content.add prop_def
363 # MPropDef description template
364 fun tpl_mpropdef_article(mpropdef: MPropDef): TplArticle do
365 var article = mpropdef.tpl_article
366 article.content = new Template
367 if not mpropdef.is_intro then
369 var intro = mpropdef.mproperty.intro
370 var location = intro.location
371 var sourcelink = tpl_showsource(location)
372 var intro_def = intro.tpl_short_definition
373 intro_def.location = sourcelink
374 intro_def.github_area = tpl_github(intro.full_namespace, intro.mdoc, location)
375 article.content.add intro_def
377 # add mpropdef description
378 var location = mpropdef.location
379 var sourcelink = tpl_showsource(location)
380 var prop_def = mpropdef.tpl_definition
381 prop_def.location = sourcelink
382 prop_def.github_area = tpl_github(mpropdef.full_namespace, mpropdef.mdoc, location)
383 article.content.add prop_def
387 # Github area (for Github comment edition plugin)
388 # return null if no github plugin for this page
389 fun tpl_github(namespace: String, mdoc: nullable MDoc, loc: nullable Location): nullable TplGithubArea do
390 if loc == null then return null
391 if ctx.opt_github_gitdir.value == null then return null
392 var gitdir = ctx.opt_github_gitdir.value.as(not null)
393 var location = loc.github(gitdir)
396 comment = mdoc.full_comment
400 return new TplGithubArea(comment, namespace, location)
405 # Display a list of modules contained in program
409 private var mmodules = new Array[MModule]
411 init(ctx: NitdocContext) do
414 var mmodules = new HashSet[MModule]
415 for mmodule in ctx.mbuilder.model.mmodule_importation_hierarchy do
416 if mmodule.name == "<main
>" then continue
417 var owner = mmodule.public_owner
418 if owner != null then
421 mmodules.add(mmodule)
425 var sorter = new MModuleNameSorter
426 self.mmodules.add_all(mmodules)
427 sorter.sort(self.mmodules)
430 redef fun tpl_title do return "Overview | {super}"
432 redef fun tpl_topmenu do
434 topmenu.add_elt("#", "Overview", true)
435 topmenu
.add_elt
("search.html", "Search", false)
439 redef fun tpl_content
do
440 var tpl
= new TplOverviewPage
442 if ctx
.opt_custom_title
.value
!= null then
443 tpl
.title
= ctx
.opt_custom_title
.value
.to_s
445 tpl
.title
= "Overview"
448 if ctx
.opt_custom_intro
.value
!= null then
449 tpl
.text
= ctx
.opt_custom_intro
.value
.to_s
452 for mmodule
in mmodules
do
453 if mmodule
.mdoc
!= null then
454 var mtpl
= new Template
455 mtpl
.add mmodule
.tpl_link
457 mtpl
.add mmodule
.mdoc
.short_comment
466 # Genrate dot and template for module hierarchy
467 fun tpl_dot
: nullable TplGraph do
468 # build poset with public owners
469 var poset
= new POSet[MModule]
470 for mmodule
in mmodules
do
471 poset
.add_node
(mmodule
)
472 for omodule
in mmodules
do
473 if mmodule
== omodule
then continue
474 if mmodule
.in_importation
< omodule
then
475 poset
.add_node
(omodule
)
476 poset
.add_edge
(mmodule
, omodule
)
481 var op
= new FlatBuffer
482 op
.append
("digraph dep \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n")
483 for mmodule
in poset
do
484 op
.append
("\"{mmodule.name}\
"[URL=\"{mmodule.nitdoc_url}\
"];\n")
485 for omodule
in poset
[mmodule
].direct_greaters
do
486 op
.append
("\"{mmodule.name}\
"->\"{omodule.name}\
";\n")
490 return tpl_graph
(op
, "dep", "Modules hierarchy")
495 # Display a list of modules, classes and properties
499 init(ctx
: NitdocContext) do super(ctx
)
501 redef fun tpl_title
do return "Search | {super}"
503 redef fun tpl_topmenu
do
505 topmenu
.add_elt
("index.html", "Overview", false)
506 topmenu
.add_elt
("#", "Search", true)
510 redef fun tpl_content
do
511 var tpl
= new TplSearchPage
515 for mmodule
in modules_list
do
516 tpl
.modules
.add mmodule
.tpl_link
519 for mclass
in classes_list
do
520 tpl
.classes
.add mclass
.tpl_link
523 for mproperty
in mprops_list
do
525 m
.add mproperty
.intro
.tpl_link
527 m
.add mproperty
.intro
.mclassdef
.mclass
.tpl_link
534 # Extract mmodule list to display (sorted by name)
535 private fun modules_list
: Array[MModule] do
536 var sorted
= new Array[MModule]
537 for mmodule
in ctx
.mbuilder
.model
.mmodule_importation_hierarchy
do
538 if mmodule
.name
== "<main>" then continue
541 var sorter
= new MModuleNameSorter
546 # Extract mclass list to display (sorted by name)
547 private fun classes_list
: Array[MClass] do
548 var sorted
= new Array[MClass]
549 for mclass
in ctx
.mbuilder
.model
.mclasses
do
550 if mclass
.visibility
< ctx
.min_visibility
then continue
553 var sorter
= new MClassNameSorter
558 # Extract mproperty list to display (sorted by name)
559 private fun mprops_list
: Array[MProperty] do
560 var sorted
= new Array[MProperty]
561 for mproperty
in ctx
.mbuilder
.model
.mproperties
do
562 if mproperty
.visibility
< ctx
.min_visibility
then continue
563 if mproperty
isa MAttribute then continue
566 var sorter
= new MPropertyNameSorter
573 # Display the list of introduced and redefined classes in module
577 private var mmodule
: MModule
578 private var intro_mclassdefs
: Set[MClassDef]
579 private var redef_mclassdefs
: Set[MClassDef]
580 private var sorted_intro_mclassdefs
: Array[MClassDef]
581 private var sorted_redef_mclassdefs
: Array[MClassDef]
583 init(mmodule
: MModule, ctx
: NitdocContext) do
584 self.mmodule
= mmodule
585 var sorter
= new MClassDefNameSorter
586 intro_mclassdefs
= in_nesting_intro_mclassdefs
(ctx
.min_visibility
)
587 sorted_intro_mclassdefs
= intro_mclassdefs
.to_a
588 sorter
.sort sorted_intro_mclassdefs
589 redef_mclassdefs
= in_nesting_redef_mclassdefs
(ctx
.min_visibility
)
590 sorted_redef_mclassdefs
= redef_mclassdefs
.to_a
591 sorter
.sort sorted_redef_mclassdefs
595 redef fun tpl_title
do
596 if mmodule
.mdoc
!= null then
597 return "{mmodule.nitdoc_name} module | {mmodule.mdoc.short_comment} | {super}"
599 return "{mmodule.nitdoc_name} module | {super}"
603 redef fun tpl_topmenu
do
605 topmenu
.add_elt
("index.html", "Overview", false)
606 topmenu
.add_elt
("#", "{mmodule.nitdoc_name}", true)
607 topmenu
.add_elt
("search.html", "Search", false)
611 redef fun tpl_sidebar
do
612 var sidebar
= new TplSidebar
613 tpl_sidebar_classes
(sidebar
)
614 tpl_sidebar_inheritance
(sidebar
)
618 # Classes to display on sidebar
619 fun tpl_sidebar_classes
(sidebar
: TplSidebar) do
620 var box
= new TplSidebarBox("Class Definitions")
621 var group
= new TplSidebarGroup("Introductions")
622 for mclassdef
in sorted_intro_mclassdefs
do
623 tpl_sidebar_item
(mclassdef
, group
)
626 group
= new TplSidebarGroup("Refinements")
627 for mclassdef
in sorted_redef_mclassdefs
do
628 if intro_mclassdefs
.has
(mclassdef
.mclass
.intro
) then continue
629 tpl_sidebar_item
(mclassdef
, group
)
632 sidebar
.boxes
.add box
635 # Module inheritance to display on sidebar
636 fun tpl_sidebar_inheritance
(sidebar
: TplSidebar) do
637 var box
= new TplSidebarBox("Module Hierarchy")
638 box
.elts
.add tpl_sidebar_group
("Nested Modules", mmodule
.in_nesting
.direct_greaters
.to_a
)
639 var dependencies
= new Array[MModule]
640 for dep
in mmodule
.in_importation
.greaters
do
642 dep
.direct_owner
== mmodule
or
643 dep
.public_owner
== mmodule
then continue
644 dependencies
.add
(dep
)
646 if dependencies
.length
> 0 then
647 box
.elts
.add tpl_sidebar_group
("All dependencies", dependencies
)
649 var clients
= new Array[MModule]
650 for dep
in mmodule
.in_importation
.smallers
do
651 if dep
.name
== "<main>" then continue
652 if dep
== mmodule
then continue
655 if clients
.length
> 0 then
656 box
.elts
.add tpl_sidebar_group
("All clients", clients
)
658 sidebar
.boxes
.add box
661 private fun tpl_sidebar_item
(mclassdef
: MClassDef, group
: TplSidebarGroup) do
662 if mclassdef
.is_intro
then
663 group
.add_bullet
("I", "Introduced", mclassdef
.tpl_link_anchor
, ["intro"])
665 group
.add_bullet
("R", "Redefined", mclassdef
.tpl_link_anchor
, ["redef"])
669 private fun tpl_sidebar_group
(name
: String, elts
: Array[MModule]): TplSidebarGroup do
670 var group
= new TplSidebarGroup(name
)
672 group
.add_elt
(elt
.tpl_link
, new Array[String])
677 redef fun tpl_content
do
678 var class_sorter
= new MClassNameSorter
679 var tpl
= new TplModulePage
680 tpl
.title
= mmodule
.nitdoc_name
681 tpl
.subtitle
= mmodule
.tpl_signature
682 tpl
.definition
= mmodule
.tpl_definition
683 var location
= mmodule
.location
684 tpl
.definition
.location
= tpl_showsource
(location
)
685 tpl
.definition
.github_area
= tpl_github
(mmodule
.full_namespace
, mmodule
.mdoc
, location
)
687 for mclassdef
in sorted_intro_mclassdefs
do tpl
.intros
.add tpl_mclassdef_article
(mclassdef
)
688 for mclassdef
in sorted_redef_mclassdefs
do
689 if intro_mclassdefs
.has
(mclassdef
.mclass
.intro
) then continue
690 tpl
.redefs
.add tpl_mclassdef_article
(mclassdef
)
695 # Genrate dot hierarchy for class inheritance
696 fun tpl_dot
: nullable TplGraph do
697 # build poset with public owners
698 var poset
= new POSet[MModule]
699 for mmodule
in self.mmodule
.in_importation
.poset
do
700 if mmodule
.name
== "<main>" then continue
701 #if mmodule.public_owner != null then continue
702 if not mmodule
.in_importation
< self.mmodule
and not self.mmodule
.in_importation
< mmodule
and mmodule
!= self.mmodule
then continue
703 poset
.add_node
(mmodule
)
704 for omodule
in mmodule
.in_importation
.poset
do
705 if mmodule
== omodule
then continue
706 if omodule
.name
== "<main>" then continue
707 if not omodule
.in_importation
< self.mmodule
and not self.mmodule
.in_importation
< omodule
then continue
708 if omodule
.in_importation
< mmodule
then
709 poset
.add_node
(omodule
)
710 poset
.add_edge
(omodule
, mmodule
)
712 if mmodule
.in_importation
< omodule
then
713 poset
.add_node
(omodule
)
714 poset
.add_edge
(mmodule
, omodule
)
716 #if omodule.public_owner != null then continue
717 #if mmodule.in_importation < omodule then
718 #poset.add_node(omodule)
719 #poset.add_edge(mmodule, omodule)
724 var op
= new FlatBuffer
725 var name
= "dep_{mmodule.name}"
726 op
.append
("digraph {name} \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n")
727 for mmodule
in poset
do
728 if mmodule
== self.mmodule
then
729 op
.append
("\"{mmodule.name}\
"[shape=box,margin=0.03];\n")
731 op
.append
("\"{mmodule.name}\
"[URL=\"{mmodule.nitdoc_url}\
"];\n")
733 for omodule
in poset
[mmodule
].direct_greaters
do
734 op
.append
("\"{mmodule.name}\
"->\"{omodule.name}\
";\n")
738 return tpl_graph
(op
, name
, "Dependency graph for module {mmodule.name}")
741 private fun in_nesting_intro_mclassdefs
(min_visibility
: MVisibility): Set[MClassDef] do
742 var res
= new HashSet[MClassDef]
743 for mmodule
in self.mmodule
.in_nesting
.greaters
do
744 res
.add_all mmodule
.intro_mclassdefs
(min_visibility
)
749 private fun in_nesting_redef_mclassdefs
(min_visibility
: MVisibility): Set[MClassDef] do
750 var res
= new HashSet[MClassDef]
751 for mmodule
in self.mmodule
.in_nesting
.greaters
do
752 res
.add_all mmodule
.redef_mclassdefs
(min_visibility
)
759 # Display a list properties defined or redefined for this class
763 private var mclass
: MClass
764 private var inherited_mpropdefs
: Set[MPropDef]
765 private var intro_mpropdefs
: Set[MPropDef]
766 private var redef_mpropdefs
: Set[MPropDef]
767 private var all_mpropdefs
: Set[MPropDef]
769 init(mclass
: MClass, ctx
: NitdocContext) do
772 intro_mpropdefs
= mclass_intro_mpropdefs
773 redef_mpropdefs
= mclass_redef_mpropdefs
774 inherited_mpropdefs
= in_nesting_inherited_mpropedefs
775 all_mpropdefs
= new HashSet[MPropDef]
776 all_mpropdefs
.add_all intro_mpropdefs
777 all_mpropdefs
.add_all redef_mpropdefs
778 all_mpropdefs
.add_all inherited_mpropdefs
781 private fun in_nesting_inherited_mpropedefs
: Set[MPropDef] do
782 var res
= new HashSet[MPropDef]
783 var local
= mclass
.local_mproperties
(ctx
.min_visibility
)
784 for mprop
in mclass
.inherited_mproperties
(ctx
.mainmodule
, ctx
.min_visibility
) do
785 if local
.has
(mprop
) then continue
786 if mprop
isa MMethod and mprop
.is_init
then continue
792 private fun mclass_intro_mpropdefs
: Set[MPropDef] do
793 var res
= new HashSet[MPropDef]
794 for mclassdef
in mclass
.mclassdefs
do
795 for mpropdef
in mclassdef
.mpropdefs
do
796 if not mpropdef
.is_intro
then continue
797 if mclassdef
.mmodule
.public_owner
!= mclass
.public_owner
then continue
798 var mprop
= mpropdef
.mproperty
799 if mprop
isa MMethod and mprop
.is_init
and mclass
.is_abstract
then continue
800 if mprop
.visibility
< ctx
.min_visibility
then continue
807 private fun mclass_redef_mpropdefs
: Set[MPropDef] do
808 var res
= new HashSet[MPropDef]
809 for mclassdef
in mclass
.mclassdefs
do
810 if mclassdef
== mclass
.intro
then continue
811 for mpropdef
in mclassdef
.mpropdefs
do
812 if mclassdef
.mmodule
.public_owner
== mclass
.public_owner
then continue
813 if mpropdef
.mproperty
.visibility
< ctx
.min_visibility
then continue
820 redef fun tpl_title
do
821 if mclass
.mdoc
!= null then
822 return "{mclass.nitdoc_name} class | {mclass.mdoc.short_comment} | {super}"
824 return "{mclass.nitdoc_name} class | {super}"
828 redef fun tpl_topmenu
do
831 if mclass
.public_owner
== null then
832 mmodule
= mclass
.intro_mmodule
834 mmodule
= mclass
.public_owner
.as(not null)
836 topmenu
.add_elt
("index.html", "Overview", false)
837 topmenu
.add_elt
("{mmodule.nitdoc_url}", "{mmodule.nitdoc_name}", false)
838 topmenu
.add_elt
("#", "{mclass.nitdoc_name}", true)
839 topmenu
.add_elt
("search.html", "Search", false)
843 redef fun tpl_sidebar
do
844 var sidebar
= new TplSidebar
845 tpl_sidebar_properties
(sidebar
)
846 tpl_sidebar_inheritance
(sidebar
)
850 # Property list to display in sidebar
851 fun tpl_sidebar_properties
(sidebar
: TplSidebar) do
852 var kind_map
= sort_by_kind
(all_mpropdefs
)
853 var sorter
= new MPropDefNameSorter
854 var box
= new TplSidebarBox("Properties")
856 var elts
= kind_map
["type"].to_a
858 var group
= new TplSidebarGroup("Virtual Types")
860 tpl_sidebar_item
(mprop
, group
)
864 elts
= kind_map
["init"].to_a
866 group
= new TplSidebarGroup("Constructors")
868 tpl_sidebar_item
(mprop
, group
)
872 elts
= kind_map
["fun"].to_a
874 group
= new TplSidebarGroup("Methods")
876 tpl_sidebar_item
(mprop
, group
)
879 sidebar
.boxes
.add box
882 # Class inheritance to display in sidebar
883 fun tpl_sidebar_inheritance
(sidebar
: TplSidebar) do
884 var sorted
= new Array[MClass]
885 var sorterp
= new MClassNameSorter
886 var box
= new TplSidebarBox("Inheritance")
887 var greaters
= mclass
.in_hierarchy
(ctx
.mainmodule
).greaters
.to_a
888 if greaters
.length
> 1 then
889 ctx
.mainmodule
.linearize_mclasses
(greaters
)
890 box
.elts
.add tpl_sidebar_group
("Superclasses", greaters
)
892 var smallers
= mclass
.in_hierarchy
(ctx
.mainmodule
).smallers
.to_a
893 var direct_smallers
= mclass
.in_hierarchy
(ctx
.mainmodule
).direct_smallers
.to_a
894 if smallers
.length
<= 1 then
895 box
.elts
.add
(new TplSidebarGroup("No Known Subclasses"))
896 else if smallers
.length
<= 100 then
897 ctx
.mainmodule
.linearize_mclasses
(smallers
)
898 box
.elts
.add tpl_sidebar_group
("Subclasses", smallers
)
899 else if direct_smallers
.length
<= 100 then
900 ctx
.mainmodule
.linearize_mclasses
(direct_smallers
)
901 box
.elts
.add tpl_sidebar_group
("Direct Subclasses Only", direct_smallers
)
903 box
.elts
.add
(new TplSidebarGroup("Too much Subclasses to list"))
905 sidebar
.boxes
.add box
908 private fun tpl_sidebar_item
(mprop
: MPropDef, group
: TplSidebarGroup) do
909 if mprop
.is_intro
and mprop
.mclassdef
.mclass
== mclass
then
910 group
.add_bullet
("I", "Introduced", mprop
.tpl_link
, ["intro"])
911 else if mprop
.is_intro
and mprop
.mclassdef
.mclass
!= mclass
then
912 group
.add_bullet
("H", "Inherited", mprop
.tpl_link
, ["inherit"])
914 group
.add_bullet
("R", "Redefined", mprop
.tpl_link
, ["redef"])
918 private fun tpl_sidebar_group
(name
: String, elts
: Array[MClass]): TplSidebarGroup do
919 var group
= new TplSidebarGroup(name
)
921 if elt
== mclass
then continue
922 group
.add_elt
(elt
.tpl_link
, new Array[String])
927 redef fun tpl_content
do
928 var intro
= mclass
.intro
929 var tpl
= new TplClassPage
930 tpl
.title
= "{mclass.nitdoc_name}{mclass.tpl_short_signature}"
931 tpl
.subtitle
= mclass
.tpl_namespace_with_signature
932 tpl
.definition
= intro
.tpl_definition
933 var location
= intro
.location
934 tpl
.definition
.location
= tpl_showsource
(location
)
935 tpl
.definition
.github_area
= tpl_github
(intro
.full_namespace
, intro
.mdoc
, location
)
939 var prop_sorter
= new MPropDefNameSorter
940 var kind_map
= sort_by_kind
(intro_mpropdefs
)
943 var elts
= kind_map
["type"].to_a
944 prop_sorter
.sort
(elts
)
945 for elt
in elts
do tpl
.types
.add tpl_mpropdef_article
(elt
)
948 elts
= kind_map
["init"].to_a
949 prop_sorter
.sort
(elts
)
950 for elt
in elts
do tpl
.inits
.add tpl_mpropdef_article
(elt
)
953 elts
= kind_map
["fun"].to_a
954 prop_sorter
.sort
(elts
)
955 for elt
in elts
do tpl
.methods
.add tpl_mpropdef_article
(elt
)
958 kind_map
= sort_by_kind
(redef_mpropdefs
)
959 var module_sorter
= new MModuleNameSorter
960 var module_map
= sort_by_mmodule
(kind_map
["fun"])
961 var owner_map
= sort_by_public_owner
(module_map
.keys
)
962 var owners
= owner_map
.keys
.to_a
963 module_sorter
.sort owners
965 var ctpl
= new TplConcernList
966 var mtpl
= new Template
967 for owner
in owners
do
969 var octpl
= new TplConcernListElt
970 octpl
.anchor
= "#{owner.nitdoc_anchor}"
971 octpl
.name
= owner
.nitdoc_name
972 if owner
.mdoc
!= null then
973 octpl
.comment
= owner
.mdoc
.short_comment
977 var otpl
= new TplTopConcern
978 otpl
.anchor
= owner
.nitdoc_anchor
979 otpl
.concern
= owner
.tpl_link
982 var mmodules
= owner_map
[owner
].to_a
983 module_sorter
.sort mmodules
984 var stpl
= new TplConcernList
985 for mmodule
in mmodules
do
987 var mctpl
= new TplConcernListElt
988 mctpl
.anchor
= "#{mmodule.nitdoc_anchor}"
989 mctpl
.name
= mmodule
.nitdoc_name
990 if mmodule
.mdoc
!= null then
991 mctpl
.comment
= mmodule
.mdoc
.short_comment
995 var cctpl
= new TplConcern
996 cctpl
.anchor
= mmodule
.nitdoc_anchor
997 cctpl
.concern
= mmodule
.tpl_link
998 if mmodule
.mdoc
!= null then
999 cctpl
.comment
= mmodule
.mdoc
.short_comment
1003 var mprops
= module_map
[mmodule
].to_a
1004 prop_sorter
.sort mprops
1005 for mprop
in mprops
do mtpl
.add tpl_mpropdef_article
(mprop
)
1009 if not owners
.is_empty
then
1012 tpl
.methods
.add mtpl
1016 private fun sort_by_kind
(mpropdefs
: Set[MPropDef]): Map[String, Set[MPropDef]] do
1017 var map
= new HashMap[String, Set[MPropDef]]
1018 map
["type"] = new HashSet[MPropDef]
1019 map
["init"] = new HashSet[MPropDef]
1020 map
["fun"] = new HashSet[MPropDef]
1021 for mpropdef
in mpropdefs
do
1022 if mpropdef
isa MVirtualTypeDef then
1023 map
["type"].add mpropdef
1024 else if mpropdef
isa MMethodDef then
1025 if mpropdef
.mproperty
.is_init
then
1026 map
["init"].add mpropdef
1028 map
["fun"].add mpropdef
1035 private fun sort_by_mmodule
(mpropdefs
: Collection[MPropDef]): Map[MModule, Set[MPropDef]] do
1036 var map
= new HashMap[MModule, Set[MPropDef]]
1037 for mpropdef
in mpropdefs
do
1038 var mmodule
= mpropdef
.mclassdef
.mmodule
1039 if not map
.has_key
(mmodule
) then map
[mmodule
] = new HashSet[MPropDef]
1040 map
[mmodule
].add mpropdef
1045 private fun sort_by_public_owner
(mmodules
: Collection[MModule]): Map[MModule, Set[MModule]] do
1046 var map
= new HashMap[MModule, Set[MModule]]
1047 for mmodule
in mmodules
do
1049 if mmodule
.public_owner
!= null then owner
= mmodule
.public_owner
.as(not null)
1050 if not map
.has_key
(owner
) then map
[owner
] = new HashSet[MModule]
1051 map
[owner
].add mmodule
1056 # Generate dot hierarchy for classes
1057 fun tpl_dot
: nullable TplGraph do
1058 var pe
= mclass
.in_hierarchy
(ctx
.mainmodule
)
1059 var cla
= new HashSet[MClass]
1060 var sm
= new HashSet[MClass]
1061 var sm2
= new HashSet[MClass]
1063 while cla
.length
+ sm
.length
< 10 and sm
.length
> 0 do
1067 sm2
.add_all
(pe
.poset
[x
].direct_smallers
)
1073 cla
.add_all
(pe
.greaters
)
1075 var op
= new FlatBuffer
1076 var name
= "dep_{mclass.name}"
1077 op
.append
("digraph {name} \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n")
1080 op
.append
("\"{c.name}\
"[shape=box,margin=0.03];\n")
1082 op
.append
("\"{c.name}\
"[URL=\"{c.nitdoc_url}\
"];\n")
1084 for c2
in pe
.poset
[c
].direct_greaters
do
1085 if not cla
.has
(c2
) then continue
1086 op
.append
("\"{c.name}\
"->\"{c2.name}\
";\n")
1088 if not pe
.poset
[c
].direct_smallers
.is_empty
then
1090 for c2
in pe
.poset
[c
].direct_smallers
do
1091 if cla
.has
(c2
) then others
= false
1094 op
.append
("\"{c.name}...\
"[label=\"\
"];\n")
1095 op
.append
("\"{c.name}...\
"->\"{c.name}\
"[style=dotted];\n")
1100 return tpl_graph
(op
, name
, "Dependency graph for class {mclass.name}")
1109 # Return the HTML escaped name of the module
1110 private fun nitdoc_name
: String do return name
.html_escape
1112 private fun full_namespace
: String do
1113 if public_owner
!= null then
1114 return "{public_owner.nitdoc_name}::{nitdoc_name}"
1119 # URL to nitdoc page
1120 # module_owner_name.html
1121 private fun nitdoc_url
: String do
1122 var res
= new FlatBuffer
1123 res
.append
("module_")
1124 var mowner
= public_owner
1125 if mowner
!= null then
1126 res
.append
("{public_owner.name}_")
1128 res
.append
("{self.name}.html")
1132 # html nitdoc_anchor id for the module in a nitdoc page
1134 private fun nitdoc_anchor
: String do
1135 var res
= new FlatBuffer
1137 var mowner
= public_owner
1138 if mowner
!= null then
1139 res
.append
("{public_owner.name}_")
1141 res
.append
(self.name
)
1145 # Return a link (html a tag) to the nitdoc module page
1146 private fun tpl_link
: TplLink do
1147 var tpl
= new TplLink
1148 tpl
.href
= nitdoc_url
1149 tpl
.text
= nitdoc_name
1150 if mdoc
!= null then
1151 tpl
.title
= mdoc
.short_comment
1156 # Return the module signature decorated with html
1157 private fun tpl_signature
: Template do
1158 var tpl
= new Template
1159 tpl
.add
"<span>module "
1160 tpl
.add tpl_full_namespace
1165 # Return the module full namespace decorated with html
1166 private fun tpl_full_namespace
: Template do
1167 var tpl
= new Template
1169 var mowner
= public_owner
1170 if mowner
!= null then
1171 tpl
.add public_owner
.tpl_namespace
1179 # Return the module full namespace decorated with html
1180 private fun tpl_namespace
: Template do
1181 var tpl
= new Template
1183 var mowner
= public_owner
1184 if mowner
!= null then
1185 tpl
.add public_owner
.tpl_namespace
1193 # Description with short comment
1194 private fun tpl_short_definition
: TplDefinition do
1195 var tpl
= new TplDefinition
1196 tpl
.namespace
= tpl_namespace
1197 if mdoc
!= null then
1198 tpl
.comment
= mdoc
.tpl_short_comment
1203 # Description with full comment
1204 private fun tpl_definition
: TplDefinition do
1205 var tpl
= new TplDefinition
1206 tpl
.namespace
= tpl_namespace
1207 if mdoc
!= null then
1208 tpl
.comment
= mdoc
.tpl_comment
1215 # Return the HTML escaped name of the module
1216 private fun nitdoc_name
: String do return name
.html_escape
1218 # URL to nitdoc page
1219 # class_owner_name.html
1220 private fun nitdoc_url
: String do
1221 return "class_{public_owner}_{name}.html"
1224 # html nitdoc_anchor id for the class in a nitdoc page
1226 private fun nitdoc_anchor
: String do
1227 return "CLASS_{public_owner.name}_{name}"
1230 # Return a link (with signature) to the nitdoc class page
1231 private fun tpl_link
: TplLink do
1232 var tpl
= new TplLink
1233 tpl
.href
= nitdoc_url
1234 tpl
.text
= "{nitdoc_name}{tpl_short_signature.write_to_string}"
1235 if intro
.mdoc
!= null then
1236 tpl
.title
= intro
.mdoc
.short_comment
1241 # Return a short link (without signature) to the nitdoc class page
1242 private fun tpl_short_link
: TplLink do
1243 var tpl
= new TplLink
1244 tpl
.href
= nitdoc_url
1245 tpl
.text
= nitdoc_name
1246 if intro
.mdoc
!= null then
1247 tpl
.title
= intro
.mdoc
.short_comment
1252 # Return a link (with signature) to the class nitdoc_anchor
1253 private fun tpl_link_anchor
: TplLink do
1254 var tpl
= new TplLink
1255 tpl
.href
= "#{nitdoc_anchor}"
1256 tpl
.text
= "{nitdoc_name}{tpl_short_signature.write_to_string}"
1257 if intro
.mdoc
!= null then
1258 tpl
.title
= intro
.mdoc
.short_comment
1263 # Return the generic signature of the class with bounds
1264 private fun tpl_signature
: Template do
1265 var tpl
= new Template
1268 for i
in [0..intro
.parameter_names
.length
[ do
1269 tpl
.add
"{intro.parameter_names[i]}: "
1270 tpl
.add intro
.bound_mtype
.arguments
[i
].tpl_link
1271 if i
< intro
.parameter_names
.length
- 1 then tpl
.add
", "
1278 # Return the generic signature of the class without bounds
1279 private fun tpl_short_signature
: String do
1281 return "[{intro.parameter_names.join(", ")}]"
1287 # Return the class namespace decorated with html
1288 private fun tpl_namespace
: Template do
1289 var tpl
= new Template
1290 tpl
.add intro_mmodule
.tpl_namespace
1292 tpl
.add tpl_short_link
1297 private fun tpl_namespace_with_signature
: Template do
1298 var tpl
= new Template
1299 tpl
.add intro
.tpl_modifiers
1300 tpl
.add intro
.mmodule
.tpl_namespace
1303 tpl
.add tpl_signature
1308 redef class MProperty
1309 # Escape name for html output
1310 private fun nitdoc_name
: String do return name
.html_escape
1312 # Return the property namespace decorated with html
1313 private fun tpl_namespace
: Template do
1314 var tpl
= new Template
1315 tpl
.add intro_mclassdef
.mclass
.tpl_namespace
1316 tpl
.add intro_mclassdef
.mclass
.tpl_short_signature
1318 tpl
.add intro
.tpl_link
1323 private fun tpl_signature
: Template is abstract
1327 redef fun tpl_signature
do return intro
.msignature
.tpl_signature
1330 redef class MVirtualTypeProp
1331 redef fun tpl_signature
do
1332 var tpl
= new Template
1334 tpl
.add intro
.bound
.tpl_link
1340 # Link to the type definition in the nitdoc page
1341 private fun tpl_link
: Template is abstract
1344 redef class MClassType
1345 redef fun tpl_link
do return mclass
.tpl_link
1348 redef class MNullableType
1349 redef fun tpl_link
do
1350 var tpl
= new Template
1352 tpl
.add mtype
.tpl_link
1357 redef class MGenericType
1358 redef fun tpl_link
: Template do
1359 var tpl
= new Template
1360 tpl
.add mclass
.tpl_short_link
1362 for i
in [0..arguments
.length
[ do
1363 tpl
.add arguments
[i
].tpl_link
1364 if i
< arguments
.length
- 1 then tpl
.add
", "
1371 redef class MParameterType
1372 redef fun tpl_link
do
1373 var name
= mclass
.intro
.parameter_names
[rank
]
1374 var tpl
= new TplLink
1375 tpl
.href
= "{mclass.nitdoc_url}#FT_{name}"
1377 tpl
.title
= "formal type"
1382 redef class MVirtualType
1383 redef fun tpl_link
do return mproperty
.intro
.tpl_link
1386 redef class MClassDef
1387 # Return the classdef namespace decorated with html
1388 private fun tpl_namespace
: Template do
1389 var tpl
= new Template
1390 tpl
.add mmodule
.tpl_namespace
1392 tpl
.add mclass
.tpl_link
1397 private fun full_namespace
: String do
1398 return "{mmodule.full_namespace}::{mclass.nitdoc_name}"
1401 private fun tpl_link_anchor
: TplLink do return mclass
.tpl_link_anchor
1403 private fun tpl_article
: TplArticle do
1404 var tpl
= new TplArticle
1405 tpl
.id
= mclass
.nitdoc_anchor
1406 tpl
.classes
.add_all
(tpl_css_classes
)
1407 tpl
.title
= new Template
1408 tpl
.title
.add mclass
.tpl_short_link
1409 tpl
.title
.add mclass
.tpl_signature
1410 tpl
.subtitle
= new Template
1411 tpl
.subtitle
.add tpl_modifiers
1412 tpl
.subtitle
.add tpl_namespace
1413 tpl
.content
= new Template
1414 tpl
.content
.add tpl_definition
1418 private fun tpl_css_classes
: Set[String] do
1419 var set
= new HashSet[String]
1420 set
.add_all mclass
.intro
.modifiers
1421 set
.add_all modifiers
1425 private fun tpl_modifiers
: Template do
1426 var tpl
= new Template
1427 for modifier
in modifiers
do
1428 if modifier
== "public" then continue
1429 tpl
.add
"{modifier} "
1434 private fun tpl_short_definition
: TplDefinition do
1435 var tpl
= new TplDefinition
1436 tpl
.namespace
= mmodule
.tpl_full_namespace
1437 if mdoc
!= null then
1438 tpl
.comment
= mdoc
.tpl_short_comment
1443 private fun tpl_definition
: TplDefinition do
1444 var tpl
= new TplDefinition
1445 tpl
.namespace
= mmodule
.tpl_full_namespace
1446 if mdoc
!= null then
1447 tpl
.comment
= mdoc
.tpl_comment
1453 redef class MPropDef
1454 # Return the full qualified name of the mpropdef
1455 # module::classdef::name
1456 private fun tpl_namespace
: Template do
1457 var tpl
= new Template
1458 tpl
.add mclassdef
.tpl_namespace
1460 tpl
.add mproperty
.name
1464 private fun full_namespace
: String do
1465 return "{mclassdef.full_namespace}::{mproperty.nitdoc_name}"
1468 # URL into the nitdoc page
1469 # class_owner_name.html#nitdoc_anchor
1470 private fun nitdoc_url
: String do
1471 return "{mclassdef.mclass.nitdoc_url}#{nitdoc_anchor}"
1474 # html nitdoc_anchor id for the property in a nitdoc class page
1475 # PROP_mclass_propertyname
1476 private fun nitdoc_anchor
: String do
1477 return "PROP_{mclassdef.mclass.public_owner.nitdoc_name}_{mproperty.name.replace(" ", "_")}"
1480 # Return a link to property into the nitdoc class page
1481 # <a href="nitdoc_url" title="short_comment">nitdoc_name</a>
1482 private fun tpl_link
: TplLink do
1483 var tpl
= new TplLink
1484 tpl
.href
= nitdoc_url
1485 tpl
.text
= mproperty
.nitdoc_name
1486 if mproperty
.intro
.mdoc
!= null then
1487 tpl
.title
= mproperty
.intro
.mdoc
.short_comment
1492 private fun tpl_article
: TplArticle do
1493 var tpl
= new TplArticle
1494 tpl
.id
= nitdoc_anchor
1495 tpl
.classes
.add_all
(tpl_css_classes
)
1496 tpl
.title
= new Template
1497 tpl
.title
.add mproperty
.nitdoc_name
1498 tpl
.title
.add mproperty
.tpl_signature
1499 tpl
.subtitle
= new Template
1500 tpl
.subtitle
.add tpl_modifiers
1501 tpl
.subtitle
.add tpl_namespace
1502 tpl
.content
= new Template
1503 tpl
.content
.add tpl_definition
1507 private fun tpl_css_classes
: Set[String] do
1508 var set
= new HashSet[String]
1509 set
.add_all mproperty
.intro
.modifiers
1510 set
.add_all modifiers
1514 private fun tpl_modifiers
: Template do
1515 var tpl
= new Template
1516 for modifier
in modifiers
do
1517 if modifier
== "public" then continue
1518 tpl
.add
"{modifier} "
1523 private fun tpl_short_definition
: TplDefinition do
1524 var tpl
= new TplDefinition
1525 tpl
.namespace
= mclassdef
.tpl_namespace
1526 if mdoc
!= null then
1527 tpl
.comment
= mdoc
.tpl_short_comment
1532 private fun tpl_definition
: TplDefinition do
1533 var tpl
= new TplDefinition
1534 tpl
.namespace
= mclassdef
.tpl_namespace
1535 if mdoc
!= null then
1536 tpl
.comment
= mdoc
.tpl_comment
1542 redef class MSignature
1543 private fun tpl_signature
: Template do
1544 var tpl
= new Template
1545 if not mparameters
.is_empty
then
1547 for i
in [0..mparameters
.length
[ do
1548 tpl
.add mparameters
[i
].tpl_link
1549 if i
< mparameters
.length
- 1 then tpl
.add
", "
1553 if return_mtype
!= null then
1555 tpl
.add return_mtype
.tpl_link
1561 redef class MParameter
1562 private fun tpl_link
: Template do
1563 var tpl
= new Template
1565 tpl
.add mtype
.tpl_link
1566 if is_vararg
then tpl
.add
"..."
1571 redef class Location
1572 fun github
(gitdir
: String): String do
1573 var base_dir
= getcwd
.join_path
(gitdir
).simplify_path
1574 var file_loc
= getcwd
.join_path
(file
.filename
).simplify_path
1575 var gith_loc
= file_loc
.substring
(base_dir
.length
+ 1, file_loc
.length
)
1576 return "{gith_loc}:{line_start},{column_start}--{line_end},{column_end}"
1581 private fun short_comment
: String do
1582 return content
.first
.html_escape
1585 private fun full_comment
: String do
1586 return content
.join
("\n").html_escape
1589 private fun tpl_short_comment
: TplShortComment do
1590 return new TplShortComment(short_markdown
)
1593 private fun tpl_comment
: TplComment do
1594 return new TplComment(full_markdown
)
1598 var nitdoc
= new NitdocContext
1599 nitdoc
.generate_nitdoc