X-Git-Url: http://nitlanguage.org diff --git a/src/nitcatalog.nit b/src/nitcatalog.nit index fe6d8c7..e3e77f3 100644 --- a/src/nitcatalog.nit +++ b/src/nitcatalog.nit @@ -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 # @@ -86,6 +86,12 @@ class CatalogPage # 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 +100,7 @@ class CatalogPage - + """ add more_head @@ -116,7 +122,7 @@ class CatalogPage @@ -270,7 +276,7 @@ class Catalog # 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 CatalogPage("..") var score = score[mpackage].to_f var name = mpackage.name.html_escape res.more_head.add """{{{name}}}""" @@ -359,73 +365,72 @@ class Catalog res.add "

Tags

\n" var tags = mpackage.metadata("package.tags") - var ts2 = new Array[String] - var cat = null + var ts = new Array[String] if tags != null then - var ts = tags.split(",") - for t in ts do + for t in tags.split(",") do t = t.trim if t == "" then continue - if cat == null then cat = t - tag2proj[t].add mpackage - t = t.html_escape - ts2.add "{t}" + ts.add t end - res.add_list(ts2, ", ", ", ") end - if ts2.is_empty then - var t = "none" - cat = t + if ts.is_empty then ts.add "none" + var ts2 = new Array[String] + for t in ts do tag2proj[t].add mpackage - res.add "{t}" + t = t.html_escape + ts2.add "{t}" end - if cat != null then cat2proj[cat].add mpackage - score += ts2.length.score - - var reqs = deps[mpackage].greaters.to_a - reqs.remove(mpackage) - alpha_comparator.sort(reqs) - res.add "

Requirements

\n" - if reqs.is_empty then - res.add "none" - else - var list = new Array[String] - for r in reqs do - var direct = deps.has_direct_edge(mpackage, r) - var s = "" - if direct then s += "" - s += r.to_s - if direct then s += "" - s += "" - list.add s + res.add_list(ts2, ", ", ", ") + var cat = ts.first + cat2proj[cat].add mpackage + score += ts.length.score + + if deps.has(mpackage) then + var reqs = deps[mpackage].greaters.to_a + reqs.remove(mpackage) + alpha_comparator.sort(reqs) + res.add "

Requirements

\n" + if reqs.is_empty then + res.add "none" + else + var list = new Array[String] + for r in reqs do + var direct = deps.has_direct_edge(mpackage, r) + var s = "" + if direct then s += "" + s += r.to_s + if direct then s += "" + s += "" + list.add s + end + res.add_list(list, ", ", " and ") end - res.add_list(list, ", ", " and ") - end - reqs = deps[mpackage].smallers.to_a - reqs.remove(mpackage) - alpha_comparator.sort(reqs) - res.add "

Clients

\n" - if reqs.is_empty then - res.add "none" - else - var list = new Array[String] - for r in reqs do - var direct = deps.has_direct_edge(r, mpackage) - var s = "" - if direct then s += "" - s += r.to_s - if direct then s += "" - s += "" - list.add s + reqs = deps[mpackage].smallers.to_a + reqs.remove(mpackage) + alpha_comparator.sort(reqs) + res.add "

Clients

\n" + if reqs.is_empty then + res.add "none" + else + var list = new Array[String] + for r in reqs do + var direct = deps.has_direct_edge(r, mpackage) + var s = "" + if direct then s += "" + s += r.to_s + if direct then s += "" + s += "" + list.add s + end + res.add_list(list, ", ", " and ") end - res.add_list(list, ", ", " and ") - end - score += deps[mpackage].greaters.length.score - score += deps[mpackage].direct_greaters.length.score - score += deps[mpackage].smallers.length.score - score += deps[mpackage].direct_smallers.length.score + score += deps[mpackage].greaters.length.score + score += deps[mpackage].direct_greaters.length.score + score += deps[mpackage].smallers.length.score + score += deps[mpackage].direct_smallers.length.score + end var contributors = mpackage.contributors if not contributors.is_empty then @@ -494,7 +499,7 @@ class Catalog fun li_package(p: MPackage): String do var res = "" - var f = "{p.name}.html" + var f = "p/{p.name}.html" res += "{p}" var d = p.mdoc_or_fallback if d != null then res += " - {d.html_synopsis.write_to_string}" @@ -598,10 +603,12 @@ class Catalog res.add "name\n" res.add "maint\n" res.add "contrib\n" - res.add "reqs\n" - res.add "direct
reqs\n" - res.add "clients\n" - res.add "direct
clients\n" + if deps.not_empty then + res.add "reqs\n" + res.add "direct
reqs\n" + res.add "clients\n" + res.add "direct
clients\n" + end res.add "modules\n" res.add "classes\n" res.add "methods\n" @@ -610,15 +617,17 @@ class Catalog res.add "" for p in mpackages do res.add "" - res.add "{p.name}" + res.add "{p.name}" var maint = "?" if p.maintainers.not_empty then maint = p.maintainers.first res.add "{maint}" res.add "{p.contributors.length}" - res.add "{deps[p].greaters.length-1}" - res.add "{deps[p].direct_greaters.length}" - res.add "{deps[p].smallers.length-1}" - res.add "{deps[p].direct_smallers.length}" + if deps.not_empty then + res.add "{deps[p].greaters.length-1}" + res.add "{deps[p].direct_greaters.length}" + res.add "{deps[p].smallers.length-1}" + res.add "{deps[p].direct_smallers.length}" + end res.add "{mmodules[p]}" res.add "{mclasses[p]}" res.add "{mmethods[p]}" @@ -645,6 +654,13 @@ end var model = new Model var tc = new ToolContext +var opt_dir = new OptionString("Directory where the HTML files are generated", "-d", "--dir") +var opt_no_git = new OptionBool("Do not gather git information from the working directory", "--no-git") +var opt_no_parse = new OptionBool("Do not parse nit files (no importation information)", "--no-parse") +var opt_no_model = new OptionBool("Do not analyse nit files (no class/method information)", "--no-model") + +tc.option_context.add_option(opt_dir, opt_no_git, opt_no_parse, opt_no_model) + tc.process_options(sys.args) tc.keep_going = true @@ -664,6 +680,7 @@ for p in model.mpackages do modelbuilder.scan_group(g) # Load the module to process importation information + if opt_no_parse.value then continue modelbuilder.parse_group(g) catalog.deps.add_node(p) @@ -674,15 +691,19 @@ for p in model.mpackages do catalog.deps.add_edge(p, ip) end end +end +if not opt_no_git.value then for p in model.mpackages do catalog.git_info(p) end # Run phases to modelize classes and properties (so we can count them) -#modelbuilder.run_phases +if not opt_no_model.value then + modelbuilder.run_phases +end -var out = "out" -out.mkdir +var out = opt_dir.value or else "catalog.out" +(out/"p").mkdir # Generate the css (hard coded) var css = """ @@ -788,13 +809,13 @@ css.write_to_file(out/"style.css") for p in model.mpackages do # print p - var f = "{p.name}.html" + var f = "p/{p.name}.html" catalog.package_page(p).write_to_file(out/f) end # INDEX -var index = new CatalogPage +var index = new CatalogPage("") index.more_head.add "Packages in Nit" index.add """ @@ -805,12 +826,14 @@ index.add """ index.add "

Highlighted Packages

\n" index.add catalog.list_best(catalog.score) -index.add "

Most Required

\n" -var reqs = new Counter[MPackage] -for p in model.mpackages do - reqs[p] = catalog.deps[p].smallers.length - 1 +if catalog.deps.not_empty then + index.add "

Most Required

\n" + var reqs = new Counter[MPackage] + for p in model.mpackages do + reqs[p] = catalog.deps[p].smallers.length - 1 + end + index.add catalog.list_best(reqs) end -index.add catalog.list_best(reqs) index.add "

By First Tag

\n" index.add catalog.list_by(catalog.cat2proj, "cat_") @@ -839,7 +862,7 @@ index.write_to_file(out/"index.html") # PEOPLE -var page = new CatalogPage +var page = new CatalogPage("") page.more_head.add "People of Nit" page.add """
\n

People of Nit

\n""" page.add "

By Maintainer

\n" @@ -851,7 +874,7 @@ page.write_to_file(out/"people.html") # TABLE -page = new CatalogPage +page = new CatalogPage("") page.more_head.add "Projets of Nit" page.add """
\n

People of Nit

\n""" page.add "

Table of Projets

\n"