X-Git-Url: http://nitlanguage.org diff --git a/src/nitcatalog.nit b/src/nitcatalog.nit index 29477c1..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,7 +132,68 @@ g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); end end +redef class NitdocDecorator + redef fun add_image(v, link, name, comment) + do + # Keep absolute links as is + if link.has_prefix("http://") or link.has_prefix("https://") then + super + return + end + + do + # 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 + + # 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 @@ -171,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] @@ -199,12 +268,12 @@ redef class Catalog