X-Git-Url: http://nitlanguage.org diff --git a/src/nitcatalog.nit b/src/nitcatalog.nit index d2aff2d..2a0a4a5 100644 --- a/src/nitcatalog.nit +++ b/src/nitcatalog.nit @@ -22,9 +22,10 @@ module nitcatalog import loader # Scan&load packages, groups and modules -import doc::doc_down # Display mdoc import catalog +import doc::templates::html_model + # A HTML page in a catalog # # This is just a template with the header pre-filled and the footer injected at rendering. @@ -131,62 +132,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.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 @@ -222,12 +233,19 @@ redef class Catalog var name = mpackage.name.html_escape res.more_head.add """{{{name}}}""" - res.add """ -
    -

    {{{name}}}

    -""" + res.add """
    """ + var mdoc = mpackage.mdoc_or_fallback - if mdoc != null then res.add mdoc.html_documentation + if mdoc == null then + res.add """

    {{{name}}}

    """ + else + res.add """ +
    +

    {{{name}}} - 

    +
    +""" + res.add mdoc.html_documentation + end res.add "

    Content

    " var ot = new OrderedTree[MConcern] @@ -250,12 +268,12 @@ redef class Catalog