# 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_markdown
import modelize_property
import markdown
redef class ModelBuilder
fun test_markdown(page: HTMLTag, mmodule: MModule)
do
page.add_raw_html ""
page.add_raw_html "
module {mmodule}
"
if mmodule2nmodule.has_key(mmodule) then
var nmodule = mmodule2nmodule[mmodule]
do
var nmoduledecl = nmodule.n_moduledecl
if nmoduledecl == null then break label x
var ndoc = nmoduledecl.n_doc
if ndoc == null then break label x
page.add ndoc.full_markdown
end label x
for nclassdef in nmodule.n_classdefs do
var mclassdef = nclassdef.mclassdef.as(not null)
if nclassdef isa AStdClassdef then
var ndoc = nclassdef.n_doc
if ndoc != null then
if mclassdef.mclass.intro == mclassdef then page.add_raw_html ""
page.add_raw_html "class {mclassdef}
"
page.add ndoc.full_markdown
end
end
for npropdef in nclassdef.n_propdefs do
var mpropdef = npropdef.mpropdef.as(not null)
var ndoc = npropdef.n_doc
if ndoc != null then
if mpropdef.mproperty.intro == mpropdef then page.add_raw_html ""
page.add_raw_html "prop {mpropdef}
"
page.add ndoc.full_markdown
end
end
end
end
end
end
var toolcontext = new ToolContext
var opt_full = new OptionBool("Process also imported modules", "--full")
toolcontext.option_context.add_option(opt_full)
toolcontext.process_options
var args = toolcontext.option_context.rest
if args.is_empty then
print "usage: test_markdown [options] file.nit..."
toolcontext.option_context.usage
return
end
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 """
"""
if opt_full.value then
for m in model.mmodules do
modelbuilder.test_markdown(page, m)
end
else
for m in mmodules do
modelbuilder.test_markdown(page, m)
end
end
page.add_raw_html ""
print page.html