src/doc/commands: refactor `CmdCode` and `CmdEntityCode`
authorAlexandre Terrasa <alexandre@moz-code.org>
Tue, 12 Jun 2018 15:17:48 +0000 (11:17 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Fri, 22 Jun 2018 03:42:10 +0000 (23:42 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/doc/commands/commands_html.nit
src/doc/commands/commands_json.nit
src/doc/commands/commands_md.nit
src/doc/commands/commands_model.nit
src/doc/term/term.nit

index c712e6c..88ddfd1 100644 (file)
@@ -125,7 +125,7 @@ redef class CmdEntityLink
        end
 end
 
-redef class CmdEntityCode
+redef class CmdCode
        redef fun to_html do
                var output = render_code(node)
                if output == null then return ""
index b109c87..cdab14e 100644 (file)
@@ -86,7 +86,7 @@ redef class CmdEntityLink
        end
 end
 
-redef class CmdEntityCode
+redef class CmdCode
        redef fun to_json do
                var obj = new JsonObject
                var node = self.node
index 78ca986..b2af510 100644 (file)
@@ -110,7 +110,7 @@ redef class CmdEntityLink
        end
 end
 
-redef class CmdEntityCode
+redef class CmdCode
        redef fun to_md do
                var output = render_code(node)
                if output == null then return ""
index 5b51e3f..ff7862e 100644 (file)
@@ -422,10 +422,10 @@ end
 abstract class CmdCode
        super DocCommand
 
-       autoinit(model, modelbuilder, filter, format)
+       autoinit(model, filter, node, format)
 
-       # ModelBuilder used to get AST nodes
-       var modelbuilder: ModelBuilder
+       # AST node to display code from
+       var node: nullable ANode = null is optional, writable
 
        # Rendering format
        #
@@ -470,8 +470,8 @@ class CmdEntityCode
 
        autoinit(model, modelbuilder, filter, mentity, mentity_name, format)
 
-       # AST node to return
-       var node: nullable ANode = null is optional, writable
+       # ModelBuilder used to get AST nodes from entities
+       var modelbuilder: ModelBuilder
 
        # Same as `CmdEntity::init_mentity`
        #
index fc864bb..de36f05 100644 (file)
@@ -221,13 +221,12 @@ redef class CmdEntityCode
                else
                        print title
                end
-               if no_color == null or not no_color then
+               var node = self.node
+               if (no_color == null or not no_color) and node != null then
                        var ansi = render_code(node)
-                       if ansi != null then
-                               print "~~~"
-                               print ansi.write_to_string
-                               print "~~~"
-                       end
+                       print "~~~"
+                       print ansi.write_to_string
+                       print "~~~"
                else
                        printn mentity.cs_source_code
                end