src/doc: migrate showsource links to new templates
authorAlexandre Terrasa <alexandre@moz-code.org>
Tue, 24 Feb 2015 13:28:42 +0000 (14:28 +0100)
committerAlexandre Terrasa <alexandre@moz-code.org>
Tue, 5 May 2015 15:56:57 +0000 (11:56 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

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

index f88be01..a3fbf07 100644 (file)
@@ -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
@@ -501,11 +501,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
@@ -520,7 +520,9 @@ redef class DefinitionArticle
                        title.add mentity.html_namespace
                        html_title = title
                        toc_title = mentity.html_name
-                       # article.source_link = v.tpl_showsource(mentity.location)
+                       if mentity isa MModule then
+                               html_source_link = v.html_source_link(mentity.location)
+                       end
                else if mentity isa MClass then
                        var title = new Template
                        title.add mentity.html_icon
@@ -536,7 +538,7 @@ redef class DefinitionArticle
                        html_title = mentity.html_declaration
                        html_subtitle = title
                        toc_title = "in {mentity.html_name}"
-                       # article.source_link = v.tpl_showsource(mentity.location)
+                       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
@@ -556,7 +558,7 @@ redef class DefinitionArticle
                                html_title = title
                                toc_title = "in {mentity.mclassdef.html_name}"
                        end
-                       # article.source_link = v.tpl_showsource(mentity.location)
+                       html_source_link = v.html_source_link(mentity.location)
                end
                super
        end
@@ -587,13 +589,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
index aa1708c..cc5f9f4 100644 (file)
@@ -442,6 +442,19 @@ redef class IntroArticle
        redef var is_hidden = false
        redef var is_toc_hidden = true
 
+       # Link to source to display if any.
+       var html_source_link: nullable Writable is noinit, writable
+
+       redef fun render_title do
+               var lnk = html_source_link
+               if lnk != null then
+                       add "<div class='source-link'>"
+                       add lnk
+                       addn "</div>"
+               end
+               super
+       end
+
        redef fun render_body do
                var comment = mentity.html_comment
                if comment != null then addn comment
@@ -472,6 +485,19 @@ redef class DefinitionArticle
        # FIXME diff hack
        var is_short_comment: Bool = false is writable
 
+       # Link to source to display if any.
+       var html_source_link: nullable Writable is noinit, writable
+
+       redef fun render_title do
+               var lnk = html_source_link
+               if lnk != null then
+                       add "<div class='source-link'>"
+                       add lnk
+                       addn "</div>"
+               end
+               super
+       end
+
        redef fun render_body do
                if not is_no_body then
                        var comment