examples.pl -- Serve example files
Locate and serve files for the Examples menu as well as examples included from overview notebooks. The examples come from two sources:
- Prolog files in the file search path
examples
. Such files are distributed with SWISH. - Gitty files marked as
example
. Such files can be created by the users.
This module also makes the known examples available through swish_provides/1 for supporting conditional statements on example overview notebooks.
- list_examples(+Request)[private]
- Get a list of registered example code. Examples are described in
a file
swish_examples('index.json')
. - examples(JSON:list, +Options) is det[private]
- JSON is a list of JSON dicts containing the keys below. The list
is composed from all *.pl files in the search path
example
.- file:File
- href:URL
- title:String
- requires:Term
- group:String
- index_json(+BaseHREF, +Directory, -JSON)[private]
- Produce a JSON description for the examples in the directory
Dir. This deals with two scenarios: if a file
index.json
is provided, use this file and add the not-described files as examples that are not included in the menu. If noindex.json
is present, all files are added as example files. - add_examples_href(+HREF, +JSON0, -JSON) is det[private]
- Add a
href
key pointing at the example. Also removes all items that are not dicts or have nofile
key. - ex_file_json(+ExampleBase, +Path, -JSON) is det[private]
- Create a JSON representation for the given example file.
- md_eval:provides(?Term) is nondet[multifile]
- Make examples available through swish_provides/1. Can be used in
dynamic cells as, e.g.,:
:- if(swish_provides(example('chat80.pl',_,_))). ... :- endif.
- community_examples(-Dict) is det[private]
- Extract examples from the gitty store.