From: Jean Privat Date: Thu, 10 Sep 2015 18:53:52 +0000 (-0400) Subject: Merge: nitcatalog: content and options X-Git-Tag: v0.7.8~33 X-Git-Url: http://nitlanguage.org?hp=7f6510358a43d98bdb887e7b0f43b46e4bf8b263 Merge: nitcatalog: content and options Two improvements: * content list (example: see end of page , section *content*) * command-line options Pull-Request: #1699 Reviewed-by: Lucas Bajolet Reviewed-by: Alexis Laferrière --- diff --git a/src/nitcatalog.nit b/src/nitcatalog.nit index c843b51..ba0cb1c 100644 --- a/src/nitcatalog.nit +++ b/src/nitcatalog.nit @@ -25,7 +25,7 @@ # * [X] generate a page per package with the readme and most metadata # * [ ] link/include/be included in the documentation # * [ ] propose `related packages` -# * [ ] show directory content (a la nitls) +# * [X] show directory content (a la nitls) # * [X] gather git information from the working directory # * [ ] gather git information from the repository # * [ ] gather package information from github @@ -33,7 +33,7 @@ # * [ ] reify people # * [ ] separate information gathering from rendering # * [ ] move up information gathering in (existing or new) service modules -# * [ ] add command line options +# * [X] add command line options # * [ ] harden HTML (escaping, path injection, etc) # * [ ] nitcorn server with RESTful API # @@ -238,6 +238,34 @@ class Catalog res.add "" end + # Recursively generate a level in the file tree of the *content* section + private fun gen_content_level(ot: OrderedTree[Object], os: Array[Object], res: Template) + do + res.add "
    \n" + for o in os do + res.add "
  • " + if o isa MGroup then + var d = "" + var mdoc = o.mdoc + if mdoc != null then d = ": {mdoc.html_synopsis.write_to_string}" + res.add "{o.name}{d} ({o.filepath.to_s})" + else if o isa ModulePath then + var d = "" + var m = o.mmodule + if m != null then + var mdoc = m.mdoc + if mdoc != null then d = ": {mdoc.html_synopsis.write_to_string}" + end + res.add "{o.name}{d} ({o.filepath.to_s})" + else + abort + end + var subs = ot.sub.get_or_null(o) + if subs != null then gen_content_level(ot, subs, res) + res.add "
  • \n" + end + res.add "
\n" + end # Compute information and generate a full HTML page for a package fun package_page(mpackage: MPackage): Writable @@ -257,6 +285,23 @@ class Catalog res.add mdoc.html_documentation score += mdoc.content.length.score end + + res.add "

Content

" + var ot = new OrderedTree[Object] + for g in mpackage.mgroups do + var pa = g.parent + if g.is_interesting then + ot.add(pa, g) + pa = g + end + for mp in g.module_paths do + ot.add(pa, mp) + end + end + ot.sort_with(alpha_comparator) + gen_content_level(ot, ot.roots, res) + + res.add """