redef class CmdCode
redef fun to_html do
- var output = render_code(node)
- if output == null then return ""
- return "<pre>{output.write_to_string}</pre>"
+ var node = self.node
+ if node == null then return ""
+
+ var code = render_code(node)
+ return "<pre>{code.write_to_string}</pre>"
+ end
+
+ redef fun render_code(node) do
+ if format == "html" then
+ var hl = new CmdHtmlightVisitor
+ hl.show_infobox = false
+ hl.highlight_node node
+ return hl.html
+ end
+ return super
+ end
+end
+
+# Custom HtmlightVisitor for commands
+#
+# We create a new subclass so its behavior can be refined in clients without
+# breaking the main implementation.
+class CmdHtmlightVisitor
+ super HtmlightVisitor
+
+ redef fun hrefto(mentity) do
+ if mentity isa MClassDef then return mentity.mclass.html_url
+ if mentity isa MPropDef then return mentity.mproperty.html_url
+ return mentity.html_url
end
end
return "<pre>{command}</pre>"
end
end
-
-# Misc
-
-redef class CmdHtmlightVisitor
- redef fun hrefto(mentity) do
- if mentity isa MClassDef then return mentity.mclass.html_url
- if mentity isa MPropDef then return mentity.mproperty.html_url
- return mentity.html_url
- end
-end
redef fun to_json do
var obj = new JsonObject
var node = self.node
- if node != null then
- obj["location"] = node.location
- end
- var output = render_code(node)
- if output != null then
- obj["code"] = output.write_to_string
- end
+ if node == null then return obj
+
+ var code = render_code(node)
+ obj["location"] = node.location
+ obj["code"] = code.write_to_string
return obj
end
end
redef class CmdCode
redef fun to_md do
- var output = render_code(node)
- if output == null then return ""
+ var node = self.node
+ if node == null then return ""
+ var code = render_code(node)
var tpl = new Template
tpl.addn "~~~nit"
- tpl.add output.write_to_string
+ tpl.add code.write_to_string
tpl.addn "~~~"
return tpl.write_to_string
end
+
+ redef fun render_code(node) do
+ if format == "ansi" then
+ var hl = new AnsiHighlightVisitor
+ hl.highlight_node node
+ return hl.result
+ end
+ return super
+ end
end
redef class CmdAncestors
module commands_model
import commands_base
-
-import model::model_collect
import modelize
-import modelbuilder
-import htmlight
# Retrieve the MDoc related to a MEntity
class CmdComment
var format = "raw" is optional, writable
# Render `node` depending on the selected `format`
- fun render_code(node: nullable ANode): nullable Writable do
- if node == null then return null
- if format == "html" then
- var hl = new CmdHtmlightVisitor
- hl.show_infobox = false
- hl.highlight_node node
- return hl.html
- else if format == "ansi" then
- var hl = new AnsiHighlightVisitor
- hl.highlight_node node
- return hl.result
- end
+ fun render_code(node: ANode): Writable do
return node.location.text
end
end
-# Custom HtmlightVisitor for commands
-#
-# We create a new subclass so its behavior can be refined in clients without
-# breaking the main implementation.
-class CmdHtmlightVisitor
- super HtmlightVisitor
-end
-
# Cmd that finds the source code related to an `mentity`
class CmdEntityCode
super CmdEntity