X-Git-Url: http://nitlanguage.org diff --git a/src/nitcatalog.nit b/src/nitcatalog.nit index 6aba6f1..21847ee 100644 --- a/src/nitcatalog.nit +++ b/src/nitcatalog.nit @@ -12,28 +12,28 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Basic catalog generator for Nit projects +# Basic catalog generator for Nit packages # # See: # -# The tool scans projects and generates the HTML files of a catalog. +# The tool scans packages and generates the HTML files of a catalog. # # ## Features # -# * [X] scan projects and their `.ini` -# * [X] generate lists of projects -# * [X] generate a page per project with the readme and most metadata +# * [X] scan packages and their `.ini` +# * [X] generate lists of packages +# * [X] generate a page per package with the readme and most metadata # * [ ] link/include/be included in the documentation -# * [ ] propose `related projects` -# * [ ] show directory content (a la nitls) +# * [ ] propose `related packages` +# * [X] show directory content (a la nitls) # * [X] gather git information from the working directory # * [ ] gather git information from the repository -# * [ ] gather project information from github +# * [ ] gather package information from github # * [ ] gather people information from github # * [ ] 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 # @@ -48,13 +48,13 @@ # How to use the tool as the basis of a Nit code archive on the web usable with a package manager is not clear. module nitcatalog -import loader # Scan&load projects, groups and modules +import loader # Scan&load packages, groups and modules import doc::doc_down # Display mdoc import md5 # To get gravatar images import counter # For statistics import modelize # To process and count classes and methods -redef class MProject +redef class MPackage # Return the associated metadata from the `ini`, if any fun metadata(key: String): nullable String do @@ -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 @@ -139,7 +145,7 @@ class CatalogPage end redef class Int - # Returns `log(self+1)`. Used to compute score of projects + # Returns `log(self+1)`. Used to compute score of packages fun score: Float do return (self+1).to_f.log end @@ -150,46 +156,46 @@ class Catalog # used to access the files and count source lines of code var modelbuilder: ModelBuilder - # Projects by tag - var tag2proj = new MultiHashMap[String, MProject] + # Packages by tag + var tag2proj = new MultiHashMap[String, MPackage] - # Projects by category - var cat2proj = new MultiHashMap[String, MProject] + # Packages by category + var cat2proj = new MultiHashMap[String, MPackage] - # Projects by maintainer - var maint2proj = new MultiHashMap[String, MProject] + # Packages by maintainer + var maint2proj = new MultiHashMap[String, MPackage] - # Projects by contributors - var contrib2proj = new MultiHashMap[String, MProject] + # Packages by contributors + var contrib2proj = new MultiHashMap[String, MPackage] - # Dependency between projects - var deps = new POSet[MProject] + # Dependency between packages + var deps = new POSet[MPackage] - # Number of modules by project - var mmodules = new Counter[MProject] + # Number of modules by package + var mmodules = new Counter[MPackage] - # Number of classes by project - var mclasses = new Counter[MProject] + # Number of classes by package + var mclasses = new Counter[MPackage] - # Number of methods by project - var mmethods = new Counter[MProject] + # Number of methods by package + var mmethods = new Counter[MPackage] - # Number of line of code by project - var loc = new Counter[MProject] + # Number of line of code by package + var loc = new Counter[MPackage] - # Number of commits by project - var commits = new Counter[MProject] + # Number of commits by package + var commits = new Counter[MPackage] - # Score by project + # Score by package # # The score is loosely computed using other metrics - var score = new Counter[MProject] + var score = new Counter[MPackage] - # Scan, register and add a contributor to a project - fun add_contrib(person: String, mproject: MProject, res: Template) + # Scan, register and add a contributor to a package + fun add_contrib(person: String, mpackage: MPackage, res: Template) do var projs = contrib2proj[person] - if not projs.has(mproject) then projs.add mproject + if not projs.has(mpackage) then projs.add mpackage var name = person var email = null var page = null @@ -238,45 +244,102 @@ 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 project - fun project_page(mproject: MProject): Writable + # Compute information and generate a full HTML page for a package + fun package_page(mpackage: MPackage): Writable do - var res = new CatalogPage - var score = score[mproject].to_f - var name = mproject.name.html_escape + var res = new CatalogPage("..") + var score = score[mpackage].to_f + var name = mpackage.name.html_escape res.more_head.add """{{{name}}}""" res.add """

{{{name}}}

""" - var mdoc = mproject.mdoc_or_fallback + var mdoc = mpackage.mdoc_or_fallback if mdoc != null then score += 100.0 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 """
""" - self.score[mproject] = score.to_i + self.score[mpackage] = score.to_i return res end - # Return a short HTML sequence for a project + # Return a short HTML sequence for a package # # Intended to use in lists. - fun li_project(p: MProject): String + 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}" return res end - # List projects by group. + # List packages by group. # # For each key of the `map` a `

` is generated. - # Each project is then listed. + # Each package is then listed. # # The list of keys is generated first to allow fast access to the correct `

`. # `id_prefix` is used to give an id to the `

` element. - fun list_by(map: MultiHashMap[String, MProject], id_prefix: String): Template + fun list_by(map: MultiHashMap[String, MPackage], id_prefix: String): Template do var res = new Template var keys = map.keys.to_a @@ -478,7 +542,7 @@ class Catalog res.add "

{e} ({projs.length})

\n" @@ -486,8 +550,8 @@ class Catalog return res end - # List the 10 best projects from `cpt` - fun list_best(cpt: Counter[MProject]): Template + # List the 10 best packages from `cpt` + fun list_best(cpt: Counter[MPackage]): Template do var res = new Template res.add "