# This file is part of NIT ( http://www.nitlanguage.org ).
#
-# Copyright 2008 Jean Privat <jean@pryen.org>
-#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# See the License for the specific language governing permissions and
# limitations under the License.
+# ni or nit index, is a command tool used to display documentation
module ni
import model_utils
init(toolcontext: ToolContext) do
# We need a model to collect stufs
self.toolcontext = toolcontext
+ self.toolcontext.option_context.options.clear
self.arguments = toolcontext.option_context.rest
- if arguments.length > 2 then
+ if arguments.is_empty or arguments.length > 2 then
print "usage: ni path/to/module.nit [expression]"
toolcontext.option_context.usage
exit(1)
pager.add("known clients: ".bold + "{mmodule.in_importation.direct_smallers.join(", ")}\n")
end
pager.add_rule
- pager.addn(nmodule.comment.green)
+ pager.addn(nmodule.n_moduledecl.n_doc.comment.green)
pager.add_rule
var cats = new HashMap[String, Collection[MClass]]
for mclass in sorted do
var nclass = mbuilder.mclassdef2nclassdef[mclass.intro].as(AStdClassdef)
pager.add("")
- if not nclass.short_comment.is_empty then
- pager.add("\t# {nclass.short_comment}")
+ if not nclass.n_doc == null and not nclass.n_doc.short_comment.is_empty then
+ pager.add("\t# {nclass.n_doc.short_comment}")
end
if cat == "refined classes" then
pager.add("\tredef {mclass.short_doc}")
pager.add("# {mclass.namespace}\n".bold)
pager.add("{mclass.short_doc}")
pager.add_rule
- pager.addn(nclass.comment.green)
+ pager.addn(nclass.n_doc.comment.green)
pager.add_rule
if not mclass.parameter_types.is_empty then
pager.add("# formal types".bold)
private fun method_fulldoc(pager: Pager, mprop: MMethod) do
if mbuilder.mpropdef2npropdef.has_key(mprop.intro) then
var nprop = mbuilder.mpropdef2npropdef[mprop.intro]
- if not nprop.short_comment.is_empty then
- pager.add("\t# {nprop.short_comment}")
+ if not nprop.n_doc == null and not nprop.n_doc.short_comment.is_empty then
+ pager.add("\t# {nprop.n_doc.short_comment}")
end
if nprop isa AAttrPropdef then
pager.add("\t{nprop.read_accessor}")
end
end
-redef class AModule
+redef class ADoc
private fun comment: String do
- var ret = ""
- for t in n_moduledecl.n_doc.n_comment do
- ret += "{t.text.replace("# ", "")}"
+ var res = new Buffer
+ for t in n_comment do
+ res.append(t.text.replace("# ", "").replace("#", ""))
end
- return ret
- end
-end
-
-redef class AStdClassdef
- private fun comment: String do
- var ret = ""
- if n_doc != null then
- for t in n_doc.n_comment do
- var txt = t.text.replace("# ", "")
- txt = txt.replace("#", "")
- ret += "{txt}"
- end
- end
- return ret
+ return res.to_s
end
private fun short_comment: String do
- var ret = ""
- if n_doc != null then
- var txt = n_doc.n_comment.first.text
- txt = txt.replace("# ", "")
- txt = txt.replace("\n", "")
- ret += txt
- end
- return ret
+ return n_comment.first.text.replace("# ", "").replace("\n", "")
end
end
-redef class APropdef
- private fun short_comment: String is abstract
-end
-
redef class AAttrPropdef
- redef fun short_comment do
- var ret = ""
- if n_doc != null then
- var txt = n_doc.n_comment.first.text
- txt = txt.replace("# ", "")
- txt = txt.replace("\n", "")
- ret += txt
- end
- return ret
- end
-
private fun read_accessor: String do
var ret = "fun "
#FIXME bug with standard::stream::FDStream::fd
end
redef class AMethPropdef
- redef fun short_comment do
- var ret = ""
- if n_doc != null then
- var txt = n_doc.n_comment.first.text
- txt = txt.replace("# ", "")
- txt = txt.replace("\n", "")
- ret += txt
- end
- return ret
- end
-
redef fun to_s do
var ret = ""
if not mpropdef.mproperty.is_init then