end
redef class CmdEntity
-
-
redef fun http_init(req) do
var name = req.param("id")
if name != null then name = name.from_percent_encoding
end
end
+redef class CmdEntityCode
+ # FIXME avoid linearization conflict
+ redef fun http_init(req) do
+ var name = req.param("id")
+ if name != null then name = name.from_percent_encoding
+ mentity_name = name
+
+ format = req.string_arg("format") or else "raw"
+ return init_command
+ end
+end
+
# CmdGraph
redef class CmdGraph
redef fun to_s do return "No features for `{mentity.full_name}`"
end
-# Cmd that finds the source code related to an `mentity`
-class CmdCode
- super CmdEntity
+# Abstract command that returns source-code pieces
+abstract class CmdCode
+ super DocCommand
- autoinit(view, modelbuilder, mentity, mentity_name, format)
+ autoinit(view, modelbuilder, format)
# ModelBuilder used to get AST nodes
var modelbuilder: ModelBuilder
- # AST node to return
- var node: nullable ANode = null is optional, writable
-
# Rendering format
#
# Set the output format for this piece of code.
# Another example is to render raw format to put into a HTML code tag.
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 HtmlightVisitor
+ hl.highlight_node node
+ return hl.html
+ else if format == "ansi" then
+ var hl = new AnsiHighlightVisitor
+ hl.highlight_node node
+ return hl.result
+ end
+ return node.location.text
+ end
+end
+
+# Cmd that finds the source code related to an `mentity`
+class CmdEntityCode
+ super CmdEntity
+ super CmdCode
+
+ autoinit(view, modelbuilder, mentity, mentity_name, format)
+
+ # AST node to return
+ var node: nullable ANode = null is optional, writable
+
# Same as `CmdEntity::init_mentity`
#
# Plus `WarningNoCode` if no code/AST node is found for `mentity`.
if node == null then return new WarningNoCode(mentity)
return res
end
-
- # Render `node` depending on the selected `format`
- fun render: nullable Writable do
- var node = self.node
- if node == null then return null
- if format == "html" then
- var hl = new HtmlightVisitor
- hl.highlight_node node
- return hl.html
- else if format == "ansi" then
- var hl = new AnsiHighlightVisitor
- hl.highlight_node node
- return hl.result
- end
- var mentity = self.mentity
- if mentity == null then return null
- return mentity.location.text
- end
end
# No code for `mentity`
fun new_command(name: String): nullable DocCommand do
# CmdEntity
if name == "doc" then return new CmdComment(view)
- if name == "code" then return new CmdCode(view, modelbuilder)
+ if name == "code" then return new CmdEntityCode(view, modelbuilder)
if name == "lin" then return new CmdLinearization(view)
if name == "defs" then return new CmdFeatures(view)
if name == "parents" then return new CmdParents(view)