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 # Nitdoc page generation
21 redef class ToolContext
22 private var opt_dir
= new OptionString("output directory", "-d", "--dir")
23 private var opt_source
= new OptionString("link for source (%f for filename, %l for first line, %L for last line)", "--source")
24 private var opt_sharedir
= new OptionString("directory containing nitdoc assets", "--sharedir")
25 private var opt_shareurl
= new OptionString("use shareurl instead of copy shared files", "--shareurl")
26 private var opt_nodot
= new OptionBool("do not generate graphes with graphviz", "--no-dot")
27 private var opt_private
= new OptionBool("also generate private API", "--private")
29 private var opt_custom_title
= new OptionString("custom title for homepage", "--custom-title")
30 private var opt_custom_brand
= new OptionString("custom link to external site", "--custom-brand")
31 private var opt_custom_intro
= new OptionString("custom intro text for homepage", "--custom-overview-text")
32 private var opt_custom_footer
= new OptionString("custom footer text", "--custom-footer-text")
34 private var opt_github_upstream
= new OptionString("Git branch where edited commits will be pulled into (ex: user:repo:branch)", "--github-upstream")
35 private var opt_github_base_sha1
= new OptionString("Git sha1 of base commit used to create pull request", "--github-base-sha1")
36 private var opt_github_gitdir
= new OptionString("Git working directory used to resolve path name (ex: /home/me/myproject/)", "--github-gitdir")
38 private var opt_piwik_tracker
= new OptionString("Piwik tracker URL (ex: nitlanguage.org/piwik/)", "--piwik-tracker")
39 private var opt_piwik_site_id
= new OptionString("Piwik site ID", "--piwik-site-id")
41 private var output_dir
: String
42 private var min_visibility
: MVisibility
47 var opts
= option_context
48 opts
.add_option
(opt_dir
, opt_source
, opt_sharedir
, opt_shareurl
, opt_nodot
, opt_private
)
49 opts
.add_option
(opt_custom_title
, opt_custom_footer
, opt_custom_intro
, opt_custom_brand
)
50 opts
.add_option
(opt_github_upstream
, opt_github_base_sha1
, opt_github_gitdir
)
51 opts
.add_option
(opt_piwik_tracker
, opt_piwik_site_id
)
53 var tpl
= new Template
54 tpl
.add
"Usage: nitdoc [OPTION]... <file.nit>...\n"
55 tpl
.add
"Generates HTML pages of API documentation from Nit source files."
56 tooldescription
= tpl
.write_to_string
59 redef fun process_options
(args
) do
63 var output_dir
= opt_dir
.value
64 if output_dir
== null then
67 self.output_dir
= output_dir
69 if opt_private
.value
then
70 min_visibility
= none_visibility
72 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"
87 # The Nitdoc class explores the model and generate pages for each mentities found
91 var mainmodule
: MModule
104 private fun init_output_dir
do
105 # create destination dir if it's necessary
106 var output_dir
= ctx
.output_dir
107 if not output_dir
.file_exists
then output_dir
.mkdir
109 var sharedir
= ctx
.opt_sharedir
.value
110 if sharedir
== null then
111 var dir
= ctx
.nit_dir
112 sharedir
= dir
/"share/nitdoc"
113 if not sharedir
.file_exists
then
114 print
"Error: Cannot locate nitdoc share files. Uses --sharedir or envvar NIT_DIR"
119 if ctx
.opt_shareurl
.value
== null then
120 sys
.system
("cp -r {sharedir.to_s}/* {output_dir.to_s}/")
122 sys
.system
("cp -r {sharedir.to_s}/resources/ {output_dir.to_s}/resources/")
127 private fun overview
do
128 var page
= new NitdocOverview(ctx
, model
, mainmodule
)
129 page
.render
.write_to_file
("{ctx.output_dir.to_s}/{page.page_url}")
132 private fun search
do
133 var page
= new NitdocSearch(ctx
, model
, mainmodule
)
134 page
.render
.write_to_file
("{ctx.output_dir.to_s}/{page.page_url}")
137 private fun groups
do
138 for mproject
in model
.mprojects
do
139 for mgroup
in mproject
.mgroups
.to_a
do
140 var page
= new NitdocGroup(ctx
, model
, mainmodule
, mgroup
)
141 page
.render
.write_to_file
("{ctx.output_dir.to_s}/{page.page_url}")
146 private fun modules
do
147 for mmodule
in model
.mmodules
do
148 if mmodule
.is_fictive
then continue
149 var page
= new NitdocModule(ctx
, model
, mainmodule
, mmodule
)
150 page
.render
.write_to_file
("{ctx.output_dir.to_s}/{page.page_url}")
154 private fun classes
do
155 for mclass
in model
.mclasses
do
156 if mclass
.visibility
<= ctx
.min_visibility
then continue
157 var page
= new NitdocClass(ctx
, model
, mainmodule
, mclass
)
158 page
.render
.write_to_file
("{ctx.output_dir.to_s}/{page.page_url}")
162 private fun properties
do
163 for mproperty
in model
.mproperties
do
164 if mproperty
.visibility
<= ctx
.min_visibility
then continue
165 var page
= new NitdocProperty(ctx
, model
, mainmodule
, mproperty
)
166 page
.render
.write_to_file
("{ctx.output_dir.to_s}/{page.page_url}")
170 private fun quicksearch_list
do
171 var quicksearch
= new QuickSearch(ctx
, model
)
172 quicksearch
.render
.write_to_file
("{ctx.output_dir.to_s}/quicksearch-list.js")
176 # Nitdoc QuickSearch list generator
178 # Create a JSON object containing links to:
182 # All entities are grouped by name to make the research easier.
185 private var mmodules
= new HashSet[MModule]
186 private var mclasses
= new HashSet[MClass]
187 private var mpropdefs
= new HashMap[String, Set[MPropDef]]
193 for mmodule
in model
.mmodules
do
194 if mmodule
.is_fictive
then continue
197 for mclass
in model
.mclasses
do
198 if mclass
.visibility
< ctx
.min_visibility
then continue
201 for mproperty
in model
.mproperties
do
202 if mproperty
.visibility
< ctx
.min_visibility
then continue
203 if mproperty
isa MAttribute then continue
204 if not mpropdefs
.has_key
(mproperty
.name
) then
205 mpropdefs
[mproperty
.name
] = new HashSet[MPropDef]
207 mpropdefs
[mproperty
.name
].add_all
(mproperty
.mpropdefs
)
211 fun render
: Template do
212 var tpl
= new Template
213 tpl
.add
"var nitdocQuickSearchRawList=\{ "
214 for mmodule
in mmodules
do
215 tpl
.add
"\"{mmodule.name}\
":["
216 tpl
.add
"\{txt:\"{mmodule.full_name}\",url
:\
"{mmodule.nitdoc_url}\"\
},"
219 for mclass in mclasses do
220 var full_name = mclass.intro.mmodule.full_name
221 tpl.add "\
"{mclass.name}\":["
222 tpl.add "\
{txt:\"{full_name}\
",url:\"{mclass.nitdoc_url}\
"\},"
225 for mproperty
, mprops
in mpropdefs
do
226 tpl
.add
"\"{mproperty}\
":["
227 for mpropdef
in mprops
do
228 var full_name
= mpropdef
.mclassdef
.mclass
.full_name
229 var cls_url
= mpropdef
.mclassdef
.mclass
.nitdoc_url
230 var def_url
= "{cls_url}#{mpropdef.mproperty.nitdoc_id}"
231 tpl
.add
"\{txt:\"{full_name}\",url
:\
"{def_url}\"\
},"
241 # Define page structure and properties
242 abstract class NitdocPage
244 private var ctx: ToolContext
245 private var model: Model
246 private var mainmodule: MModule
247 private var name_sorter = new MEntityNameSorter
249 # Render the page as a html template
250 fun render: Template do
252 if ctx.opt_shareurl.value != null then
253 shareurl = ctx.opt_shareurl.value.as(not null)
258 tpl.title = tpl_title
260 tpl.shareurl = shareurl
261 tpl.topmenu = tpl_topmenu
263 tpl.footer = ctx.opt_custom_footer.value
264 tpl.body_attrs.add(new TagAttribute("data-bootstrap-share
", shareurl))
265 tpl.sidebar = tpl_sidebar
268 var tracker_url = ctx.opt_piwik_tracker.value
269 var site_id = ctx.opt_piwik_site_id.value
270 if tracker_url != null and site_id != null then
271 tpl.scripts.add new TplPiwikScript(tracker_url, site_id)
277 fun page_url: String is abstract
279 # Build page template
280 fun tpl_page: TplPage is abstract
282 # Build page sidebar if any
283 fun tpl_sidebar: nullable TplSidebar do return null
285 # Build page title string
286 fun tpl_title: String do
287 if ctx.opt_custom_title.value != null then
288 return ctx.opt_custom_title.value.to_s
293 # Build top menu template
294 fun tpl_topmenu: TplTopMenu do
295 var topmenu = new TplTopMenu(page_url)
296 var brand = ctx.opt_custom_brand.value
297 if brand != null then
298 var tpl = new Template
299 tpl.add "<span
class='navbar-brand'>"
304 topmenu.add_link new TplLink("index
.html
", "Overview")
305 topmenu.add_link new TplLink("search
.html
", "Index")
309 # Build page content template
310 fun tpl_content is abstract
312 # Clickable graphviz image using dot format
313 # return null if no graph for this page
314 fun tpl_graph(dot: Buffer, name: String, title: nullable String): nullable TplArticle do
315 if ctx.opt_nodot.value then return null
316 var output_dir = ctx.output_dir
317 var file = new OFStream.open("{output_dir}/{name}.dot
")
320 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
; \
}")
321 var fmap = new IFStream.open("{output_dir}/{name}.map
")
322 var map = fmap.read_all
325 var article = new TplArticle("graph
")
327 if title != null then
328 article.title = title
329 alt = "alt
='{title}'"
331 article.css_classes.add "text-center
"
332 var content = new Template
333 content.add "<img src
='{name}.png' usemap
='#{name}' style
='margin:auto' {alt}/>"
335 article.content = content
339 # A (source) link template for a given location
340 fun tpl_showsource(location: nullable Location): nullable String
342 if location == null then return null
343 var source = ctx.opt_source.value
344 if source == null then
345 var url = location.file.filename.simplify_path
346 return "<a target
='_blank' title
='Show source' href
=\
"{url}\">View Source</a
>"
348 # THIS IS JUST UGLY ! (but there is no replace yet)
349 var x = source.split_with("%f
")
350 source = x.join(location.file.filename.simplify_path)
351 x = source.split_with("%l
")
352 source = x.join(location.line_start.to_s)
353 x = source.split_with("%L
")
354 source = x.join(location.line_end.to_s)
355 source = source.simplify_path
356 return "<a target
='_blank' title
='Show source' href
=\
"{source.to_s}\">View Source</a
>"
359 # MProject description template
360 fun tpl_mproject_article(mproject: MProject): TplArticle do
361 var article = mproject.tpl_article
362 article.subtitle = mproject.tpl_declaration
363 article.content = mproject.tpl_definition
364 if mproject.mdoc != null then
365 article.content = mproject.mdoc.tpl_short_comment
370 # MGroup description template
371 fun tpl_mgroup_article(mgroup: MGroup): TplArticle do
372 var article = mgroup.tpl_article
373 article.subtitle = mgroup.tpl_declaration
374 article.content = mgroup.tpl_definition
378 # MModule description template
379 fun tpl_mmodule_article(mmodule: MModule): TplArticle do
380 var article = mmodule.tpl_article
381 article.subtitle = mmodule.tpl_declaration
382 article.content = mmodule.tpl_definition
384 var intros = mmodule.intro_mclassdefs(ctx.min_visibility).to_a
385 if not intros.is_empty then
386 mainmodule.linearize_mclassdefs(intros)
387 var intros_art = new TplArticle.with_title("{mmodule.nitdoc_id}_intros
", "Introduces")
388 var intros_lst = new TplList.with_classes(["list-unstyled
", "list-labeled
"])
389 for mclassdef in intros do
390 intros_lst.add_li mclassdef.tpl_list_item
392 if not intros_lst.is_empty then
393 intros_art.content = intros_lst
394 article.add_child intros_art
397 var redefs = mmodule.redef_mclassdefs(ctx.min_visibility).to_a
398 if not redefs.is_empty then
399 mainmodule.linearize_mclassdefs(redefs)
400 var redefs_art = new TplArticle.with_title("{mmodule.nitdoc_id}_redefs
", "Redefines")
401 var redefs_lst = new TplList.with_classes(["list-unstyled
", "list-labeled
"])
402 for mclassdef in redefs do
403 redefs_lst.add_li mclassdef.tpl_list_item
405 if not redefs_lst.is_empty then
406 redefs_art.content = redefs_lst
407 article.add_child redefs_art
413 # MClassDef description template
414 fun tpl_mclass_article(mclass: MClass, mclassdefs: Array[MClassDef]): TplArticle do
415 var article = mclass.tpl_article
416 if not mclassdefs.has(mclass.intro) then
418 var intro_article = mclass.intro.tpl_short_article
419 intro_article.source_link = tpl_showsource(mclass.intro.location)
420 article.add_child intro_article
422 mainmodule.linearize_mclassdefs(mclassdefs)
423 for mclassdef in mclassdefs do
424 # add mclassdef full description
425 var redef_article = mclassdef.tpl_article
426 redef_article.source_link = tpl_showsource(mclassdef.location)
427 article.add_child redef_article
429 var intros = new TplArticle.with_title("{mclassdef.nitdoc_id}_intros
", "Introduces")
430 var intros_lst = new TplList.with_classes(["list-unstyled
", "list-labeled
"])
431 for mpropdef in mclassdef.collect_intro_mpropdefs(ctx.min_visibility) do
432 intros_lst.add_li mpropdef.tpl_list_item
434 if not intros_lst.is_empty then
435 intros.content = intros_lst
436 redef_article.add_child intros
438 var redefs = new TplArticle.with_title("{mclassdef.nitdoc_id}_redefs
", "Redefines")
439 var redefs_lst = new TplList.with_classes(["list-unstyled
", "list-labeled
"])
440 for mpropdef in mclassdef.collect_redef_mpropdefs(ctx.min_visibility) do
441 redefs_lst.add_li mpropdef.tpl_list_item
443 if not redefs_lst.is_empty then
444 redefs.content = redefs_lst
445 redef_article.add_child redefs
451 # MClassDef description template
452 fun tpl_mclassdef_article(mclassdef: MClassDef): TplArticle do
453 var article = mclassdef.tpl_article
454 if mclassdef.is_intro then article.content = null
455 article.source_link = tpl_showsource(mclassdef.location)
459 # MProp description template
461 # `main_mpropdef`: The most important mpropdef to display
462 # `local_mpropdefs`: List of other locally defined mpropdefs to display
463 # `lin`: full linearization from local_mpropdefs to intro (displayed in redef tree)
464 fun tpl_mprop_article(main_mpropdef: MPropDef, local_mpropdefs: Array[MPropDef],
465 lin: Array[MPropDef]): TplArticle do
466 var mprop = main_mpropdef.mproperty
467 var article = new TplArticle(mprop.nitdoc_id)
468 var title = new Template
469 title.add mprop.tpl_icon
470 title.add "<span id
='{main_mpropdef.nitdoc_id}'></span
>"
471 if main_mpropdef.is_intro then
472 title.add mprop.tpl_link
473 title.add mprop.intro.tpl_signature
475 var cls_url = mprop.intro.mclassdef.mclass.nitdoc_url
476 var def_url = "{cls_url}#{mprop.nitdoc_id}"
477 var lnk
= new TplLink.with_title
(def_url
, mprop
.name
, "Go to introduction")
481 article
.title
= title
482 article
.title_classes
.add
"signature"
483 article
.summary_title
= "{mprop.nitdoc_name}"
484 article
.subtitle
= main_mpropdef
.tpl_namespace
485 if main_mpropdef
.mdoc
!= null then
486 article
.content
= main_mpropdef
.mdoc
.tpl_comment
488 var subarticle
= new TplArticle("{main_mpropdef.nitdoc_id}_redefs")
489 # Add redef in same `MClass`
490 if local_mpropdefs
.length
> 1 then
491 for mpropdef
in local_mpropdefs
do
492 if mpropdef
== main_mpropdef
then continue
493 var redef_article
= new TplArticle("{mpropdef.nitdoc_id}")
494 var redef_title
= new Template
495 redef_title
.add
"also redef in "
496 redef_title
.add mpropdef
.tpl_namespace
497 redef_article
.title
= redef_title
498 redef_article
.title_classes
.add
"signature info"
499 redef_article
.css_classes
.add
"nospace"
500 var redef_content
= new Template
501 if mpropdef
.mdoc
!= null then
502 redef_content
.add mpropdef
.mdoc
.tpl_comment
504 redef_article
.content
= redef_content
505 subarticle
.add_child redef_article
509 if lin
.length
> 1 then
510 var lin_article
= new TplArticle("{main_mpropdef.nitdoc_id}_lin")
511 lin_article
.title
= "Inheritance"
512 var lst
= new TplList.with_classes
(["list-unstyled", "list-labeled"])
513 for mpropdef
in lin
do
514 lst
.add_li mpropdef
.tpl_inheritance_item
516 lin_article
.content
= lst
517 subarticle
.add_child lin_article
519 article
.add_child subarticle
523 # MProperty description template
524 fun tpl_mpropdef_article
(mpropdef
: MPropDef): TplArticle do
525 var article
= mpropdef
.tpl_article
526 article
.source_link
= tpl_showsource
(mpropdef
.location
)
532 # Display a list of modules contained in program
536 private var page
= new TplPage
537 redef fun tpl_page
do return page
539 private var sidebar
= new TplSidebar
540 redef fun tpl_sidebar
do return sidebar
542 redef fun tpl_title
do
543 if ctx
.opt_custom_title
.value
!= null then
544 return ctx
.opt_custom_title
.value
.to_s
550 redef fun page_url
do return "index.html"
553 private fun tpl_intro
: TplSection do
554 var section
= new TplSection.with_title
("overview", tpl_title
)
555 var article
= new TplArticle("intro")
556 if ctx
.opt_custom_intro
.value
!= null then
557 article
.content
= ctx
.opt_custom_intro
.value
.to_s
559 section
.add_child article
564 private fun tpl_projects
(section
: TplSection) do
566 var mprojects
= model
.mprojects
.to_a
567 var sorter
= new MConcernRankSorter
568 sorter
.sort mprojects
569 var ssection
= new TplSection.with_title
("projects", "Projects")
570 for mproject
in mprojects
do
571 ssection
.add_child tpl_mproject_article
(mproject
)
573 section
.add_child ssection
576 redef fun tpl_content
do
579 tpl_page
.add_section top
584 # Display a list of modules, classes and properties
588 private var page
= new TplPage
589 redef fun tpl_page
do return page
591 redef fun tpl_title
do return "Index"
593 redef fun page_url
do return "search.html"
595 redef fun tpl_content
do
596 var tpl
= new TplSearchPage("search_all")
597 var section
= new TplSection("search")
601 for mmodule
in modules_list
do
602 tpl
.modules
.add mmodule
.tpl_link
605 for mclass
in classes_list
do
606 tpl
.classes
.add mclass
.tpl_link
609 for mproperty
in mprops_list
do
611 m
.add mproperty
.intro
.tpl_link
613 m
.add mproperty
.intro
.mclassdef
.mclass
.tpl_link
617 section
.add_child tpl
618 tpl_page
.add_section section
621 # Extract mmodule list to display (sorted by name)
622 private fun modules_list
: Array[MModule] do
623 var sorted
= new Array[MModule]
624 for mmodule
in model
.mmodule_importation_hierarchy
do
625 if mmodule
.is_fictive
then continue
628 name_sorter
.sort
(sorted
)
632 # Extract mclass list to display (sorted by name)
633 private fun classes_list
: Array[MClass] do
634 var sorted
= new Array[MClass]
635 for mclass
in model
.mclasses
do
636 if mclass
.visibility
< ctx
.min_visibility
then continue
639 name_sorter
.sort
(sorted
)
643 # Extract mproperty list to display (sorted by name)
644 private fun mprops_list
: Array[MProperty] do
645 var sorted
= new Array[MProperty]
646 for mproperty
in model
.mproperties
do
647 if mproperty
.visibility
< ctx
.min_visibility
then continue
648 if mproperty
isa MAttribute then continue
651 name_sorter
.sort
(sorted
)
657 # Display a flattened view of the group
661 private var mgroup
: MGroup
663 private var concerns
: ConcernsTree is noinit
664 private var intros
: Set[MClass] is noinit
665 private var redefs
: Set[MClass] is noinit
668 self.concerns
= model
.concerns_tree
(mgroup
.collect_mmodules
)
669 self.concerns
.sort_with
(new MConcernRankSorter)
670 self.intros
= mgroup
.in_nesting_intro_mclasses
(ctx
.min_visibility
)
671 var redefs
= new HashSet[MClass]
672 for rdef
in mgroup
.in_nesting_redef_mclasses
(ctx
.min_visibility
) do
673 if intros
.has
(rdef
) then continue
679 private var page
= new TplPage
680 redef fun tpl_page
do return page
682 private var sidebar
= new TplSidebar
683 redef fun tpl_sidebar
do return sidebar
685 redef fun tpl_title
do return mgroup
.nitdoc_name
687 redef fun page_url
do return mgroup
.nitdoc_url
689 redef fun tpl_topmenu
do
691 var mproject
= mgroup
.mproject
692 if not mgroup
.is_root
then
693 topmenu
.add_link
new TplLink(mproject
.nitdoc_url
, mproject
.nitdoc_name
)
695 topmenu
.add_link
new TplLink(page_url
, mproject
.nitdoc_name
)
699 # Class list to display in sidebar
700 fun tpl_sidebar_mclasses
do
701 var mclasses
= new HashSet[MClass]
702 mclasses
.add_all intros
703 mclasses
.add_all redefs
704 if mclasses
.is_empty
then return
705 var list
= new TplList.with_classes
(["list-unstyled", "list-labeled"])
707 var sorted
= mclasses
.to_a
708 name_sorter
.sort
(sorted
)
709 for mclass
in sorted
do
710 list
.add_li tpl_sidebar_item
(mclass
)
712 tpl_sidebar
.boxes
.add
new TplSideBox.with_content
("All classes", list
)
715 private fun tpl_sidebar_item
(def
: MClass): TplListItem do
716 var classes
= def
.intro
.tpl_css_classes
.to_a
717 if intros
.has
(def
) then
722 var lnk
= new Template
723 lnk
.add
new TplLabel.with_classes
(classes
)
725 return new TplListItem.with_content
(lnk
)
729 private fun tpl_intro
: TplSection do
730 var section
= new TplSection.with_title
("top", tpl_title
)
731 var article
= new TplArticle("intro")
733 if mgroup
.is_root
then
734 section
.subtitle
= mgroup
.mproject
.tpl_declaration
735 article
.content
= mgroup
.mproject
.tpl_definition
737 section
.subtitle
= mgroup
.tpl_declaration
738 article
.content
= mgroup
.tpl_definition
740 section
.add_child article
744 private fun tpl_concerns
(section
: TplSection) do
745 if concerns
.is_empty
then return
746 section
.add_child
new TplArticle.with_content
("concerns", "Concerns", concerns
.to_tpl
)
749 private fun tpl_groups
(parent
: TplSection) do
750 var lst
= concerns
.to_a
752 for mentity
in lst
do
753 if mentity
isa MProject then
754 section
.add_child
new TplSection(mentity
.nitdoc_id
)
755 else if mentity
isa MGroup then
756 section
.add_child
new TplSection(mentity
.nitdoc_id
)
757 else if mentity
isa MModule then
758 section
.add_child tpl_mmodule_article
(mentity
)
763 redef fun tpl_content
do
768 tpl_page
.add_section top
771 private fun sort_by_mclass
(mclassdefs
: Collection[MClassDef]): Map[MClass, Set[MClassDef]] do
772 var map
= new HashMap[MClass, Set[MClassDef]]
773 for mclassdef
in mclassdefs
do
774 var mclass
= mclassdef
.mclass
775 if not map
.has_key
(mclass
) then map
[mclass
] = new HashSet[MClassDef]
776 map
[mclass
].add mclassdef
783 # Display the list of introduced and redefined classes in module
787 private var mmodule
: MModule
788 private var concerns
: ConcernsTree is noinit
789 private var mclasses2mdefs
: Map[MClass, Set[MClassDef]] is noinit
790 private var mmodules2mclasses
: Map[MModule, Set[MClass]] is noinit
794 var mclassdefs
= new HashSet[MClassDef]
795 mclassdefs
.add_all mmodule
.intro_mclassdefs
(ctx
.min_visibility
)
796 mclassdefs
.add_all mmodule
.redef_mclassdefs
(ctx
.min_visibility
)
797 self.mclasses2mdefs
= sort_by_mclass
(mclassdefs
)
798 self.mmodules2mclasses
= group_by_mmodule
(mclasses2mdefs
.keys
)
799 self.concerns
= model
.concerns_tree
(mmodules2mclasses
.keys
)
801 mmodule
.mgroup
.mproject
.booster_rank
= -1000
802 mmodule
.mgroup
.booster_rank
= -1000
803 mmodule
.booster_rank
= -1000
804 self.concerns
.sort_with
(new MConcernRankSorter)
805 mmodule
.mgroup
.mproject
.booster_rank
= 0
806 mmodule
.mgroup
.booster_rank
= 0
807 mmodule
.booster_rank
= 0
810 private var page
= new TplPage
811 redef fun tpl_page
do return page
813 private var sidebar
= new TplSidebar
814 redef fun tpl_sidebar
do return sidebar
816 redef fun tpl_title
do return mmodule
.nitdoc_name
817 redef fun page_url
do return mmodule
.nitdoc_url
819 redef fun tpl_topmenu
do
821 var mproject
= mmodule
.mgroup
.mproject
822 topmenu
.add_link
new TplLink(mproject
.nitdoc_url
, mproject
.nitdoc_name
)
823 topmenu
.add_link
new TplLink(page_url
, mmodule
.nitdoc_name
)
827 # Class list to display in sidebar
828 fun tpl_sidebar_mclasses
do
829 var mclasses
= new HashSet[MClass]
830 mclasses
.add_all mmodule
.filter_intro_mclasses
(ctx
.min_visibility
)
831 mclasses
.add_all mmodule
.filter_redef_mclasses
(ctx
.min_visibility
)
832 if mclasses
.is_empty
then return
833 var list
= new TplList.with_classes
(["list-unstyled", "list-labeled"])
835 var sorted
= mclasses
.to_a
836 name_sorter
.sort
(sorted
)
837 for mclass
in sorted
do
838 list
.add_li tpl_sidebar_item
(mclass
)
840 tpl_sidebar
.boxes
.add
new TplSideBox.with_content
("All classes", list
)
843 private fun tpl_sidebar_item
(def
: MClass): TplListItem do
844 var classes
= def
.intro
.tpl_css_classes
.to_a
845 if def
.intro_mmodule
== mmodule
then
850 var lnk
= new Template
851 lnk
.add
new TplLabel.with_classes
(classes
)
853 return new TplListItem.with_content
(lnk
)
857 private fun tpl_intro
: TplSection do
858 var section
= new TplSection.with_title
("top", tpl_title
)
859 section
.subtitle
= mmodule
.tpl_declaration
861 var article
= new TplArticle("intro")
862 var def
= mmodule
.tpl_definition
863 var location
= mmodule
.location
864 article
.source_link
= tpl_showsource
(location
)
865 article
.content
= def
866 section
.add_child article
870 # inheritance section
871 private fun tpl_inheritance
(parent
: TplSection) do
872 # Extract relevent modules
873 var imports
= mmodule
.in_importation
.greaters
874 if imports
.length
> 10 then imports
= mmodule
.in_importation
.direct_greaters
875 var clients
= mmodule
.in_importation
.smallers
876 if clients
.length
> 10 then clients
= mmodule
.in_importation
.direct_smallers
879 var section
= new TplSection.with_title
("dependencies", "Dependencies")
882 var mmodules
= new HashSet[MModule]
883 mmodules
.add_all mmodule
.in_nesting
.direct_greaters
884 mmodules
.add_all imports
885 if clients
.length
< 10 then mmodules
.add_all clients
887 var graph
= tpl_dot
(mmodules
)
888 if graph
!= null then section
.add_child graph
891 var lst
= new Array[MModule]
892 for dep
in imports
do
893 if dep
.is_fictive
then continue
894 if dep
== mmodule
then continue
897 if not lst
.is_empty
then
899 section
.add_child tpl_list
("imports", "Imports", lst
)
903 lst
= new Array[MModule]
904 for dep
in clients
do
905 if dep
.is_fictive
then continue
906 if dep
== mmodule
then continue
909 if not lst
.is_empty
then
911 section
.add_child tpl_list
("clients", "Clients", lst
)
914 parent
.add_child section
917 private fun tpl_list
(id
: String, title
: String, mmodules
: Array[MModule]): TplArticle do
918 var article
= new TplArticle.with_title
(id
, title
)
919 var list
= new TplList.with_classes
(["list-unstyled", "list-definition"])
920 for mmodule
in mmodules
do list
.elts
.add mmodule
.tpl_list_item
921 article
.content
= list
925 private fun tpl_concerns
(parent
: TplSection) do
926 if concerns
.is_empty
then return
927 parent
.add_child
new TplArticle.with_content
("concerns", "Concerns", concerns
.to_tpl
)
930 private fun tpl_mclasses
(parent
: TplSection) do
931 for mentity
in concerns
do
932 if mentity
isa MProject then
933 parent
.add_child
new TplSection(mentity
.nitdoc_id
)
934 else if mentity
isa MGroup then
935 parent
.add_child
new TplSection(mentity
.nitdoc_id
)
936 else if mentity
isa MModule then
937 var section
= new TplSection(mentity
.nitdoc_id
)
938 var title
= new Template
939 if mentity
== mmodule
then
941 section
.summary_title
= "in {mentity.nitdoc_name}"
944 section
.summary_title
= "from {mentity.nitdoc_name}"
946 title
.add mentity
.tpl_namespace
947 section
.title
= title
949 var mclasses
= mmodules2mclasses
[mentity
].to_a
950 name_sorter
.sort
(mclasses
)
951 for mclass
in mclasses
do
952 section
.add_child tpl_mclass_article
(mclass
, mclasses2mdefs
[mclass
].to_a
)
954 parent
.add_child section
959 private fun group_by_mmodule
(mclasses
: Collection[MClass]): Map[MModule, Set[MClass]] do
960 var res
= new HashMap[MModule, Set[MClass]]
961 for mclass
in mclasses
do
962 var mmodule
= mclass
.intro_mmodule
963 if not res
.has_key
(mmodule
) then
964 res
[mmodule
] = new HashSet[MClass]
966 res
[mmodule
].add
(mclass
)
971 redef fun tpl_content
do
977 tpl_page
.add_section top
980 # Genrate dot hierarchy for class inheritance
981 fun tpl_dot
(mmodules
: Collection[MModule]): nullable TplArticle do
982 var poset
= new POSet[MModule]
983 for mmodule
in mmodules
do
984 if mmodule
.is_fictive
then continue
985 poset
.add_node mmodule
986 for omodule
in mmodules
do
987 if mmodule
.is_fictive
then continue
988 poset
.add_node mmodule
989 if mmodule
.in_importation
< omodule
then
990 poset
.add_edge
(mmodule
, omodule
)
995 var op
= new RopeBuffer
996 var name
= "dep_module_{mmodule.nitdoc_id}"
997 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")
998 for mmodule
in poset
do
999 if mmodule
== self.mmodule
then
1000 op
.append
("\"{mmodule.name}\
"[shape=box,margin=0.03];\n")
1002 op
.append
("\"{mmodule.name}\
"[URL=\"{mmodule.nitdoc_url}\
"];\n")
1004 for omodule
in poset
[mmodule
].direct_greaters
do
1005 op
.append
("\"{mmodule.name}\
"->\"{omodule.name}\
";\n")
1009 return tpl_graph
(op
, name
, null)
1012 private fun sort_by_mclass
(mclassdefs
: Collection[MClassDef]): Map[MClass, Set[MClassDef]] do
1013 var map
= new HashMap[MClass, Set[MClassDef]]
1014 for mclassdef
in mclassdefs
do
1015 var mclass
= mclassdef
.mclass
1016 if not map
.has_key
(mclass
) then map
[mclass
] = new HashSet[MClassDef]
1017 map
[mclass
].add mclassdef
1024 # Display a list properties defined or redefined for this class
1028 private var mclass
: MClass
1029 private var concerns
: ConcernsTree is noinit
1030 private var mprops2mdefs
: Map[MProperty, Set[MPropDef]] is noinit
1031 private var mmodules2mprops
: Map[MModule, Set[MProperty]] is noinit
1034 var mpropdefs
= new HashSet[MPropDef]
1035 mpropdefs
.add_all mclass
.intro_mpropdefs
(ctx
.min_visibility
)
1036 mpropdefs
.add_all mclass
.redef_mpropdefs
(ctx
.min_visibility
)
1037 self.mprops2mdefs
= sort_by_mproperty
(mpropdefs
)
1038 self.mmodules2mprops
= sort_by_mmodule
(mprops2mdefs
.keys
)
1039 self.concerns
= model
.concerns_tree
(mmodules2mprops
.keys
)
1040 self.concerns
.sort_with
(new MConcernRankSorter)
1043 private var page
= new TplPage
1044 redef fun tpl_page
do return page
1046 private var sidebar
= new TplSidebar
1047 redef fun tpl_sidebar
do return sidebar
1049 redef fun tpl_title
do return "{mclass.nitdoc_name}{mclass.tpl_signature.write_to_string}"
1050 redef fun page_url
do return mclass
.nitdoc_url
1052 redef fun tpl_topmenu
do
1054 var mproject
= mclass
.intro_mmodule
.mgroup
.mproject
1055 topmenu
.add_link
new TplLink("{mproject.nitdoc_url}", "{mproject.nitdoc_name}")
1056 topmenu
.add_link
new TplLink(page_url
, mclass
.nitdoc_name
)
1060 # Property list to display in sidebar
1061 fun tpl_sidebar_properties
do
1062 var kind_map
= sort_by_kind
(mclass_inherited_mprops
)
1063 var summary
= new TplList.with_classes
(["list-unstyled"])
1065 tpl_sidebar_list
("Virtual types", kind_map
["type"].to_a
, summary
)
1066 tpl_sidebar_list
("Constructors", kind_map
["init"].to_a
, summary
)
1067 tpl_sidebar_list
("Methods", kind_map
["fun"].to_a
, summary
)
1068 tpl_sidebar
.boxes
.add
new TplSideBox.with_content
("All properties", summary
)
1071 private fun tpl_sidebar_list
(name
: String, mprops
: Array[MProperty], summary
: TplList) do
1072 if mprops
.is_empty
then return
1073 name_sorter
.sort
(mprops
)
1074 var entry
= new TplListItem.with_content
(name
)
1075 var list
= new TplList.with_classes
(["list-unstyled", "list-labeled"])
1076 for mprop
in mprops
do
1077 list
.add_li tpl_sidebar_item
(mprop
)
1080 summary
.elts
.add entry
1083 private fun tpl_sidebar_item
(mprop
: MProperty): TplListItem do
1084 var classes
= mprop
.intro
.tpl_css_classes
.to_a
1085 if not mprops2mdefs
.has_key
(mprop
) then
1086 classes
.add
"inherit"
1087 var cls_url
= mprop
.intro
.mclassdef
.mclass
.nitdoc_url
1088 var def_url
= "{cls_url}#{mprop.nitdoc_id}"
1089 var lnk
= new TplLink(def_url
, mprop
.name
)
1090 if mprop
.intro
.mdoc
!= null then lnk
.title
= mprop
.intro
.mdoc
.short_comment
1091 var item
= new Template
1092 item
.add
new TplLabel.with_classes
(classes
)
1094 return new TplListItem.with_content
(item
)
1096 var defs
= mprops2mdefs
[mprop
]
1097 if defs
.has
(mprop
.intro
) then
1102 var lnk
= new Template
1103 lnk
.add
new TplLabel.with_classes
(classes
)
1104 lnk
.add mprop
.tpl_anchor
1105 return new TplListItem.with_content
(lnk
)
1108 private fun tpl_intro
: TplSection do
1109 var section
= new TplSection.with_title
("top", tpl_title
)
1110 section
.subtitle
= mclass
.intro
.tpl_declaration
1111 var article
= new TplArticle("comment")
1112 if mclass
.mdoc
!= null then
1113 article
.content
= mclass
.mdoc
.tpl_comment
1115 section
.add_child article
1119 private fun tpl_concerns
(parent
: TplSection) do
1121 var section
= new TplSection.with_title
("intro", "Introduction")
1122 section
.summary_title
= "Introduction"
1123 section
.add_child tpl_mclassdef_article
(mclass
.intro
)
1124 parent
.add_child section
1126 if concerns
.is_empty
then return
1127 parent
.add_child
new TplArticle.with_content
("concerns", "Concerns", concerns
.to_tpl
)
1130 private fun tpl_inheritance
(parent
: TplSection) do
1132 var hparents
= new HashSet[MClass]
1133 for c
in mclass
.in_hierarchy
(mainmodule
).direct_greaters
do
1134 if c
.visibility
< ctx
.min_visibility
then continue
1139 var hancestors
= new HashSet[MClass]
1140 for c
in mclass
.in_hierarchy
(mainmodule
).greaters
do
1141 if c
== mclass
then continue
1142 if c
.visibility
< ctx
.min_visibility
then continue
1143 if hparents
.has
(c
) then continue
1148 var hchildren
= new HashSet[MClass]
1149 for c
in mclass
.in_hierarchy
(mainmodule
).direct_smallers
do
1150 if c
.visibility
< ctx
.min_visibility
then continue
1155 var hdescendants
= new HashSet[MClass]
1156 for c
in mclass
.in_hierarchy
(mainmodule
).smallers
do
1157 if c
== mclass
then continue
1158 if c
.visibility
< ctx
.min_visibility
then continue
1159 if hchildren
.has
(c
) then continue
1164 var section
= new TplSection.with_title
("inheritance", "Inheritance")
1167 var mclasses
= new HashSet[MClass]
1168 mclasses
.add_all hancestors
1169 mclasses
.add_all hparents
1170 mclasses
.add_all hchildren
1171 mclasses
.add_all hdescendants
1173 var graph
= tpl_dot
(mclasses
)
1174 if graph
!= null then section
.add_child graph
1177 if not hparents
.is_empty
then
1178 var lst
= hparents
.to_a
1179 name_sorter
.sort lst
1180 section
.add_child tpl_list
("parents", "Parents", lst
)
1184 if not hancestors
.is_empty
then
1185 var lst
= hancestors
.to_a
1186 name_sorter
.sort lst
1187 section
.add_child tpl_list
("ancestors", "Ancestors", lst
)
1191 if not hchildren
.is_empty
then
1192 var lst
= hchildren
.to_a
1193 name_sorter
.sort lst
1194 section
.add_child tpl_list
("children", "Children", lst
)
1198 if not hdescendants
.is_empty
then
1199 var lst
= hdescendants
.to_a
1200 name_sorter
.sort lst
1201 section
.add_child tpl_list
("descendants", "Descendants", lst
)
1204 parent
.add_child section
1207 private fun tpl_list
(id
: String, title
: String, elts
: Array[MClass]): TplArticle do
1208 var article
= new TplArticle.with_title
(id
, title
)
1209 if elts
.length
> 20 then
1210 var tpl
= new Template
1213 if e
!= elts
.last
then tpl
.add
", "
1215 article
.content
= tpl
1217 var list
= new TplList.with_classes
(["list-unstyled", "list-definition"])
1218 for elt
in elts
do list
.elts
.add elt
.tpl_list_item
1219 article
.content
= list
1224 private fun tpl_properties
(parent
: TplSection) do
1225 var lst
= concerns
.to_a
1226 for mentity
in lst
do
1227 if mentity
isa MProject then
1228 parent
.add_child
new TplSection(mentity
.nitdoc_id
)
1229 else if mentity
isa MGroup then
1230 parent
.add_child
new TplSection(mentity
.nitdoc_id
)
1231 else if mentity
isa MModule then
1232 var section
= new TplSection(mentity
.nitdoc_id
)
1233 var title
= new Template
1235 title
.add mentity
.tpl_namespace
1236 section
.title
= title
1237 section
.summary_title
= "in {mentity.nitdoc_name}"
1240 var mprops
= mmodules2mprops
[mentity
]
1241 var kind_map
= sort_by_kind
(mprops
)
1244 for article
in tpl_mproperty_articles
(kind_map
, "type") do
1245 section
.add_child article
1248 for article
in tpl_mproperty_articles
(kind_map
, "init") do
1249 section
.add_child article
1252 for article
in tpl_mproperty_articles
(kind_map
, "fun") do
1253 section
.add_child article
1255 parent
.add_child section
1260 private fun tpl_mproperty_articles
(kind_map
: Map[String, Set[MProperty]],
1261 kind_name
: String): Sequence[TplArticle] do
1262 var articles
= new List[TplArticle]
1263 var elts
= kind_map
[kind_name
].to_a
1264 name_sorter
.sort
(elts
)
1266 var local_defs
= mprops2mdefs
[elt
]
1267 # var all_defs = elt.mpropdefs
1268 var all_defs
= new HashSet[MPropDef]
1269 for local_def
in local_defs
do
1270 all_defs
.add local_def
1271 var mpropdef
= local_def
1272 while not mpropdef
.is_intro
do
1273 mpropdef
= mpropdef
.lookup_next_definition
(mainmodule
, mpropdef
.mclassdef
.bound_mtype
)
1274 all_defs
.add mpropdef
1277 var loc_lin
= local_defs
.to_a
1278 mainmodule
.linearize_mpropdefs
(loc_lin
)
1279 var all_lin
= all_defs
.to_a
1280 mainmodule
.linearize_mpropdefs
(all_lin
)
1281 articles
.add tpl_mprop_article
(loc_lin
.first
, loc_lin
, all_lin
)
1286 redef fun tpl_content
do
1287 tpl_sidebar_properties
1289 tpl_inheritance
(top
)
1292 tpl_page
.add_section top
1295 private fun sort_by_mproperty
(mpropdefs
: Collection[MPropDef]): Map[MProperty, Set[MPropDef]] do
1296 var map
= new HashMap[MProperty, Set[MPropDef]]
1297 for mpropdef
in mpropdefs
do
1298 var mproperty
= mpropdef
.mproperty
1299 if not map
.has_key
(mproperty
) then map
[mproperty
] = new HashSet[MPropDef]
1300 map
[mproperty
].add mpropdef
1305 private fun sort_by_mmodule
(mprops
: Collection[MProperty]): Map[MModule, Set[MProperty]] do
1306 var map
= new HashMap[MModule, Set[MProperty]]
1307 for mprop
in mprops
do
1308 var mpropdefs
= mprops2mdefs
[mprop
].to_a
1309 mainmodule
.linearize_mpropdefs
(mpropdefs
)
1310 var mmodule
= mpropdefs
.first
.mclassdef
.mmodule
1311 if not map
.has_key
(mmodule
) then map
[mmodule
] = new HashSet[MProperty]
1312 map
[mmodule
].add mprop
1317 private fun sort_by_kind
(mprops
: Collection[MProperty]): Map[String, Set[MProperty]] do
1318 var map
= new HashMap[String, Set[MProperty]]
1319 map
["type"] = new HashSet[MProperty]
1320 map
["init"] = new HashSet[MProperty]
1321 map
["fun"] = new HashSet[MProperty]
1322 for mprop
in mprops
do
1323 if mprop
isa MVirtualTypeProp then
1324 map
["type"].add mprop
1325 else if mprop
isa MMethod then
1326 if mprop
.is_init
then
1327 map
["init"].add mprop
1329 map
["fun"].add mprop
1336 private fun mclass_inherited_mprops
: Set[MProperty] do
1337 var res
= new HashSet[MProperty]
1338 var local
= mclass
.local_mproperties
(ctx
.min_visibility
)
1339 for mprop
in mclass
.inherited_mproperties
(mainmodule
, ctx
.min_visibility
) do
1340 if local
.has
(mprop
) then continue
1341 #if mprop isa MMethod and mprop.is_init then continue
1342 if mprop
.intro
.mclassdef
.mclass
.name
== "Object" and
1343 (mprop
.visibility
== protected_visibility
or
1344 mprop
.intro
.mclassdef
.mmodule
.name
!= "kernel") then continue
1351 private fun collect_mmodules
(mprops
: Collection[MProperty]): Set[MModule] do
1352 var res
= new HashSet[MModule]
1353 for mprop
in mprops
do
1354 if mprops2mdefs
.has_key
(mprop
) then
1355 for mpropdef
in mprops2mdefs
[mprop
] do res
.add mpropdef
.mclassdef
.mmodule
1361 # Generate dot hierarchy for classes
1362 fun tpl_dot
(mclasses
: Collection[MClass]): nullable TplArticle do
1363 var poset
= new POSet[MClass]
1365 for mclass
in mclasses
do
1366 poset
.add_node mclass
1367 for oclass
in mclasses
do
1368 if mclass
== oclass
then continue
1369 poset
.add_node oclass
1370 if mclass
.in_hierarchy
(mainmodule
) < oclass
then
1371 poset
.add_edge
(mclass
, oclass
)
1376 var op
= new RopeBuffer
1377 var name
= "dep_class_{mclass.nitdoc_id}"
1378 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")
1379 var classes
= poset
.to_a
1380 var todo
= new Array[MClass]
1381 var done
= new HashSet[MClass]
1382 mainmodule
.linearize_mclasses
(classes
)
1383 if not classes
.is_empty
then todo
.add classes
.first
1384 while not todo
.is_empty
do
1386 if done
.has
(c
) then continue
1389 op
.append
("\"{c.name}\
"[shape=box,margin=0.03];\n")
1391 op
.append
("\"{c.name}\
"[URL=\"{c.nitdoc_url}\
"];\n")
1393 var smallers
= poset
[c
].direct_smallers
1394 if smallers
.length
< 10 then
1395 for c2
in smallers
do
1396 op
.append
("\"{c2.name}\
"->\"{c.name}\
";\n")
1398 todo
.add_all smallers
1400 op
.append
("\"...\
"->\"{c.name}\
";\n")
1404 return tpl_graph
(op
, name
, null)
1409 class NitdocProperty
1412 private var mproperty
: MProperty
1413 private var concerns
: ConcernsTree is noinit
1414 private var mmodules2mdefs
: Map[MModule, Set[MPropDef]] is noinit
1417 self.mproperty
= mproperty
1418 self.mmodules2mdefs
= sort_by_mmodule
(collect_mpropdefs
)
1419 self.concerns
= model
.concerns_tree
(mmodules2mdefs
.keys
)
1420 self.concerns
.sort_with
(new MConcernRankSorter)
1423 private fun collect_mpropdefs
: Set[MPropDef] do
1424 var res
= new HashSet[MPropDef]
1425 for mpropdef
in mproperty
.mpropdefs
do
1426 if not mpropdef
.is_intro
then res
.add mpropdef
1431 private var page
= new TplPage
1432 redef fun tpl_page
do return page
1434 private var sidebar
= new TplSidebar
1435 redef fun tpl_sidebar
do return sidebar
1437 redef fun tpl_title
do
1438 return "{mproperty.nitdoc_name}{mproperty.tpl_signature.write_to_string}"
1441 redef fun page_url
do return mproperty
.nitdoc_url
1443 redef fun tpl_topmenu
do
1445 var mmodule
= mproperty
.intro_mclassdef
.mmodule
1446 var mproject
= mmodule
.mgroup
.mproject
1447 var mclass
= mproperty
.intro_mclassdef
.mclass
1448 topmenu
.add_link
new TplLink("{mproject.nitdoc_url}", "{mproject.nitdoc_name}")
1449 topmenu
.add_link
new TplLink("{mclass.nitdoc_url}", "{mclass.nitdoc_name}")
1450 topmenu
.add_link
new TplLink(page_url
, mproperty
.nitdoc_name
)
1454 private fun tpl_intro
: TplSection do
1455 var title
= new Template
1456 title
.add mproperty
.nitdoc_name
1457 title
.add mproperty
.intro
.tpl_signature
1458 var section
= new TplSection.with_title
("top", title
)
1459 section
.subtitle
= mproperty
.tpl_namespace
1460 section
.summary_title
= mproperty
.nitdoc_name
1464 private fun tpl_properties
(parent
: TplSection) do
1466 var section
= new TplSection.with_title
("intro", "Introduction")
1467 section
.summary_title
= "Introduction"
1468 section
.add_child tpl_mpropdef_article
(mproperty
.intro
)
1469 parent
.add_child section
1472 if concerns
.is_empty
then return
1473 parent
.add_child
new TplArticle.with_content
("Concerns", "Concerns", concerns
.to_tpl
)
1476 var lst
= concerns
.to_a
1477 for mentity
in lst
do
1478 if mentity
isa MProject then
1479 parent
.add_child
new TplSection(mentity
.nitdoc_id
)
1480 else if mentity
isa MGroup then
1481 parent
.add_child
new TplSection(mentity
.nitdoc_id
)
1482 else if mentity
isa MModule then
1483 var ssection
= new TplSection(mentity
.nitdoc_id
)
1484 var title
= new Template
1486 title
.add mentity
.tpl_namespace
1487 ssection
.title
= title
1488 ssection
.summary_title
= "in {mentity.nitdoc_name}"
1491 var mpropdefs
= mmodules2mdefs
[mentity
].to_a
1492 name_sorter
.sort
(mpropdefs
)
1493 for mpropdef
in mpropdefs
do
1494 ssection
.add_child tpl_mpropdef_article
(mpropdef
)
1496 parent
.add_child ssection
1501 redef fun tpl_content
do
1504 tpl_page
.add_section top
1507 private fun sort_by_mmodule
(mpropdefs
: Collection[MPropDef]): Map[MModule, Set[MPropDef]] do
1508 var map
= new HashMap[MModule, Set[MPropDef]]
1509 for mpropdef
in mpropdefs
do
1510 var mmodule
= mpropdef
.mclassdef
.mmodule
1511 if not map
.has_key
(mmodule
) then map
[mmodule
] = new HashSet[MPropDef]
1512 map
[mmodule
].add mpropdef