Commit 9f66b109 authored by MARTINEZ Thierry 's avatar MARTINEZ Thierry

Examples in doc

parent 68c87a50
......@@ -38,6 +38,7 @@ initialize :-
set_prolog_flag(allow_variable_name_as_functor, true),
prolog_history(enable),
set_counter(item_id, 0),
set_plot_driver(gnu_plot),
new_model.
......
......@@ -4,6 +4,8 @@
doc/1,
devdoc/1,
grammar/1,
biocham/1,
biocham_silent/1,
generate_doc/0
]
).
......@@ -27,7 +29,15 @@ grammar(_) :-
doc('Declares a grammar predicate to be written in the documentation.').
biocham(_).
biocham_silent(_).
generate_doc :-
set_plot_driver(plot_png),
set_counter(plot_png, 0),
generate_doc(doc),
generate_doc(devdoc).
......@@ -38,12 +48,14 @@ generate_doc(Type) :-
error(existence_error(directory, _), _),
true
),
format(atom(IndexFilename), '~a/index.html', [Type]),
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) :-
......@@ -222,7 +234,7 @@ filter_id([_ | Tail], Id) :-
read_toc(Type) :-
setup_call_cleanup(
open('toc.org', read, Stream),
open('../toc.org', read, Stream),
read_toc(Stream, Type),
close(Stream)
).
......@@ -315,8 +327,9 @@ generate_body_item(section(Level, Title), Doc, _Type) :-
generate_body_item(file(File), Doc, Type) :-
atom_concat('../', File, ParentFile),
setup_call_cleanup(
open(File, read, Stream),
open(ParentFile, read, Stream),
generate_body_item_stream(Stream, Doc, Type),
close(Stream)
).
......@@ -487,11 +500,14 @@ generate_body_item_clause(Clause, Stream, Type) :-
format(Stream, '<h5 id="~a""><code>~a', [Id, Command]),
write_arguments(Arguments, Stream),
write(Stream, '.</code></h5>\n'),
write(Stream, '<div>'),
\+ (
member(DocItem, Doc),
write_doc_item(DocItem, Stream, Type),
fail
)
\+ (
write_doc_item(DocItem, Stream, Type)
)
),
write(Stream, '</div>')
;
true
).
......@@ -650,8 +666,32 @@ write_doc_item(doc(DocBody), Stream, _Type) :-
write_doc(Stream, DocBody).
write_doc_item(devdoc(DocBody), Stream, devdoc) :-
write_doc(Stream, DocBody).
write_doc_item(devdoc(DocBody), Stream, Type) :-
(
Type = devdoc
->
write_doc(Stream, DocBody)
;
true
).
write_doc_item(biocham_silent(Command), _Stream, _Type) :-
command(Command).
write_doc_item(biocham(Command), Stream, _Type) :-
with_output_to(
atom(Output),
command(Command)
),
prompt(Prompt),
format(
Stream,
'</div>
<div><code>~a</code><kbd>~w.</kbd></div>
<pre>~a</pre>
<div>',
[Prompt, Command, Output]
).
write_doc(Doc, DocBody) :-
......@@ -812,6 +852,12 @@ write_command(end, enumerate, Doc) :-
close_opened_li(Doc),
write(Doc, '</ol>').
write_command(example, Argument, Doc) :-
!,
write(Doc, '</div><div><strong>Example.</strong> '),
atom_chars(Argument, ArgumentChars),
write_doc_chars(ArgumentChars, Doc).
write_command(Command, _Argument, _Doc) :-
throw(error(unknown_command(Command))).
......
......@@ -296,5 +296,6 @@ compile_c_program(ExecutableFilename) :-
call_subprocess(ExecutableFilename, Arguments) :-
process_create(ExecutableFilename, Arguments, [process(Pid)]),
absolute_file_name(ExecutableFilename, Absolute),
process_create(Absolute, Arguments, [process(Pid)]),
process_wait(Pid, exit(0)).
......@@ -10,6 +10,13 @@
numerical_simulation :-
biocham_command,
doc('performs a numerical simulation up to 20s.'),
biocham_silent(clear_model),
biocham(a => b),
biocham(present(a)),
biocham(list_reactions),
biocham(list_ODE),
biocham(numerical_simulation),
biocham(plot),
numerical_simulation(20).
......
......@@ -2,6 +2,9 @@
plot,
[
plot/0,
set_plot_driver/1,
gnu_plot/0,
plot_png/0,
export_plot/1,
export_plot_to_png/1
]
......@@ -10,10 +13,31 @@
plot :-
biocham_command,
doc('plots the current trace.'),
doc('\\example'),
get_plot_driver(Driver),
Driver.
get_plot_driver(Driver) :-
nb_getval(plot_driver, Driver).
set_plot_driver(Driver) :-
nb_setval(plot_driver, Driver).
gnu_plot :-
export_plot(plot),
execute_plot(['-persist', 'plot.plot']).
plot_png :-
count(plot_png, Index),
format(atom(Filename), 'plot~d.png', [Index]),
export_plot_to_png(Filename),
format('<img src="~a">', [Filename]).
execute_plot(Options) :-
process_create(path(gnuplot), Options, []).
......
......@@ -4,7 +4,8 @@
execute_command/1,
toplevel/0,
quit/0,
command/1
command/1,
prompt/1
]).
......
......@@ -46,6 +46,10 @@ collect_info(DocItem, _Arguments, _ArgumentTypes, _BiochamCommand, Doc) :-
DocItem = doc(_)
;
DocItem = devdoc(_)
;
DocItem = biocham(_)
;
DocItem = biocham_silent(_)
),
!,
Doc = [DocItem].
......@@ -126,6 +130,8 @@ check_type(Grammar, Item, NewItem) :-
clause(NewHead, NewBody),
copy_term((NewHead, NewBody), (Head, Body)),
check_grammar_body(Body, NewBody)
->
true
;
throw(error(expected(Grammar)))
).
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment