:- module( doc, [ doc/1, devdoc/1, grammar/1, biocham/1, biocham_silent/1, generate_doc/0 ] ). doc(_) :- !, true. doc(_) :- doc(' Writes in the documentation (both the Reference Manual and the Developer Manual). '). devdoc(_) :- doc('Writes in the Developer Manual.'). grammar(_) :- doc('Declares a grammar predicate to be written in the documentation.'). biocham(_). biocham_silent(_). generate_doc :- set_plot_driver(gnu_plot_png), set_image_viewer_driver(img_tag), set_draw_graph_driver(graph_svg), generate_doc(doc), generate_doc(devdoc). generate_doc(Type) :- catch( make_directory(Type), error(existence_error(directory, _), _), true ), set_counter(plot_png, 0), set_counter(graph_svg, 0), working_directory(OldDir, Type), format(atom(IndexFilename), 'index.html', [Type]), setup_call_cleanup( open(IndexFilename, write, Stream), generate_doc(Stream, Type), close(Stream) ), working_directory(_OldDir, OldDir). generate_doc(Doc, Type) :- version(Version), doc_title(Type, DocTitle), format(atom(Title), 'Biocham ~a ~a', [Version, DocTitle]), format(Doc, '\c ~a

~a

', [Title, Title]), generate_toc(Doc, Type), generate_body(Doc, Type), write(Doc, ' '). doc_title(doc, 'Reference Manual'). doc_title(devdoc, 'Developer Manual'). :- dynamic(toc/1). generate_toc(Doc, Type) :- retractall(toc(_)), nb_setval(last_level, 0), read_toc(Type), write(Doc, '

Contents

\n'), nb_setval(current_counters, []), \+ ( toc(section(Level, Title)), \+ ( generate_toc_section(Doc, Level, Title) ) ), goto_toc_level(Doc, 0). generate_toc_section(Doc, Level, Title) :- goto_toc_level(Doc, Level), indent(Doc, Level), increment_counter, write(Doc, '
  • '), write_counters(Doc), make_id(Title, Id), format(Doc, ' ~a
  • \n', [Id, Title]). goto_toc_level(Doc, Level) :- nb_getval(current_counters, OldCounters), length(OldCounters, OldLevel), ( OldLevel > Level -> LevelDiff is OldLevel - Level, \+ ( between(1, LevelDiff, I), \+ ( CurrentLevel is OldLevel - I, indent(Doc, CurrentLevel), write(Doc, '\n') ) ) ; OldLevel = Level -> true ; OldLevel is Level - 1 -> indent(Doc, OldLevel), write(Doc, '