Abstract command that returns source-code pieces

Introduced properties

private var _format: String

nitc :: CmdCode :: _format

Rendering format
private var _node: nullable ANode

nitc :: CmdCode :: _node

AST node to display code from
init defaultinit(model: Model, filter: nullable ModelFilter, node: nullable ANode, format: nullable String)

nitc :: CmdCode :: defaultinit

fun format: String

nitc :: CmdCode :: format

Rendering format
fun format=(format: nullable String)

nitc :: CmdCode :: format=

Rendering format
fun node: nullable ANode

nitc :: CmdCode :: node

AST node to display code from
fun node=(node: nullable ANode)

nitc :: CmdCode :: node=

AST node to display code from
fun render_code(node: ANode): Writable

nitc :: CmdCode :: render_code

Render node depending on the selected format

Redefined properties

redef type SELF: CmdCode

nitc $ CmdCode :: SELF

Type of this instance, automatically specialized in every class
redef fun http_init(req: HttpRequest): CmdMessage

nitc :: commands_http $ CmdCode :: http_init

Init the command from an HTTPRequest
redef fun parser_init(mentity_name: String, options: CmdOptions): CmdMessage

nitc :: commands_parser $ CmdCode :: parser_init

Initialize the command from the CommandParser data
redef fun render_code(node: ANode): Writable

nitc :: md_commands $ CmdCode :: render_code

Render node depending on the selected format
redef fun render_code(node: ANode): Writable

nitc :: html_commands $ CmdCode :: render_code

Render node depending on the selected format
redef fun to_html: Writable

nitc :: html_commands $ CmdCode :: to_html

Render results as a HTML string
redef fun to_json: nullable Serializable

nitc :: json_commands $ CmdCode :: to_json

Return a JSON Serializable representation of self results
redef fun to_md: Writable

nitc :: md_commands $ CmdCode :: to_md

Render results as a Markdown string

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
private var _filter: nullable ModelFilter

nitc :: DocCommand :: _filter

ModelFilter to apply if any
private var _format: String

nitc :: CmdCode :: _format

Rendering format
private var _model: Model

nitc :: DocCommand :: _model

Model to retrieve data for
private var _node: nullable ANode

nitc :: CmdCode :: _node

AST node to display code from
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun cmd_filter: ModelFilter

nitc :: DocCommand :: cmd_filter

Return a new filter for that command execution.
init defaultinit(model: Model, filter: nullable ModelFilter, node: nullable ANode, format: nullable String)

nitc :: CmdCode :: defaultinit

init defaultinit(model: Model, filter: nullable ModelFilter)

nitc :: DocCommand :: defaultinit

abstract fun execute(no_color: nullable Bool)

nitc :: DocCommand :: execute

fun filter: nullable ModelFilter

nitc :: DocCommand :: filter

ModelFilter to apply if any
protected fun filter=(filter: nullable ModelFilter)

nitc :: DocCommand :: filter=

ModelFilter to apply if any
fun format: String

nitc :: CmdCode :: format

Rendering format
fun format=(format: nullable String)

nitc :: CmdCode :: format=

Rendering format
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
fun http_init(req: HttpRequest): CmdMessage

nitc :: DocCommand :: http_init

Init the command from an HTTPRequest
init init

core :: Object :: init

fun init_command: CmdMessage

nitc :: DocCommand :: init_command

Initialize the command
fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun model: Model

nitc :: DocCommand :: model

Model to retrieve data for
protected fun model=(model: Model)

nitc :: DocCommand :: model=

Model to retrieve data for
private intern fun native_class_name: CString

core :: Object :: native_class_name

The class name of the object in CString format.
fun node: nullable ANode

nitc :: CmdCode :: node

AST node to display code from
fun node=(node: nullable ANode)

nitc :: CmdCode :: node=

AST node to display code from
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun parser_init(arg: String, options: CmdOptions): CmdMessage

nitc :: DocCommand :: parser_init

Initialize the command from the CommandParser data
fun render_code(node: ANode): Writable

nitc :: CmdCode :: render_code

Render node depending on the selected format
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun to_html: Writable

nitc :: DocCommand :: to_html

Render results as a HTML string
abstract fun to_json: nullable Serializable

nitc :: DocCommand :: to_json

Return a JSON Serializable representation of self results
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_md: Writable

nitc :: DocCommand :: to_md

Render results as a Markdown string
fun to_s: String

core :: Object :: to_s

User readable representation of self.
package_diagram nitc::CmdCode CmdCode nitc::DocCommand DocCommand nitc::CmdCode->nitc::DocCommand core::Object Object nitc::DocCommand->core::Object ...core::Object ... ...core::Object->core::Object nitc::CmdEntityCode CmdEntityCode nitc::CmdEntityCode->nitc::CmdCode

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

abstract class DocCommand

nitc :: DocCommand

Documentation command

Children

class CmdEntityCode

nitc :: CmdEntityCode

Cmd that finds the source code related to an mentity

Class definitions

nitc $ CmdCode
# 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

nitc :: commands_parser $ CmdCode
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

nitc :: commands_http $ CmdCode
redef class CmdCode
	redef fun http_init(req) do
		var opt_format = req.string_arg("format")
		if opt_format != null then format = opt_format
		return super
	end
end
src/doc/commands/commands_http.nit:167,1--173,3

nitc :: md_commands $ CmdCode
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

nitc :: json_commands $ CmdCode
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

nitc :: html_commands $ CmdCode
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