# This file is part of NIT ( http://www.nitlanguage.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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Program to test the `markdown` module on real source files.
module test_docdown
import modelize
import highlight
import docdown
redef class ModelBuilder
fun do_test_markdown(page: HTMLTag, mmodule: MModule)
do
page.add_raw_html "
module {mmodule}"
var mdoc = mmodule.mdoc
if mdoc != null then
page.add mdoc.full_markdown
end
for mclassdef in mmodule.mclassdefs do
mdoc = mclassdef.mdoc
if mdoc != null then
page.add_raw_html "class {mclassdef}"
page.add mdoc.full_markdown
end
for mpropdef in mclassdef.mpropdefs do
mdoc = mpropdef.mdoc
if mdoc != null then
page.add_raw_html "prop {mpropdef}
"
page.add mdoc.full_markdown
end
end
end
end
end
redef class MModule
redef fun href do return "#{to_s}"
end
redef class MClassDef
redef fun href do return "#{to_s}"
end
redef class MPropDef
redef fun href do return "#{to_s}"
end
var toolcontext = new ToolContext
var opt_full = new OptionBool("Process also imported modules", "--full")
toolcontext.option_context.add_option(opt_full)
toolcontext.tooldescription = "Usage: test_markdown [OPTION]... ...\nGenerates HTML of comments of documentation from Nit source files."
toolcontext.process_options(args)
var args = toolcontext.option_context.rest
var model = new Model
var modelbuilder = new ModelBuilder(model, toolcontext)
var mmodules = modelbuilder.parse(args)
modelbuilder.run_phases
var hv = new HighlightVisitor
var page = new HTMLTag("html")
page.add_raw_html """
"""
page.add_raw_html hv.head_content
page.add_raw_html """
"""
if opt_full.value then
for p in model.mprojects do
page.add_raw_html "project {p.name}"
var mdoc = p.mdoc
if mdoc != null then
page.add mdoc.full_markdown
end
for g in p.mgroups do
mdoc = g.mdoc
if mdoc != null then
page.add_raw_html "group {g.full_name}
"
page.add mdoc.full_markdown
end
for m in g.mmodules do
modelbuilder.do_test_markdown(page, m)
end
end
end
else
for m in mmodules do
modelbuilder.do_test_markdown(page, m)
end
end
page.add_raw_html hv.foot_content
page.add_raw_html ""
page.write_to(stdout)