Merge: Nitdoc: some cleaning and fixes.
authorJean Privat <jean@pryen.org>
Fri, 5 Sep 2014 10:34:42 +0000 (06:34 -0400)
committerJean Privat <jean@pryen.org>
Fri, 5 Sep 2014 10:34:42 +0000 (06:34 -0400)
Some small fixes for nitdoc before the introduction of new features.

No concrete impact on visual for now.

Pull-Request: #718
Reviewed-by: Jean Privat <jean@pryen.org>

share/nitdoc/css/nitdoc.css
src/doc/doc_model.nit
src/doc/doc_pages.nit
src/doc/doc_templates.nit
tests/sav/nitdoc_args1.res

index 3f200bc..0fd73b7 100644 (file)
@@ -147,23 +147,23 @@ h3 {
 
 #content>.col {
        height: 100%;
-       overflow: hidden;
-}
-
-#content>.col:hover {
        overflow-y: scroll;
 }
 
-#content>.col::-webkit-scrollbar {
-    width: 7px;
-       height: 7px;
+#content>.col::-webkit-scrollbar-thumb {
+       background: transparent;
 }
 
-#content>.col::-webkit-scrollbar-thumb {
+#content>.col:hover::-webkit-scrollbar-thumb {
        background: #CCC;
        -webkit-box-shadow: inset 1px 1px 0 rgba(0,0,0,0.10),inset 0 -1px 0 rgba(0,0,0,0.07);
 }
 
+#content>.col::-webkit-scrollbar {
+    width: 7px;
+       height: 7px;
+}
+
 #content>.col::-webkit-scrollbar-thumb:hover {
        background: #999;
 }
index 9080dbf..01b7bc7 100644 (file)
@@ -54,7 +54,7 @@ redef class MEntity
        # URL of this entity Nitdoc page
        fun nitdoc_url: String is abstract
 
-       # A template link to the mentity `nitdoc_anchor`
+       # A template link to the mentity `nitdoc_id`
        fun tpl_anchor: TplLink do
                var tpl = new TplLink("#{nitdoc_id}", nitdoc_name)
                if mdoc != null then
@@ -186,7 +186,7 @@ redef class MGroup
                return "{mproject.nitdoc_id}__{nitdoc_name}"
        end
 
-       redef fun nitdoc_url do return "group_{name}.html"
+       redef fun nitdoc_url do return "group_{nitdoc_id}.html"
 
        redef fun tpl_namespace do
                var tpl = new Template
@@ -229,16 +229,7 @@ redef class MModule
                return nitdoc_name
        end
 
-       redef fun nitdoc_url do
-               var res = new FlatBuffer
-               res.append("module_")
-               var mowner = public_owner
-               if mowner != null then
-                       res.append("{public_owner.name}_")
-               end
-               res.append("{self.name}.html")
-               return res.to_s
-       end
+       redef fun nitdoc_url do return "module_{nitdoc_id}.html"
 
        redef fun tpl_declaration do
                var tpl = new Template
@@ -272,8 +263,7 @@ end
 redef class MClass
        redef fun nitdoc_name do return name.html_escape
        redef fun nitdoc_id do return "{intro_mmodule.mgroup.mproject}__{name.to_cmangle}"
-       redef fun nitdoc_url do return "class_{public_owner}_{name}.html"
-
+       redef fun nitdoc_url do return "class_{nitdoc_id}.html"
        redef fun mdoc do return intro.mdoc
 
        redef fun tpl_declaration do return intro.tpl_declaration
@@ -439,7 +429,7 @@ end
 redef class MProperty
        redef fun nitdoc_name do return name.html_escape
        redef fun nitdoc_id do return "{intro_mclassdef.mclass.nitdoc_id}__{name.to_cmangle}"
-       redef fun nitdoc_url do return "proprety_{nitdoc_id}.html"
+       redef fun nitdoc_url do return "property_{nitdoc_id}.html"
 
        redef fun mdoc do return intro.mdoc
 
index a49b76d..9c38d44 100644 (file)
@@ -135,20 +135,20 @@ class Nitdoc
        end
 
        private fun overview do
-               var overviewpage = new NitdocOverview(ctx, model, mainmodule)
-               overviewpage.render.write_to_file("{ctx.output_dir.to_s}/index.html")
+               var page = new NitdocOverview(ctx, model, mainmodule)
+               page.render.write_to_file("{ctx.output_dir.to_s}/{page.page_url}")
        end
 
        private fun search do
-               var searchpage = new NitdocSearch(ctx, model, mainmodule)
-               searchpage.render.write_to_file("{ctx.output_dir.to_s}/search.html")
+               var page = new NitdocSearch(ctx, model, mainmodule)
+               page.render.write_to_file("{ctx.output_dir.to_s}/{page.page_url}")
        end
 
        private fun groups do
                for mproject in model.mprojects do
                        for mgroup in mproject.mgroups.to_a do
                                var page = new NitdocGroup(ctx, model, mainmodule, mgroup)
-                               page.render.write_to_file("{ctx.output_dir.to_s}/{mgroup.nitdoc_url}")
+                               page.render.write_to_file("{ctx.output_dir.to_s}/{page.page_url}")
                        end
                end
        end
@@ -156,22 +156,22 @@ class Nitdoc
        private fun modules do
                for mmodule in model.mmodules do
                        if mmodule.is_fictive then continue
-                       var modulepage = new NitdocModule(ctx, model, mainmodule, mmodule)
-                       modulepage.render.write_to_file("{ctx.output_dir.to_s}/{mmodule.nitdoc_url}")
+                       var page = new NitdocModule(ctx, model, mainmodule, mmodule)
+                       page.render.write_to_file("{ctx.output_dir.to_s}/{page.page_url}")
                end
        end
 
        private fun classes do
                for mclass in model.mclasses do
-                       var classpage = new NitdocClass(ctx, model, mainmodule, mclass)
-                       classpage.render.write_to_file("{ctx.output_dir.to_s}/{mclass.nitdoc_url}")
+                       var page = new NitdocClass(ctx, model, mainmodule, mclass)
+                       page.render.write_to_file("{ctx.output_dir.to_s}/{page.page_url}")
                end
        end
 
        private fun properties do
                for mproperty in model.mproperties do
                        var page = new NitdocProperty(ctx, model, mainmodule, mproperty)
-                       page.render.write_to_file("{ctx.output_dir.to_s}/{mproperty.nitdoc_url}")
+                       page.render.write_to_file("{ctx.output_dir.to_s}/{page.page_url}")
                end
        end
 
@@ -265,6 +265,7 @@ abstract class NitdocPage
                # build page
                var tpl = tpl_page
                tpl.title = tpl_title
+               tpl.url = page_url
                tpl.shareurl = shareurl
                tpl.topmenu = tpl_topmenu
                tpl_content
@@ -281,6 +282,9 @@ abstract class NitdocPage
                return tpl
        end
 
+       # URL to this page.
+       fun page_url: String is abstract
+
        # Build page template
        fun tpl_page: TplPage is abstract
 
@@ -297,7 +301,7 @@ abstract class NitdocPage
 
        # Build top menu template
        fun tpl_topmenu: TplTopMenu do
-               var topmenu = new TplTopMenu
+               var topmenu = new TplTopMenu(page_url)
                var brand = ctx.opt_custom_brand.value
                if brand != null then
                        var tpl = new Template
@@ -306,6 +310,8 @@ abstract class NitdocPage
                        tpl.add "</span>"
                        topmenu.brand = tpl
                end
+               topmenu.add_link new TplLink("index.html", "Overview")
+               topmenu.add_link new TplLink("search.html", "Index")
                return topmenu
        end
 
@@ -344,7 +350,7 @@ abstract class NitdocPage
        do
                if location == null then return null
                var source = ctx.opt_source.value
-               if source == null then return "{location.file.filename.simplify_path}"
+               if source == null then return location.file.filename.simplify_path
                # THIS IS JUST UGLY ! (but there is no replace yet)
                var x = source.split_with("%f")
                source = x.join(location.file.filename.simplify_path)
@@ -382,26 +388,30 @@ abstract class NitdocPage
                article.content = mmodule.tpl_definition
                # mclassdefs list
                var intros = mmodule.intro_mclassdefs(ctx.min_visibility).to_a
-               mainmodule.linearize_mclassdefs(intros)
-               var intros_art = new TplArticle.with_title("{mmodule.nitdoc_id}_intros", "Introduces")
-               var intros_lst = new TplList.with_classes(["list-unstyled", "list-labeled"])
-               for mclassdef in intros do
-                       intros_lst.add_li new TplListItem.with_content(mclassdef.tpl_list_item)
-               end
-               if not intros_lst.is_empty then
-                       intros_art.content = intros_lst
-                       article.add_child intros_art
+               if not intros.is_empty then
+                       mainmodule.linearize_mclassdefs(intros)
+                       var intros_art = new TplArticle.with_title("{mmodule.nitdoc_id}_intros", "Introduces")
+                       var intros_lst = new TplList.with_classes(["list-unstyled", "list-labeled"])
+                       for mclassdef in intros do
+                               intros_lst.add_li mclassdef.tpl_list_item
+                       end
+                       if not intros_lst.is_empty then
+                               intros_art.content = intros_lst
+                               article.add_child intros_art
+                       end
                end
                var redefs = mmodule.redef_mclassdefs(ctx.min_visibility).to_a
-               mainmodule.linearize_mclassdefs(redefs)
-               var redefs_art = new TplArticle.with_title("{mmodule.nitdoc_id}_redefs", "Redefines")
-               var redefs_lst = new TplList.with_classes(["list-unstyled", "list-labeled"])
-               for mclassdef in redefs do
-                       redefs_lst.add_li new TplListItem.with_content(mclassdef.tpl_list_item)
-               end
-               if not redefs_lst.is_empty then
-                       redefs_art.content = redefs_lst
-                       article.add_child redefs_art
+               if not redefs.is_empty then
+                       mainmodule.linearize_mclassdefs(redefs)
+                       var redefs_art = new TplArticle.with_title("{mmodule.nitdoc_id}_redefs", "Redefines")
+                       var redefs_lst = new TplList.with_classes(["list-unstyled", "list-labeled"])
+                       for mclassdef in redefs do
+                               redefs_lst.add_li mclassdef.tpl_list_item
+                       end
+                       if not redefs_lst.is_empty then
+                               redefs_art.content = redefs_lst
+                               article.add_child redefs_art
+                       end
                end
                return article
        end
@@ -425,7 +435,7 @@ abstract class NitdocPage
                        var intros = new TplArticle.with_title("{mclassdef.nitdoc_id}_intros", "Introduces")
                        var intros_lst = new TplList.with_classes(["list-unstyled", "list-labeled"])
                        for mpropdef in mclassdef.collect_intro_mpropdefs(ctx.min_visibility) do
-                               intros_lst.add_li new TplListItem.with_content(mpropdef.tpl_list_item)
+                               intros_lst.add_li mpropdef.tpl_list_item
                        end
                        if not intros_lst.is_empty then
                                intros.content = intros_lst
@@ -434,7 +444,7 @@ abstract class NitdocPage
                        var redefs = new TplArticle.with_title("{mclassdef.nitdoc_id}_redefs", "Redefines")
                        var redefs_lst = new TplList.with_classes(["list-unstyled", "list-labeled"])
                        for mpropdef in mclassdef.collect_redef_mpropdefs(ctx.min_visibility) do
-                               redefs_lst.add_li new TplListItem.with_content(mpropdef.tpl_list_item)
+                               redefs_lst.add_li mpropdef.tpl_list_item
                        end
                        if not redefs_lst.is_empty then
                                redefs.content = redefs_lst
@@ -499,12 +509,7 @@ class NitdocOverview
                end
        end
 
-       redef fun tpl_topmenu do
-               var topmenu = super
-               topmenu.add_item(new TplLink("#", "Overview"), true)
-               topmenu.add_item(new TplLink("search.html", "Index"), false)
-               return topmenu
-       end
+       redef fun page_url do return "index.html"
 
        # intro text
        private fun tpl_intro: TplSection do
@@ -547,12 +552,7 @@ class NitdocSearch
 
        redef fun tpl_title do return "Index"
 
-       redef fun tpl_topmenu do
-               var topmenu = super
-               topmenu.add_item(new TplLink("index.html", "Overview"), false)
-               topmenu.add_item(new TplLink("#", "Index"), true)
-               return topmenu
-       end
+       redef fun page_url do return "search.html"
 
        redef fun tpl_content do
                var tpl = new TplSearchPage("search_all")
@@ -646,19 +646,17 @@ class NitdocGroup
        private var sidebar = new TplSidebar
        redef fun tpl_sidebar do return sidebar
 
-       redef fun tpl_title do return "{mgroup.nitdoc_name}"
+       redef fun tpl_title do return mgroup.nitdoc_name
+
+       redef fun page_url do return mgroup.nitdoc_url
 
        redef fun tpl_topmenu do
                var topmenu = super
                var mproject = mgroup.mproject
-               topmenu.add_item(new TplLink("index.html", "Overview"), false)
-               if mgroup.is_root then
-                       topmenu.add_item(new TplLink("#", "{mproject.nitdoc_name}"), true)
-               else
-                       topmenu.add_item(new TplLink(mproject.nitdoc_url, "{mproject.nitdoc_name}"), false)
-                       topmenu.add_item(new TplLink("#", "{mgroup.nitdoc_name}"), true)
+               if not mgroup.is_root then
+                       topmenu.add_link new TplLink(mproject.nitdoc_url, mproject.nitdoc_name)
                end
-               topmenu.add_item(new TplLink("search.html", "Index"), false)
+               topmenu.add_link new TplLink(page_url, mproject.nitdoc_name)
                return topmenu
        end
 
@@ -678,7 +676,7 @@ class NitdocGroup
                tpl_sidebar.boxes.add new TplSideBox.with_content("All classes", list)
        end
 
-       private fun tpl_sidebar_item(def: MClass): Template do
+       private fun tpl_sidebar_item(def: MClass): TplListItem do
                var classes = def.intro.tpl_css_classes.to_a
                if intros.has(def) then
                        classes.add "intro"
@@ -688,7 +686,7 @@ class NitdocGroup
                var lnk = new Template
                lnk.add new TplLabel.with_classes(classes)
                lnk.add def.tpl_link
-               return lnk
+               return new TplListItem.with_content(lnk)
        end
 
        # intro text
@@ -781,15 +779,14 @@ class NitdocModule
        private var sidebar = new TplSidebar
        redef fun tpl_sidebar do return sidebar
 
-       redef fun tpl_title do return "{mmodule.nitdoc_name}"
+       redef fun tpl_title do return mmodule.nitdoc_name
+       redef fun page_url do return mmodule.nitdoc_url
 
        redef fun tpl_topmenu do
                var topmenu = super
                var mproject = mmodule.mgroup.mproject
-               topmenu.add_item(new TplLink("index.html", "Overview"), false)
-               topmenu.add_item(new TplLink("{mproject.nitdoc_url}", "{mproject.nitdoc_name}"), false)
-               topmenu.add_item(new TplLink("#", "{mmodule.nitdoc_name}"), true)
-               topmenu.add_item(new TplLink("search.html", "Index"), false)
+               topmenu.add_link new TplLink(mproject.nitdoc_url, mproject.nitdoc_name)
+               topmenu.add_link new TplLink(page_url, mmodule.nitdoc_name)
                return topmenu
        end
 
@@ -809,7 +806,7 @@ class NitdocModule
                tpl_sidebar.boxes.add new TplSideBox.with_content("All classes", list)
        end
 
-       private fun tpl_sidebar_item(def: MClass): Template do
+       private fun tpl_sidebar_item(def: MClass): TplListItem do
                var classes = def.intro.tpl_css_classes.to_a
                if def.intro_mmodule == mmodule then
                        classes.add "intro"
@@ -819,7 +816,7 @@ class NitdocModule
                var lnk = new Template
                lnk.add new TplLabel.with_classes(classes)
                lnk.add def.tpl_link
-               return lnk
+               return new TplListItem.with_content(lnk)
        end
 
        # intro text
@@ -1018,14 +1015,13 @@ class NitdocClass
        redef fun tpl_sidebar do return sidebar
 
        redef fun tpl_title do return "{mclass.nitdoc_name}{mclass.tpl_signature.write_to_string}"
+       redef fun page_url do return mclass.nitdoc_url
 
        redef fun tpl_topmenu do
                var topmenu = super
                var mproject = mclass.intro_mmodule.mgroup.mproject
-               topmenu.add_item(new TplLink("index.html", "Overview"), false)
-               topmenu.add_item(new TplLink("{mproject.nitdoc_url}", "{mproject.nitdoc_name}"), false)
-               topmenu.add_item(new TplLink("#", "{mclass.nitdoc_name}"), true)
-               topmenu.add_item(new TplLink("search.html", "Index"), false)
+               topmenu.add_link new TplLink("{mproject.nitdoc_url}", "{mproject.nitdoc_name}")
+               topmenu.add_link new TplLink(page_url, mclass.nitdoc_name)
                return topmenu
        end
 
@@ -1052,14 +1048,14 @@ class NitdocClass
                summary.elts.add entry
        end
 
-       private fun tpl_sidebar_item(mprop: MProperty): Template do
+       private fun tpl_sidebar_item(mprop: MProperty): TplListItem do
                var classes = mprop.intro.tpl_css_classes.to_a
                if not mprops2mdefs.has_key(mprop) then
                        classes.add "inherit"
                        var lnk = new Template
                        lnk.add new TplLabel.with_classes(classes)
                        lnk.add mprop.intro.tpl_link
-                       return lnk
+                       return new TplListItem.with_content(lnk)
                end
                var defs = mprops2mdefs[mprop]
                if defs.has(mprop.intro) then
@@ -1070,7 +1066,7 @@ class NitdocClass
                var lnk = new Template
                lnk.add new TplLabel.with_classes(classes)
                lnk.add mprop.intro.tpl_anchor
-               return lnk
+               return new TplListItem.with_content(lnk)
        end
 
        private fun tpl_intro: TplSection do
@@ -1302,17 +1298,6 @@ class NitdocClass
                return res
        end
 
-       private fun sort_by_public_owner(mmodules: Collection[MModule]): Map[MModule, Set[MModule]] do
-               var map = new HashMap[MModule, Set[MModule]]
-               for mmodule in mmodules do
-                       var owner = mmodule
-                       if mmodule.public_owner != null then owner = mmodule.public_owner.as(not null)
-                       if not map.has_key(owner) then map[owner] = new HashSet[MModule]
-                       map[owner].add mmodule
-               end
-               return map
-       end
-
        # Generate dot hierarchy for classes
        fun tpl_dot(mclasses: Collection[MClass]): nullable TplArticle do
                var poset = new POSet[MClass]
@@ -1379,16 +1364,16 @@ class NitdocProperty
                return "{mproperty.nitdoc_name}{mproperty.tpl_signature.write_to_string}"
        end
 
+       redef fun page_url do return mproperty.nitdoc_url
+
        redef fun tpl_topmenu do
                var topmenu = super
                var mmodule = mproperty.intro_mclassdef.mmodule
                var mproject = mmodule.mgroup.mproject
                var mclass = mproperty.intro_mclassdef.mclass
-               topmenu.add_item(new TplLink("index.html", "Overview"), false)
-               topmenu.add_item(new TplLink("{mproject.nitdoc_url}", "{mproject.nitdoc_name}"), false)
-               topmenu.add_item(new TplLink("{mclass.nitdoc_url}", "{mclass.nitdoc_name}"), false)
-               topmenu.add_item(new TplLink("#", "{mproperty.nitdoc_name}"), true)
-               topmenu.add_item(new TplLink("search.html", "Index"), false)
+               topmenu.add_link new TplLink("{mproject.nitdoc_url}", "{mproject.nitdoc_name}")
+               topmenu.add_link new TplLink("{mclass.nitdoc_url}", "{mclass.nitdoc_name}")
+               topmenu.add_link new TplLink(page_url, mproperty.nitdoc_name)
                return topmenu
        end
 
index 7650feb..4d3b253 100644 (file)
@@ -25,6 +25,9 @@ class TplPage
        # Page title in HTML header
        var title: String is writable, noinit
 
+       # Page url
+       var url: String is writable, noinit
+
        # Directory where css, js and other assets can be found
        var shareurl: String is writable, noinit
 
@@ -105,7 +108,7 @@ class TplPage
                add "<script src='{shareurl}/vendors/jquery/jquery-1.11.1.min.js'></script>"
                add "<script src='{shareurl}/vendors/jquery/jquery-ui-1.10.4.custom.min.js'></script>"
                add "<script src='{shareurl}/vendors/bootstrap/js/bootstrap.min.js'></script>"
-               add "<script data-main='{shareurl}/js/nitdoc' src='{shareurl}/js/lib/require.js'</script>"
+               add "<script data-main='{shareurl}/js/nitdoc' src='{shareurl}/js/lib/require.js'></script>"
                for script in scripts do add script
                add """<script>
                        $(function () {
@@ -154,7 +157,20 @@ class TplTopMenu
        # Elements of the topmenu
        private var elts = new Array[Streamable]
 
-       init do end
+       # The page url where the top menu is displayed.
+       #
+       # Used to select the active link.
+       private var current_url: String
+
+       init(current_url: String) do
+               self.current_url = current_url
+       end
+
+       # Add a new link to the menu.
+       fun add_link(content: TplLink) do
+               var is_active = content.href == current_url
+               add_item(content, is_active)
+       end
 
        # Add a content between `<li>` tags
        fun add_item(content: Streamable, is_active: Bool) do
@@ -502,7 +518,7 @@ class TplArticle
        end
 
        redef fun is_empty: Bool do
-               return title == null and subtitle == null and content == null
+               return title == null and subtitle == null and content == null and children.is_empty
        end
 end
 
@@ -639,7 +655,7 @@ class TplLink
        var href: String writable
 
        # Text to display in the link
-       var text: String writable
+       var text: Streamable writable
 
        # Optional title
        var title: nullable String writable
@@ -681,7 +697,7 @@ class TplList
        var css_classes = new Array[String]
 
        # Add content wrapped in a <li> element
-       fun add_li(content: Streamable) do elts.add new TplListItem.with_content(content)
+       fun add_li(item: TplListItem) do elts.add item
 
        init do end
 
@@ -726,9 +742,7 @@ class TplListItem
        fun append(content: Streamable) do self.content.add content
 
        redef fun rendering do
-               add "<li class='"
-               for cls in css_classes do add " {cls}"
-               add "'>"
+               add "<li class='{css_classes.join(" ")}'>"
                add content
                add "</li>"
        end
@@ -739,12 +753,11 @@ class TplLabel
        super Template
 
        # Content of the label if any
-       var content: nullable Streamable
+       var content: nullable Streamable = null is writable
 
        # CSS classes of the <span> element
        var css_classes = new Array[String]
 
-       init do end
        init with_content(content: Streamable) do self.content = content
        init with_classes(classes: Array[String]) do self.css_classes = classes
 
index b9a9402..3494b3f 100644 (file)
@@ -1,8 +1,8 @@
-class_module_0_Int.html
-class_module_0_Object.html
-class_module_0_Sys.html
-class_module_1_A.html
-class_module_1_B.html
+class_module_0__Int.html
+class_module_0__Object.html
+class_module_0__Sys.html
+class_module_1__A.html
+class_module_1__B.html
 css/
 dep_A.dot
 dep_A.map
@@ -32,23 +32,23 @@ dep_module_1.dot
 dep_module_1.map
 dep_module_1.png
 dep_module_1.s.dot
-group_module_0.html
-group_module_1.html
+group_module_0__module_0.html
+group_module_1__module_1.html
 index.html
 js/
 less/
-module_module_0.html
-module_module_1.html
-proprety_module_0__Object__init.html
-proprety_module_0__Object__output.html
-proprety_module_0__Object__print.html
-proprety_module_0__Sys__main.html
-proprety_module_1__A__a1.html
-proprety_module_1__A__a12.html
-proprety_module_1__A__a123.html
-proprety_module_1__A__a13.html
-proprety_module_1__B__all2.html
-proprety_module_1__B__all25.html
+module_module_0__module_0__module_0.html
+module_module_1__module_1__module_1.html
+property_module_0__Object__init.html
+property_module_0__Object__output.html
+property_module_0__Object__print.html
+property_module_0__Sys__main.html
+property_module_1__A__a1.html
+property_module_1__A__a12.html
+property_module_1__A__a123.html
+property_module_1__A__a13.html
+property_module_1__B__all2.html
+property_module_1__B__all25.html
 quicksearch-list.js
 resources/
 search.html