nitc :: CmdCode :: defaultinit
nitc :: CmdCode :: render_code
Rendernode
depending on the selected format
nitc :: commands_http $ CmdCode :: http_init
Init the command from an HTTPRequestnitc :: commands_parser $ CmdCode :: parser_init
Initialize the command from the CommandParser datanitc :: md_commands $ CmdCode :: render_code
Rendernode
depending on the selected format
nitc :: html_commands $ CmdCode :: render_code
Rendernode
depending on the selected format
nitc :: json_commands $ CmdCode :: to_json
Return a JSON Serializable representation ofself
results
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
nitc :: DocCommand :: cmd_filter
Return a new filter for that command execution.nitc :: CmdCode :: defaultinit
core :: Object :: defaultinit
nitc :: DocCommand :: defaultinit
nitc :: DocCommand :: execute
nitc :: DocCommand :: filter=
ModelFilter to apply if anynitc :: DocCommand :: http_init
Init the command from an HTTPRequestcore :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).nitc :: DocCommand :: parser_init
Initialize the command from the CommandParser datanitc :: CmdCode :: render_code
Rendernode
depending on the selected format
nitc :: DocCommand :: to_json
Return a JSON Serializable representation ofself
results
# Abstract command that returns source-code pieces
abstract class CmdCode
super DocCommand
autoinit(model, filter, node, format)
# AST node to display code from
var node: nullable ANode = null is optional, writable
# Rendering format
#
# Set the output format for this piece of code.
# Can be "raw", "html" or "ansi".
# Default is "raw".
#
# This format can be different than the format used in the command response.
# For example you can choose to render code as HTML inside a JSON object response.
# 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: ANode): Writable do
return node.location.text
end
end
src/doc/commands/commands_model.nit:417,1--441,3
redef class CmdCode
redef fun parser_init(mentity_name, options) do
var opt_format = options.opt_string("format")
if opt_format != null then format = opt_format
return super
end
end
src/doc/commands/commands_parser.nit:325,1--331,3
redef class CmdCode
redef fun to_md do
var node = self.node
if node == null then return ""
var code = render_code(node)
var tpl = new Template
tpl.addn "~~~nit"
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
src/doc/templates/md_commands.nit:114,1--135,3
redef class CmdCode
redef fun to_json do
var obj = new JsonObject
var node = self.node
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
src/doc/templates/json_commands.nit:88,1--99,3
redef class CmdCode
redef fun to_html do
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
src/doc/templates/html_commands.nit:130,1--148,3