doc_down: introduce `synopsis` service
authorAlexandre Terrasa <alexandre@moz-code.org>
Fri, 22 May 2015 03:16:08 +0000 (23:16 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Wed, 24 Jun 2015 20:29:59 +0000 (16:29 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/doc/doc_down.nit
src/doc/doc_phases/doc_html.nit
src/doc/html_templates/html_model.nit
src/doc/html_templates/html_templates.nit

index 876ce07..5284dc1 100644 (file)
@@ -20,11 +20,19 @@ import highlight
 private import parser_util
 
 redef class MDoc
-       # Comment synopsys HTML escaped
-       var short_comment: String is lazy do return content.first.html_escape
 
-       # Full comment HTML escaped
-       var full_comment: String is lazy do return content.join("\n").html_escape
+       # Synopsis HTML escaped.
+       var synopsis: String is lazy do return content.first.html_escape
+
+       # Comment without synopsis HTML escaped
+       var comment: String is lazy do
+               var lines = content.to_a
+               if not lines.is_empty then lines.shift
+               return content.join("\n").html_escape
+       end
+
+       # Full comment HTML escaped.
+       var documentation: String is lazy do return content.join("\n").html_escape
 
        private var markdown_proc: MarkdownProcessor is lazy do
                return original_mentity.model.nitdoc_md_processor
@@ -34,8 +42,8 @@ redef class MDoc
                return original_mentity.model.nitdoc_inline_processor
        end
 
-       # Synopsys in a template
-       var tpl_short_comment: Writable is lazy do
+       # Renders the synopsis as a HTML comment block.
+       var html_synopsis: Writable is lazy do
                var res = new Template
                var syn = inline_proc.process(content.first)
                res.add "<span class=\"synopsys nitdoc\">{syn}</span>"
@@ -43,17 +51,28 @@ redef class MDoc
 
        end
 
-       # Full comment in a template
-       var tpl_comment: Writable is lazy do
-               var res = new Template
+       # Renders the comment without the synopsis as a HTML comment block.
+       var html_comment: Writable is lazy do
                var lines = content.to_a
+               if not lines.is_empty then lines.shift
+               return lines_to_html(lines)
+       end
+
+       # Renders the synopsis and the comment as a HTML comment block.
+       var html_documentation: Writable is lazy do return lines_to_html(content.to_a)
+
+       # Renders markdown line as a HTML comment block.
+       private fun lines_to_html(lines: Array[String]): Writable do
+               var res = new Template
                res.add "<div class=\"nitdoc\">"
                # do not use DocUnit as synopsys
-               if not content.first.has_prefix("    ") and
-                  not content.first.has_prefix("\t") then
-                       # parse synopsys
-                       var syn = inline_proc.process(lines.shift)
-                       res.add "<p class=\"synopsys\">{syn}</p>"
+               if not lines.is_empty then
+                       if not lines.first.has_prefix("    ") and
+                          not lines.first.has_prefix("\t") then
+                               # parse synopsys
+                               var syn = inline_proc.process(lines.shift)
+                               res.add "<p class=\"synopsys\">{syn}</p>"
+                       end
                end
                # check for annotations
                for i in [0 .. lines.length[ do
@@ -70,6 +89,7 @@ redef class MDoc
                res.add markdown_proc.process(lines.join("\n"))
                res.add "</div>"
                return res
+
        end
 end
 
index 6532a1d..fd4fa31 100644 (file)
@@ -375,7 +375,7 @@ redef class MClassPage
                        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
+                       if mdoc != null then lnk.title = mdoc.synopsis
                        var item = new Template
                        item.add new DocHTMLLabel.with_classes(classes)
                        item.add lnk
index b5ccd96..ed895ee 100644 (file)
@@ -44,7 +44,7 @@ redef class MEntity
                var tpl = new Link(nitdoc_url, html_name)
                var mdoc = mdoc_or_fallback
                if mdoc != null then
-                       tpl.title = mdoc.short_comment
+                       tpl.title = mdoc.synopsis
                end
                return tpl
        end
@@ -56,7 +56,7 @@ redef class MEntity
                var tpl = new Link("#{nitdoc_id}", html_name)
                var mdoc = mdoc_or_fallback
                if mdoc != null then
-                       tpl.title = mdoc.short_comment
+                       tpl.title = mdoc.synopsis
                end
                return tpl
        end
@@ -94,18 +94,25 @@ redef class MEntity
        # * MPropdef: `mclassdef:mpropdef`
        fun html_namespace: Template is abstract
 
-       # Returns the comment of this MEntity formatted as HTML.
-       var html_comment: nullable Writable is lazy do
+       # Returns the synopsis and the comment of this MEntity formatted as HTML.
+       var html_documentation: nullable Writable is lazy do
+               var mdoc = mdoc_or_fallback
+               if mdoc == null then return null
+               return mdoc.html_documentation
+       end
+
+       # Returns the synopsis of this MEntity formatted as HTML.
+       var html_synopsis: nullable Writable is lazy do
                var mdoc = mdoc_or_fallback
                if mdoc == null then return null
-               return mdoc.tpl_comment
+               return mdoc.html_synopsis
        end
 
-       # Returns the comment of this MEntity formatted as HTML.
-       var html_short_comment: nullable Writable is lazy do
+       # Returns the the comment without the synopsis formatted as HTML.
+       var html_comment: nullable Writable is lazy do
                var mdoc = mdoc_or_fallback
                if mdoc == null then return null
-               return mdoc.tpl_short_comment
+               return mdoc.html_comment
        end
 
        # Icon that will be displayed before the title
@@ -125,7 +132,7 @@ redef class MEntity
                var tpl = new Template
                tpl.add new DocHTMLLabel.with_classes(css_classes)
                tpl.add html_link
-               var comment = html_short_comment
+               var comment = html_synopsis
                if comment != null then
                        tpl.add ": "
                        tpl.add comment
@@ -688,7 +695,7 @@ redef class MConcern
                var lnk = html_link
                var tpl = new Template
                tpl.add new Link.with_title("#{nitdoc_id}.concern", lnk.text, lnk.title)
-               var comment = html_short_comment
+               var comment = html_synopsis
                if comment != null then
                        tpl.add ": "
                        tpl.add comment
index 6b0bc54..e2567fa 100644 (file)
@@ -446,7 +446,7 @@ redef class IntroArticle
 
        redef fun render_body do
                var tabs = new DocTabs("{html_id}.tabs", "")
-               var comment = mentity.html_comment
+               var comment = mentity.html_documentation
                if comment != null then
                        tabs.add_panel new DocTabPanel("{html_tab_id}-comment", "Comment", comment)
                end
@@ -502,9 +502,9 @@ redef class DefinitionArticle
                if not is_no_body then
                        var comment
                        if is_short_comment then
-                               comment = mentity.html_short_comment
+                               comment = mentity.html_synopsis
                        else
-                               comment = mentity.html_comment
+                               comment = mentity.html_documentation
                        end
                        if comment != null then
                                tabs.add_panel new DocTabPanel("{html_tab_id}-comment", "Comment", comment)
@@ -542,7 +542,7 @@ redef class DefinitionLinArticle
                        if not mentity isa MPropDef then continue # TODO handle all mentities
                        var tpl = new Template
                        tpl.add mentity.mclassdef.html_namespace
-                       var comment = mentity.mclassdef.html_short_comment
+                       var comment = mentity.mclassdef.html_synopsis
                        if comment != null then
                                tpl.add ": "
                                tpl.add comment