X-Git-Url: http://nitlanguage.org diff --git a/src/nitcatalog.nit b/src/nitcatalog.nit index c843b51..c604fa6 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 # @@ -83,9 +83,18 @@ end class CatalogPage super Template + # The associated catalog, used to groups options and other global data + var catalog: Catalog + # Placeholder to include additional things before the ``. var more_head = new Template + # Relative path to the root directory (with the index file). + # + # Use "" for pages in the root directory + # Use ".." for pages in a subdirectory + var rootpath: String + redef init do add """ @@ -94,7 +103,7 @@ class CatalogPage - + """ add more_head @@ -116,7 +125,7 @@ class CatalogPage @@ -125,6 +134,37 @@ class CatalogPage """ end + # Inject piwik HTML code if required + private fun add_piwik + do + var tracker_url = catalog.piwik_tracker + if tracker_url == null then return + + var site_id = catalog.piwik_site_id + + tracker_url = tracker_url.trim + if tracker_url.chars.last != '/' then tracker_url += "/" + add """ + + + + +""" + + end + redef fun rendering do add """ @@ -132,6 +172,10 @@ class CatalogPage +""" + add_piwik + add """ + """ @@ -185,6 +229,12 @@ class Catalog # The score is loosely computed using other metrics var score = new Counter[MPackage] + # Return a empty `CatalogPage`. + fun new_page(rootpath: String): CatalogPage + do + return new CatalogPage(self, rootpath) + end + # Scan, register and add a contributor to a package fun add_contrib(person: String, mpackage: MPackage, res: Template) do @@ -238,11 +288,36 @@ class Catalog res.add "" end + # Recursively generate a level in the file tree of the *content* section + private fun gen_content_level(ot: OrderedTree[MConcern], os: Array[Object], res: Template) + do + res.add "\n" + end # Compute information and generate a full HTML page for a package fun package_page(mpackage: MPackage): Writable do - var res = new CatalogPage + var res = new_page("..") var score = score[mpackage].to_f var name = mpackage.name.html_escape res.more_head.add """{{{name}}}""" @@ -257,11 +332,43 @@ class Catalog res.add mdoc.html_documentation score += mdoc.content.length.score end + + res.add "

Content

" + var ot = new OrderedTree[MConcern] + 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.mmodules do + ot.add(pa, mp) + end + end + ot.sort_with(alpha_comparator) + gen_content_level(ot, ot.roots, res) + + res.add """