X-Git-Url: http://nitlanguage.org
diff --git a/src/nitcatalog.nit b/src/nitcatalog.nit
index d2aff2d..5c478f0 100644
--- a/src/nitcatalog.nit
+++ b/src/nitcatalog.nit
@@ -131,62 +131,72 @@ g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
end
end
-redef class Catalog
- # Return a empty `CatalogPage`.
- fun new_page(rootpath: String): CatalogPage
+redef class NitdocDecorator
+ redef fun add_image(v, link, name, comment)
do
- return new CatalogPage(self, rootpath)
- end
+ # Keep absolute links as is
+ if link.has_prefix("http://") or link.has_prefix("https://") then
+ super
+ return
+ end
- # Add a contributor to a package
- fun add_contrib(person: String, mpackage: MPackage, res: Template)
- do
- var name = person
- var email = null
- var page = null
-
- # Regular expressions are broken, need to investigate.
- # So split manually.
- #
- #var re = "([^<(]*?)(<([^>]*?)>)?(\\((.*)\\))?".to_re
- #var m = (person+" ").search(re)
- #print "{person}: `{m or else "?"}` `{m[1] or else "?"}` `{m[3] or else "?"}` `{m[5] or else "?"}`"
do
- var sp1 = person.split_once_on("<")
- if sp1.length < 2 then
- break
- end
- var sp2 = sp1.last.split_once_on(">")
- if sp2.length < 2 then
- break
- end
- name = sp1.first.trim
- email = sp2.first.trim
- var sp3 = sp2.last.split_once_on("(")
- if sp3.length < 2 then
- break
- end
- var sp4 = sp3.last.split_once_on(")")
- if sp4.length < 2 then
- break
- end
- page = sp4.first.trim
+ # Get the directory of the doc object to deal with the relative link
+ var mdoc = current_mdoc
+ if mdoc == null then break
+ var source = mdoc.location.file
+ if source == null then break
+ var path = source.filename
+ var stat = path.file_stat
+ if stat == null then break
+ if not stat.is_dir then path = path.dirname
+
+ # Get the full path to the local resource
+ var fulllink = path / link.to_s
+ stat = fulllink.file_stat
+ if stat == null then break
+
+ # Get a collision-free catalog name for the resource
+ var hash = fulllink.md5
+ var ext = fulllink.file_extension
+ if ext != null then hash = hash + "." + ext
+
+ # Copy the local resource in the resource directory of the catalog
+ var res = catalog.outdir / "res" / hash
+ fulllink.file_copy_to(res)
+
+ # Hijack the link in the html.
+ link = ".." / "res" / hash
+ super(v, link, name, comment)
+ return
end
- var e = name.html_escape
- res.add "
"
- if page != null then
- res.add ""
- end
- if email != null then
- # TODO get more things from github by using the email as a key
- # "https://api.github.com/search/users?q={email}+in:email"
- var md5 = email.md5.to_lower
- res.add "
"
- end
- res.add "{e}"
- if page != null then res.add ""
- res.add ""
+ # Something went bad
+ catalog.modelbuilder.toolcontext.error(current_mdoc.location, "Error: cannot find local image `{link}`")
+ super
+ end
+
+ # The registered catalog
+ #
+ # It is used to deal with relative links in images.
+ var catalog: Catalog is noautoinit
+end
+
+redef class Catalog
+ redef init
+ do
+ # Register `self` to the global NitdocDecorator
+ # FIXME this is ugly. But no better idea at the moment.
+ modelbuilder.model.nitdoc_md_processor.emitter.decorator.as(NitdocDecorator).catalog = self
+ end
+
+ # The output directory where to generate pages
+ var outdir: String is noautoinit
+
+ # Return a empty `CatalogPage`.
+ fun new_page(rootpath: String): CatalogPage
+ do
+ return new CatalogPage(self, rootpath)
end
# Recursively generate a level in the file tree of the *content* section
@@ -268,9 +278,8 @@ redef class Catalog
var e = homepage.html_escape
res.add "{e}\n"
end
- var maintainer = mpackage.metadata("package.maintainer")
- if maintainer != null then
- add_contrib(maintainer, mpackage, res)
+ for maintainer in mpackage.maintainers do
+ res.add "{maintainer.to_html}"
end
var license = mpackage.metadata("package.license")
if license != null then
@@ -306,6 +315,15 @@ redef class Catalog
end
res.add "\n"
+ res.add "Quality
\n\n"
+ var errors = errors[mpackage]
+ if errors > 0 then
+ res.add "- {errors} errors
\n"
+ end
+ res.add "- {warnings[mpackage]} warnings ({warnings_per_kloc[mpackage]}/kloc)
\n"
+ res.add "- {documentation_score[mpackage]}% documented
\n"
+ res.add "
\n"
+
res.add "Tags
\n"
var ts2 = new Array[String]
for t in mpackage.tags do
@@ -360,7 +378,7 @@ redef class Catalog
if not contributors.is_empty then
res.add "Contributors
\n"
for c in contributors do
- add_contrib(c, mpackage, res)
+ res.add "- {c.to_html}
"
end
res.add "
"
end
@@ -401,18 +419,18 @@ redef class Catalog
#
# 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, MPackage], id_prefix: String): Template
+ fun list_by(map: MultiHashMap[Object, MPackage], id_prefix: String): Template
do
var res = new Template
var keys = map.keys.to_a
alpha_comparator.sort(keys)
- var list = [for x in keys do "{x.html_escape}"]
+ var list = [for x in keys do "{x.to_s.html_escape}"]
res.add_list(list, ", ", " and ")
for k in keys do
var projs = map[k].to_a
alpha_comparator.sort(projs)
- var e = k.html_escape
+ var e = k.to_s.html_escape
res.add "{e} ({projs.length})
\n\n"
for p in projs do
res.add "- "
@@ -465,12 +483,16 @@ redef class Catalog
res.add "
methods | \n"
res.add "lines | \n"
res.add "score | \n"
+ res.add "errors | \n"
+ res.add "warnings | \n"
+ res.add "w/kloc | \n"
+ res.add "doc | \n"
res.add ""
for p in mpackages do
res.add ""
res.add "{p.name} | "
var maint = "?"
- if p.maintainers.not_empty then maint = p.maintainers.first
+ if p.maintainers.not_empty then maint = p.maintainers.first.name.html_escape
res.add "{maint} | "
res.add "{p.contributors.length} | "
if deps.not_empty then
@@ -484,6 +506,10 @@ redef class Catalog
res.add "{mmethods[p]} | "
res.add "{loc[p]} | "
res.add "{score[p]} | "
+ res.add "{errors[p]} | "
+ res.add "{warnings[p]} | "
+ res.add "{warnings_per_kloc[p]} | "
+ res.add "{documentation_score[p]} | "
res.add "
\n"
end
res.add "\n"
@@ -571,6 +597,9 @@ end
var out = opt_dir.value or else "catalog.out"
(out/"p").mkdir
+(out/"res").mkdir
+
+catalog.outdir = out
# Generate the css (hard coded)
var css = """