Merge: Byte data type
[nit.git] / src / doc / doc_phases / doc_html.nit
index 48763df..83a2cc9 100644 (file)
@@ -104,7 +104,7 @@ class RenderHTMLPhase
 
        redef fun apply do
                init_output_dir
-               for page in doc.pages do
+               for page in doc.pages.values do
                        page.render(self, doc).write_to_file("{ctx.output_dir.to_s}/{page.html_url}")
                end
        end
@@ -133,8 +133,8 @@ class RenderHTMLPhase
 
        end
 
-       # A source link template for a given location
-       fun tpl_showsource(location: nullable Location): nullable String
+       # Returns a HTML link for a given `location`.
+       fun html_source_link(location: nullable Location): nullable String
        do
                if location == null then return null
                var source = ctx.opt_source.value
@@ -187,19 +187,12 @@ redef class DocPage
        # all properties below are roughly copied from `doc_pages`
 
        # Build page title string
-       fun init_title(v: RenderHTMLPhase, doc: DocModel) is abstract
+       fun init_title(v: RenderHTMLPhase, doc: DocModel) do end
 
        # Build top menu template if any.
        fun init_topmenu(v: RenderHTMLPhase, doc: DocModel) do
                topmenu = new DocTopMenu
-               var brand = v.ctx.opt_custom_brand.value
-               if brand != null then
-                       var tpl = new Template
-                       tpl.add "<span class='navbar-brand'>"
-                       tpl.add brand
-                       tpl.add "</span>"
-                       topmenu.brand = tpl
-               end
+               topmenu.brand = v.ctx.opt_custom_brand.value
                var title = "Overview"
                if v.ctx.opt_custom_title.value != null then
                        title = v.ctx.opt_custom_title.value.to_s
@@ -379,7 +372,7 @@ redef class MClassPage
                if not mprop_is_local(mprop) then
                        classes.add "inherit"
                        var cls_url = mprop.intro.mclassdef.mclass.nitdoc_url
-                       var def_url = "{cls_url}#{mprop.nitdoc_id}"
+                       var def_url = "{cls_url}#{mprop.nitdoc_id}.definition"
                        var lnk = new Link(def_url, mprop.html_name)
                        var mdoc = mprop.intro.mdoc_or_fallback
                        if mdoc != null then lnk.title = mdoc.short_comment
@@ -393,12 +386,28 @@ redef class MClassPage
                else
                        classes.add "redef"
                end
+               var def = select_mpropdef(mprop)
+               var anc = def.html_link_to_anchor
+               anc.href = "#{def.nitdoc_id}.definition"
                var lnk = new Template
                lnk.add new DocHTMLLabel.with_classes(classes)
-               lnk.add mprop.html_link_to_anchor
+               lnk.add anc
                return new ListItem(lnk)
        end
 
+       # Get the mpropdef contained in `self` page for a mprop.
+       #
+       # FIXME this method is used to translate a mprop into a mpropdefs for
+       # section linking. A better page structure should avoid this...
+       private fun select_mpropdef(mprop: MProperty): MPropDef do
+               for mclassdef in mentity.mclassdefs do
+                       for mpropdef in mclassdef.mpropdefs do
+                               if mpropdef.mproperty == mprop then return mpropdef
+                       end
+               end
+               abort # FIXME is there a case where the prop is not found?
+       end
+
        private fun mclass_inherited_mprops(v: RenderHTMLPhase, doc: DocModel): Set[MProperty] do
                var res = new HashSet[MProperty]
                var local = mentity.local_mproperties(v.ctx.min_visibility)
@@ -462,7 +471,7 @@ redef class MEntitySection
                        title.add mentity.html_signature
                        html_title = title
                        html_subtitle = mentity.html_namespace
-                       toc_title = mentity.html_name
+                       html_toc_title = mentity.html_name
                end
                super
        end
@@ -473,14 +482,18 @@ redef class ConcernSection
        redef fun init_html_render(v, doc, page) do
                if not page isa MEntityPage then return
                var mentity = self.mentity
-               if page.mentity isa MModule and mentity isa MModule then
+               if page isa MGroupPage then
+                       html_title = null
+                       html_toc_title = mentity.html_name
+                       is_toc_hidden = false
+               else if page.mentity isa MModule and mentity isa MModule then
                        var title = new Template
                        if mentity == page.mentity then
                                title.add "in "
-                               toc_title = "in {mentity.html_name}"
+                               html_toc_title = "in {mentity.html_name}"
                        else
                                title.add "from "
-                               toc_title = "from {mentity.html_name}"
+                               html_toc_title = "from {mentity.html_name}"
                        end
                        title.add mentity.html_namespace
                        html_title = title
@@ -490,7 +503,7 @@ redef class ConcernSection
                        title.add "in "
                        title.add mentity.html_namespace
                        html_title = title
-                       toc_title = "in {mentity.html_name}"
+                       html_toc_title = "in {mentity.html_name}"
                end
                super
        end
@@ -501,11 +514,11 @@ redef class IntroArticle
        redef fun init_html_render(v, doc, page) do
                var mentity = self.mentity
                if mentity isa MModule then
-                       # article.source_link = v.tpl_showsource(mentity.location)
+                       html_source_link = v.html_source_link(mentity.location)
                else if mentity isa MClassDef then
-                       # article.source_link = v.tpl_showsource(mentity.location)
+                       html_source_link = v.html_source_link(mentity.location)
                else if mentity isa MPropDef then
-                       # article.source_link = v.tpl_showsource(mentity.location)
+                       html_source_link = v.html_source_link(mentity.location)
                end
        end
 end
@@ -519,107 +532,43 @@ redef class DefinitionArticle
                        title.add mentity.html_icon
                        title.add mentity.html_namespace
                        html_title = title
-                       toc_title = mentity.html_name
-                       # article.source_link = v.tpl_showsource(mentity.location)
-               else if mentity isa MClass then
-                       var title = new Template
-                       title.add mentity.html_icon
-                       title.add mentity.html_link
-                       html_title = title
-                       html_subtitle = mentity.html_namespace
-                       toc_title = mentity.html_name
-                       is_no_body = true
+                       html_toc_title = mentity.html_name
+                       if mentity isa MModule then
+                               html_source_link = v.html_source_link(mentity.location)
+                       end
                else if mentity isa MClassDef then
                        var title = new Template
                        title.add "in "
                        title.add mentity.mmodule.html_namespace
                        html_title = mentity.html_declaration
                        html_subtitle = title
-                       toc_title = "in {mentity.html_name}"
-                       # article.source_link = v.tpl_showsource(mentity.location)
+                       html_toc_title = "in {mentity.html_name}"
+                       html_source_link = v.html_source_link(mentity.location)
                        if page isa MEntityPage and mentity.is_intro and mentity.mmodule != page.mentity then
                                is_short_comment = true
                        end
                        if page isa MModulePage then is_toc_hidden = true
                else if mentity isa MPropDef then
-                       if page isa MEntityPage and page.mentity isa MClass then
+                       if page isa MClassPage then
                                var title = new Template
                                title.add mentity.html_icon
                                title.add mentity.html_declaration
                                html_title = title
                                html_subtitle = mentity.html_namespace
-                               toc_title = mentity.html_name
-                               # TODO move in its own phase? let's see after doc_template refactoring.
-                               # Add linearization
-                               var all_defs = new HashSet[MPropDef]
-                               for local_def in local_defs(page.as(MClassPage), mentity.mproperty) do
-                                       all_defs.add local_def
-                                       var smpropdef = local_def
-                                       while not smpropdef.is_intro do
-                                               smpropdef = smpropdef.lookup_next_definition(
-                                                       doc.mainmodule, smpropdef.mclassdef.bound_mtype)
-                                               all_defs.add smpropdef
-                                       end
-                               end
-                               var lin = all_defs.to_a
-                               doc.mainmodule.linearize_mpropdefs(lin)
-                               if lin.length > 1 then
-                                       var lin_article = new DocArticle
-                                       lin_article.html_id = "{mentity.nitdoc_id}.lin"
-                                       lin_article.html_title = "Inheritance"
-                                       lin_article.is_toc_hidden = true
-                                       var lst = new UnorderedList
-                                       lst.css_classes.add("list-unstyled list-labeled")
-                                       for smpropdef in lin do
-                                               lst.add_li tpl_inheritance_item(smpropdef)
-                                       end
-                                       # FIXME will be moved in its own phase
-                                       lin_article.add lst
-                                       add_child lin_article
-                               end
+                               html_toc_title = mentity.html_name
                        else
                                var title = new Template
                                title.add "in "
                                title.add mentity.mclassdef.html_link
                                html_title = title
-                               toc_title = "in {mentity.mclassdef.html_name}"
-                       end
-                       # article.source_link = v.tpl_showsource(mentity.location)
-               end
-               super
-       end
-
-       # Filter `page.mpropdefs` for this `mpropertie`.
-       #
-       # FIXME compatability with current templates.
-       private fun local_defs(page: MClassPage, mproperty: MProperty): HashSet[MPropDef] do
-               var mpropdefs = new HashSet[MPropDef]
-               for mpropdef in page.mpropdefs do
-                       if mpropdef.mproperty == mproperty then
-                               mpropdefs.add mpropdef
+                               html_toc_title = "in {mentity.mclassdef.html_name}"
                        end
+                       html_source_link = v.html_source_link(mentity.location)
                end
-               return mpropdefs
-       end
-
-       private fun tpl_inheritance_item(mpropdef: MPropDef): ListItem do
-               var lnk = new Template
-               lnk.add new TplLabel.with_classes(css_classes)
-               lnk.add mpropdef.mclassdef.mmodule.html_namespace
-               lnk.add "::"
-               var atext = mpropdef.mclassdef.html_link.text
-               var ahref = "{mpropdef.mclassdef.mclass.nitdoc_url}#{mpropdef.mproperty.nitdoc_id}"
-               var atitle = mpropdef.mclassdef.html_link.title
-               var anchor = new Link.with_title(ahref, atext, atitle)
-               lnk.add anchor
-               var comment = mpropdef.html_short_comment
-               if comment != null then
-                       lnk.add ": "
-                       lnk.add comment
+               if page isa MGroupPage and mentity isa MModule then
+                       is_toc_hidden = true
                end
-               var li = new ListItem(lnk)
-               li.css_classes.add "signature"
-               return li
+               super
        end
 end
 
@@ -627,7 +576,7 @@ redef class HomeArticle
        redef fun init_html_render(v, doc, page) do
                if v.ctx.opt_custom_title.value != null then
                        self.html_title = v.ctx.opt_custom_title.value.to_s
-                       self.toc_title = v.ctx.opt_custom_title.value.to_s
+                       self.html_toc_title = v.ctx.opt_custom_title.value.to_s
                end
                self.content = v.ctx.opt_custom_intro.value
                super
@@ -637,7 +586,7 @@ end
 redef class GraphArticle
        redef fun init_html_render(v, doc, page) do
                var output_dir = v.ctx.output_dir
-               var path = output_dir / id
+               var path = output_dir / graph_id
                var path_sh = path.escape_to_sh
                var file = new FileWriter.open("{path}.dot")
                file.write(dot)
@@ -648,13 +597,3 @@ redef class GraphArticle
                fmap.close
        end
 end
-
-redef class Location
-       # Github url based on this location
-       fun github(gitdir: String): String do
-               var base_dir = getcwd.join_path(gitdir).simplify_path
-               var file_loc = getcwd.join_path(file.filename).simplify_path
-               var gith_loc = file_loc.substring(base_dir.length + 1, file_loc.length)
-               return "{gith_loc}:{line_start},{column_start}--{line_end},{column_end}"
-       end
-end