Structured documentation of a MEntity object

Introduced properties

private var _comment: String

nitc :: MDoc :: _comment

All comment lines except for the synopsis
private var _content: Array[String]

nitc :: MDoc :: _content

Raw content, line by line
private var _documentation: String

nitc :: MDoc :: _documentation

Full comment
private var _html_comment: Writable

nitc :: MDoc :: _html_comment

Renders the comment without the synopsis as a HTML comment block.
private var _html_documentation: Writable

nitc :: MDoc :: _html_documentation

Renders the synopsis and the comment as a HTML comment block.
private var _html_synopsis: Writable

nitc :: MDoc :: _html_synopsis

Renders the synopsis as a HTML comment block.
private var _location: Location

nitc :: MDoc :: _location

The original location of the doc for error messages
private var _md_comment: Writable

nitc :: MDoc :: _md_comment

private var _md_documentation: Writable

nitc :: MDoc :: _md_documentation

Renders the synopsis and the comment as a HTML comment block.
private var _md_synopsis: Writable

nitc :: MDoc :: _md_synopsis

Renders the synopsis as a HTML comment block.
private var _original_mentity: nullable MEntity

nitc :: MDoc :: _original_mentity

The entity where the documentation is originally attached to.
private var _synopsis: String

nitc :: MDoc :: _synopsis

The comment first line
fun comment: String

nitc :: MDoc :: comment

All comment lines except for the synopsis
protected fun comment=(comment: String)

nitc :: MDoc :: comment=

All comment lines except for the synopsis
fun content: Array[String]

nitc :: MDoc :: content

Raw content, line by line
protected fun content=(content: Array[String])

nitc :: MDoc :: content=

Raw content, line by line
fun cs_comment(no_color: nullable Bool, indent: nullable Int): String

nitc :: MDoc :: cs_comment

Returns the full comment formatted for the console
fun cs_short_comment(no_color: nullable Bool): String

nitc :: MDoc :: cs_short_comment

Returns the synopsis formatted for the console
init defaultinit(location: Location)

nitc :: MDoc :: defaultinit

fun documentation: String

nitc :: MDoc :: documentation

Full comment
protected fun documentation=(documentation: String)

nitc :: MDoc :: documentation=

Full comment
fun fill_infobox(res: HInfoBox)

nitc :: MDoc :: fill_infobox

Append an entry for the doc in the given infobox
fun html_comment: Writable

nitc :: MDoc :: html_comment

Renders the comment without the synopsis as a HTML comment block.
protected fun html_comment=(html_comment: Writable)

nitc :: MDoc :: html_comment=

Renders the comment without the synopsis as a HTML comment block.
fun html_documentation: Writable

nitc :: MDoc :: html_documentation

Renders the synopsis and the comment as a HTML comment block.
protected fun html_documentation=(html_documentation: Writable)

nitc :: MDoc :: html_documentation=

Renders the synopsis and the comment as a HTML comment block.
fun html_synopsis: Writable

nitc :: MDoc :: html_synopsis

Renders the synopsis as a HTML comment block.
protected fun html_synopsis=(html_synopsis: Writable)

nitc :: MDoc :: html_synopsis=

Renders the synopsis as a HTML comment block.
private fun lines_to_html(lines: Array[String]): Writable

nitc :: MDoc :: lines_to_html

Renders markdown line as a HTML comment block.
private fun lines_to_md(lines: Array[String]): Writable

nitc :: MDoc :: lines_to_md

fun location: Location

nitc :: MDoc :: location

The original location of the doc for error messages
protected fun location=(location: Location)

nitc :: MDoc :: location=

The original location of the doc for error messages
protected fun md_comment=(md_comment: Writable)

nitc :: MDoc :: md_comment=

fun md_documentation: Writable

nitc :: MDoc :: md_documentation

Renders the synopsis and the comment as a HTML comment block.
protected fun md_documentation=(md_documentation: Writable)

nitc :: MDoc :: md_documentation=

Renders the synopsis and the comment as a HTML comment block.
fun md_synopsis: Writable

nitc :: MDoc :: md_synopsis

Renders the synopsis as a HTML comment block.
protected fun md_synopsis=(md_synopsis: Writable)

nitc :: MDoc :: md_synopsis=

Renders the synopsis as a HTML comment block.
fun original_mentity: nullable MEntity

nitc :: MDoc :: original_mentity

The entity where the documentation is originally attached to.
fun original_mentity=(original_mentity: nullable MEntity)

nitc :: MDoc :: original_mentity=

The entity where the documentation is originally attached to.
fun synopsis: String

nitc :: MDoc :: synopsis

The comment first line
protected fun synopsis=(synopsis: String)

nitc :: MDoc :: synopsis=

The comment first line

Redefined properties

redef type SELF: MDoc

nitc $ MDoc :: SELF

Type of this instance, automatically specialized in every class
redef fun core_serialize_to(v: Serializer)

nitc :: json_model $ MDoc :: core_serialize_to

Actual serialization of self to serializer
redef init from_deserializer(v: Deserializer)

nitc :: json_model $ MDoc :: from_deserializer

Create an instance of this class from the deserializer

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 _comment: String

nitc :: MDoc :: _comment

All comment lines except for the synopsis
private var _content: Array[String]

nitc :: MDoc :: _content

Raw content, line by line
private var _documentation: String

nitc :: MDoc :: _documentation

Full comment
private var _html_comment: Writable

nitc :: MDoc :: _html_comment

Renders the comment without the synopsis as a HTML comment block.
private var _html_documentation: Writable

nitc :: MDoc :: _html_documentation

Renders the synopsis and the comment as a HTML comment block.
private var _html_synopsis: Writable

nitc :: MDoc :: _html_synopsis

Renders the synopsis as a HTML comment block.
private var _location: Location

nitc :: MDoc :: _location

The original location of the doc for error messages
private var _md_comment: Writable

nitc :: MDoc :: _md_comment

private var _md_documentation: Writable

nitc :: MDoc :: _md_documentation

Renders the synopsis and the comment as a HTML comment block.
private var _md_synopsis: Writable

nitc :: MDoc :: _md_synopsis

Renders the synopsis as a HTML comment block.
private var _original_mentity: nullable MEntity

nitc :: MDoc :: _original_mentity

The entity where the documentation is originally attached to.
private var _synopsis: String

nitc :: MDoc :: _synopsis

The comment first line
protected fun accept_json_serializer(v: JsonSerializer)

serialization :: Serializable :: accept_json_serializer

Refinable service to customize the serialization of this class to JSON
protected fun accept_msgpack_attribute_counter(v: AttributeCounter)

serialization :: Serializable :: accept_msgpack_attribute_counter

Hook to customize the behavior of the AttributeCounter
protected fun accept_msgpack_serializer(v: MsgPackSerializer)

serialization :: Serializable :: accept_msgpack_serializer

Hook to customize the serialization of this class to MessagePack
protected fun add_to_bundle(bundle: NativeBundle, key: JavaString)

serialization :: Serializable :: add_to_bundle

Called by []= to dynamically choose the appropriate method according
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 comment: String

nitc :: MDoc :: comment

All comment lines except for the synopsis
protected fun comment=(comment: String)

nitc :: MDoc :: comment=

All comment lines except for the synopsis
fun content: Array[String]

nitc :: MDoc :: content

Raw content, line by line
protected fun content=(content: Array[String])

nitc :: MDoc :: content=

Raw content, line by line
fun core_serialize_to(serializer: Serializer)

serialization :: Serializable :: core_serialize_to

Actual serialization of self to serializer
fun cs_comment(no_color: nullable Bool, indent: nullable Int): String

nitc :: MDoc :: cs_comment

Returns the full comment formatted for the console
fun cs_short_comment(no_color: nullable Bool): String

nitc :: MDoc :: cs_short_comment

Returns the synopsis formatted for the console
init defaultinit(location: Location)

nitc :: MDoc :: defaultinit

fun documentation: String

nitc :: MDoc :: documentation

Full comment
protected fun documentation=(documentation: String)

nitc :: MDoc :: documentation=

Full comment
fun fill_infobox(res: HInfoBox)

nitc :: MDoc :: fill_infobox

Append an entry for the doc in the given infobox
init from_deserializer(deserializer: Deserializer)

serialization :: Serializable :: from_deserializer

Create an instance of this class from the deserializer
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 html_comment: Writable

nitc :: MDoc :: html_comment

Renders the comment without the synopsis as a HTML comment block.
protected fun html_comment=(html_comment: Writable)

nitc :: MDoc :: html_comment=

Renders the comment without the synopsis as a HTML comment block.
fun html_documentation: Writable

nitc :: MDoc :: html_documentation

Renders the synopsis and the comment as a HTML comment block.
protected fun html_documentation=(html_documentation: Writable)

nitc :: MDoc :: html_documentation=

Renders the synopsis and the comment as a HTML comment block.
fun html_synopsis: Writable

nitc :: MDoc :: html_synopsis

Renders the synopsis as a HTML comment block.
protected fun html_synopsis=(html_synopsis: Writable)

nitc :: MDoc :: html_synopsis=

Renders the synopsis as a HTML comment block.
init init

core :: Object :: init

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.
private fun lines_to_html(lines: Array[String]): Writable

nitc :: MDoc :: lines_to_html

Renders markdown line as a HTML comment block.
private fun lines_to_md(lines: Array[String]): Writable

nitc :: MDoc :: lines_to_md

fun location: Location

nitc :: MDoc :: location

The original location of the doc for error messages
protected fun location=(location: Location)

nitc :: MDoc :: location=

The original location of the doc for error messages
protected fun md_comment=(md_comment: Writable)

nitc :: MDoc :: md_comment=

fun md_documentation: Writable

nitc :: MDoc :: md_documentation

Renders the synopsis and the comment as a HTML comment block.
protected fun md_documentation=(md_documentation: Writable)

nitc :: MDoc :: md_documentation=

Renders the synopsis and the comment as a HTML comment block.
fun md_synopsis: Writable

nitc :: MDoc :: md_synopsis

Renders the synopsis as a HTML comment block.
protected fun md_synopsis=(md_synopsis: Writable)

nitc :: MDoc :: md_synopsis=

Renders the synopsis as a HTML comment block.
protected fun msgpack_extra_array_items: Int

serialization :: Serializable :: msgpack_extra_array_items

Hook to request a larger than usual metadata array
private intern fun native_class_name: CString

core :: Object :: native_class_name

The class name of the object in CString format.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun original_mentity: nullable MEntity

nitc :: MDoc :: original_mentity

The entity where the documentation is originally attached to.
fun original_mentity=(original_mentity: nullable MEntity)

nitc :: MDoc :: original_mentity=

The entity where the documentation is originally attached to.
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 serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun serialize_msgpack(plain: nullable Bool): Bytes

serialization :: Serializable :: serialize_msgpack

Serialize self to MessagePack bytes
fun serialize_to(serializer: Serializer)

serialization :: Serializable :: serialize_to

Serialize self to serializer
fun serialize_to_json(plain: nullable Bool, pretty: nullable Bool): String

serialization :: Serializable :: serialize_to_json

Serialize self to JSON
private fun serialize_to_or_delay(v: Serializer)

serialization :: Serializable :: serialize_to_or_delay

Accept references or force direct serialization (using serialize_to)
fun synopsis: String

nitc :: MDoc :: synopsis

The comment first line
protected fun synopsis=(synopsis: String)

nitc :: MDoc :: synopsis=

The comment first line
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun to_json: String

serialization :: Serializable :: to_json

Serialize self to plain JSON
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_pretty_json: String

serialization :: Serializable :: to_pretty_json

Serialize self to plain pretty JSON
fun to_s: String

core :: Object :: to_s

User readable representation of self.
package_diagram nitc::MDoc MDoc serialization::Serializable Serializable nitc::MDoc->serialization::Serializable core::Object Object serialization::Serializable->core::Object ...core::Object ... ...core::Object->core::Object

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

interface Serializable

serialization :: Serializable

Instances of this class can be passed to Serializer::serialize

Class definitions

nitc $ MDoc
# Structured documentation of a `MEntity` object
class MDoc
	# Raw content, line by line
	# The starting `#` and first space are stripped.
	# The trailing `\n` are chomped.
	var content = new Array[String]

	# The entity where the documentation is originally attached to.
	# This gives some context to resolve identifiers or to run examples.
	var original_mentity: nullable MEntity = null is writable

	# The original location of the doc for error messages
	var location: Location

	# The comment first line
	var synopsis: String is lazy do return content.first

	# All comment lines except for the synopsis
	var comment: String is lazy do
		var lines = content.to_a
		if not lines.is_empty then lines.shift
		return lines.join("\n")
	end

	# Full comment
	var documentation: String is lazy do return content.join("\n")
end
src/model/mdoc.nit:21,1--47,3

nitc :: term_model $ MDoc
redef class MDoc
	# Returns the full comment formatted for the console
	fun cs_comment(no_color: nullable Bool, indent: nullable Int): String do
		var res = new FlatBuffer
		indent = indent or else 0
		for line in content do
			res.append "{" " * indent}{line}\n"
		end
		if no_color == null or not no_color then
			return res.write_to_string.green
		end
		return res.write_to_string
	end

	# Returns the synopsis formatted for the console
	fun cs_short_comment(no_color: nullable Bool): String do
		if no_color == null or not no_color then
			return content.first.green
		end
		return content.first
	end
end
src/doc/templates/term_model.nit:24,1--45,3

nitc :: htmlight $ MDoc
redef class MDoc
	# Append an entry for the doc in the given infobox
	fun fill_infobox(res: HInfoBox)
	do
		if content.length < 2 then
			res.new_field("doc").text(content.first)
			return
		end
		var c = res.new_dropdown("doc", content.first)
		for x in content.iterator.skip_head(1) do
			c.append x
			c.add_raw_html "<br>"
		end
	end
end
src/htmlight.nit:424,1--438,3

nitc :: md_commands $ MDoc
redef class MDoc

	# Renders the synopsis as a HTML comment block.
	var md_synopsis: Writable is lazy do
		if content.is_empty then return ""
		return content.first
	end

	#
	var md_comment: Writable is lazy do
		if content.is_empty then return ""
		var lines = content.to_a
		lines.shift
		return lines.join("\n")
	end

	# Renders the synopsis and the comment as a HTML comment block.
	var md_documentation: Writable is lazy do return lines_to_md(content.to_a)

	private fun lines_to_md(lines: Array[String]): Writable do
		var res = new Template
		if not lines.is_empty then
			var syn = lines.first
			if not syn.has_prefix("    ") and not syn.has_prefix("\t") and
			  not syn.trim.has_prefix("#") then
				lines.shift
				res.add "# {syn}\n"
			end
		end
		res.add lines.join("\n")
		return res
	end
end
src/doc/templates/md_commands.nit:348,1--380,3

nitc :: html_model $ MDoc
redef class MDoc

	private var markdown_proc: MarkdownProcessor is lazy, writable do
		return original_mentity.as(not null).model.nitdoc_md_processor
	end

	private var inline_proc: MarkdownProcessor is lazy, writable do
		return original_mentity.as(not null).model.nitdoc_inline_processor
	end

	# Renders the synopsis as a HTML comment block.
	var html_synopsis: Writable is lazy do
		var res = new Template
		var syn = inline_proc.process(content.first)
		res.add "<span class=\"synopsis nitdoc\">{syn}</span>"
		return res
	end

	# Renders the comment without the synopsis as a HTML comment block.
	var html_comment: Writable is lazy do
		var lines = content.to_a
		if not lines.is_empty then lines.shift
		return lines_to_html(lines)
	end

	# Renders the synopsis and the comment as a HTML comment block.
	var html_documentation: Writable is lazy do return lines_to_html(content.to_a)

	# Renders markdown line as a HTML comment block.
	private fun lines_to_html(lines: Array[String]): Writable do
		var res = new Template
		var decorator = markdown_proc.decorator.as(NitdocDecorator)
		decorator.current_mdoc = self
		res.add "<div class=\"nitdoc\">"
		# do not use DocUnit as synopsis
		if not lines.is_empty then
			if not lines.first.has_prefix("    ") and
			   not lines.first.has_prefix("\t") then
				# parse synopsis
				var syn = inline_proc.process(lines.shift)
				res.add "<h1 class=\"synopsis\">{syn}</h1>"
			end
		end
		# check for annotations
		for i in [0 .. lines.length[ do
			var line = lines[i]
			if line.to_upper.has_prefix("ENSURE") or line.to_upper.has_prefix("REQUIRE") then
				var html = inline_proc.process(line)
				lines[i] = "<p class=\"contract\">{html}</p>"
			else if line.to_upper.has_prefix("TODO") or line.to_upper.has_prefix("FIXME") then
				var html = inline_proc.process(line)
				lines[i] = "<p class=\"todo\">{html}</p>"
			end
		end
		# add other lines
		res.add markdown_proc.process(lines.join("\n"))
		res.add "</div>"
		decorator.current_mdoc = null
		return res
	end
end
src/doc/templates/html_model.nit:385,1--445,3

nitc :: json_model $ MDoc
redef class MDoc
	serialize

	redef fun core_serialize_to(v) do
		var doc = html_documentation.write_to_string.trim
		if not doc.is_empty then
			v.serialize_attribute("html_documentation", doc)
		end
	end
end
src/doc/templates/json_model.nit:69,1--78,3