View source with raw comments or as raw
    1/*  Part of SWISH
    2
    3    Author:        Jan Wielemaker
    4    E-mail:        J.Wielemaker@vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (c)  2014-2018, VU University Amsterdam
    7			      CWI, Amsterdam
    8    All rights reserved.
    9
   10    Redistribution and use in source and binary forms, with or without
   11    modification, are permitted provided that the following conditions
   12    are met:
   13
   14    1. Redistributions of source code must retain the above copyright
   15       notice, this list of conditions and the following disclaimer.
   16
   17    2. Redistributions in binary form must reproduce the above copyright
   18       notice, this list of conditions and the following disclaimer in
   19       the documentation and/or other materials provided with the
   20       distribution.
   21
   22    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   23    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   24    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   25    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   26    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   27    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   28    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   29    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   30    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   31    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   32    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   33    POSSIBILITY OF SUCH DAMAGE.
   34
   35    Changes by:    Riccardo Zese
   36    E-mail:        riccardo.zese@unife.it
   37*/
   38
   39:- module(swish_app,
   40	  [
   41	  ]).   42:- use_module(library(pldoc), []).   43:- use_module(library(pengines)).   44:- use_module(library(http/http_dispatch)).   45:- use_module(library(option)).   46:- use_module(library(apply)).   47:- use_module(library(settings)).   48
   49:- use_module(lib/messages).   50:- use_module(lib/paths).   51:- use_module(lib/config, []).   52:- use_module(lib/page, []).   53:- use_module(lib/storage).   54:- use_module(lib/include).   55:- use_module(lib/swish_csv).   56:- use_module(lib/examples).   57:- use_module(lib/profiles).   58:- use_module(lib/highlight).   59:- use_module(lib/markdown).   60:- use_module(lib/chat, []).   61:- use_module(lib/template_hint, []).   62:- if(exists_source(library(http/http_dyn_workers))).   63:- use_module(library(http/http_dyn_workers)).   64:- else.   65:- use_module(lib/plugin/http_dyn_workers, []).   66:- endif.   67:- use_module(lib/web).   68:- use_module(lib/version).   69
   70
   71		 /*******************************
   72		 *	      VERSION		*
   73		 *******************************/
   74
   75setup_versions :-
   76	prolog_load_context(directory, Dir),
   77	register_git_module(swish,
   78			    [ directory(Dir),
   79			      home_url('https://github.com/friguzzi/trill-on-swish')
   80			    ]),
   81	pack_property(trill,directory(TrillDir)),
   82	register_git_module(trill,[directory(TrillDir),
   83	home_url('https://github.com/rzese/trill')]),
   84	check_prolog_version(070717).
   85
   86:- initialization setup_versions.   87
   88
   89		 /*******************************
   90		 *	       CORS		*
   91		 *******************************/
   92
   93% By default, enable CORS
   94
   95:- set_setting_default(http:cors, [*]).   96
   97
   98		 /*******************************
   99		 *         LOCAL CONFIG		*
  100		 *******************************/
  101
  102% create the application first, so we can modify it inside the
  103% configuration files.
  104:- pengine_application(swish).
 load_config
Load files from config-enabled if present. Currently loads from a single config-enabled directory, either found locally or from the swish directory.
  112load_config :-
  113	absolute_file_name(config_enabled(.), Path,
  114			   [ file_type(directory),
  115			     access(read),
  116			     file_errors(fail)
  117			   ]), !,
  118	atom_concat(Path, '/*.pl', Pattern),
  119	expand_file_name(Pattern, Files),
  120	maplist(user:ensure_loaded, Files).
  121load_config.
  122
  123:- initialization(load_config, now).  124
  125
  126		 /*******************************
  127		 *	      CONFIG		*
  128		 *******************************/
  129
  130:- multifile
  131	swish_config:config/2,
  132	swish_config:source_alias/2.
 swish_config:config(?Config, ?Value) is nondet
All solutions of this predicate are available in the JavaScript object config.swish.config. Config must be an atom that is also a valid JavaScript identifier. Value must be a value that is valid for json_write_dict/2. Defined config parameters:
show_beware
If true, show the Beware modal dialog on startup
tabled_results
If true, check the table results checkbox by default.
application
Name of the Pengine application.
csv_formats
CSV output formats offered. For example, ClioPatria defines this as [rdf,prolog]. The first element is default.
community_examples
Allow marking saved programs as example. If marked, the programs are added to the Examples menu.
public_access
If lib/authenticate.pl is loaded and this flag is true, all access to SWISH demands authentication. If false, only running queries and saving files is restricted. Note that this flag has no effect if no authentication module is loaded.
include_alias
Alias for searching files for `:- include(Alias(Name)).`
ping
Ping pengine status every N seconds. Updates sparkline chart with stack usage.
notebook
Dict holding options for notebooks:
eval_script
Whether or not to evaluate JavaScript in cells
fullscreen
Whether or not to start in fullscreen mode by default
fullscreen
Dict holding options for fullscreen mode:
  • hide_navbar: hide the navigation bar when in fullscreen mode.
chat
Activate the chat interface
chat_spam_protection
Perform protection against spamming on chat messages.
default_query
Initial query for the source search in an empty tab

These config options are commonly overruled using one of the configuration files. See config-available and config-enabled directories.

The defaults below are for small installations. See config-available/dim_large.pl for a default config for large communities.

  189% Allow other code to overrule the defaults from this file.
  190term_expansion(swish_config:config(Config, _Value), []) :-
  191	clause(swish_config:config(Config, _), _).
  192
  193swish_config:config(show_beware,        false).
  194swish_config:config(tabled_results,     false).
  195swish_config:config(application,        swish).
  196swish_config:config(csv_formats,        [prolog]).
  197swish_config:config(community_examples, true).
  198swish_config:config(public_access,      false).
  199swish_config:config(include_alias,	example).
  200swish_config:config(ping,		2).
  201swish_config:config(notebook,		_{ eval_script: true,
  202					   fullscreen: false
  203					 }).
  204swish_config:config(fullscreen,		_{ hide_navbar: true
  205					 }).
  206swish_config:config(chat,		true).
  207swish_config:config(chat_spam_protection, true).
  208swish_config:config(default_query,	'').
 swish_config:source_alias(Alias, Options) is nondet
Specify access for files below a given alias. Options define
access(Access)
One of read or both. Default is read.
if(Condition)
Provide additional conditions. Defined conditions are:
loaded
Only provide access to the file if it is loaded.
  222% setup HTTP session management
  223:- use_module(lib/session).  224
  225
  226                 /*******************************
  227                 *   CREATE SWISH APPLICATION   *
  228                 *******************************/
  229
  230:- multifile
  231	pengines:prepare_module/3.  232
  233:- use_module(swish:lib/render).  234:- use_module(swish:lib/trace).  235:- use_module(swish:lib/projection).  236:- use_module(swish:lib/attvar).  237:- use_module(swish:lib/jquery).  238:- use_module(swish:lib/dashboard).  239:- use_module(swish:lib/md_eval).  240:- use_module(swish:lib/html_output).  241:- use_module(swish:lib/swish_diagnostics).  242:- use_module(swish:lib/swish_debug).  243:- use_module(swish:library(pengines_io)).  244:- use_module(swish:library(solution_sequences)).  245:- use_module(swish:library(aggregate)).  246
  247pengines:prepare_module(Module, swish, _Options) :-
  248	pengines_io:pengine_bind_io_to_html(Module).
  249%:- set_setting(swish:time_limit, 3600).
  250% Additional sandboxing rules.
  251:- use_module(lib/flags).  252%:- use_module(lib/logging).
  253
  254% Libraries that are nice to have in SWISH, but cannot be loaded
  255% because they use directives that are considered unsafe.  We load
  256% them here, so they only need to be imported, which is just fine.
  257
  258:- use_module(library(clpfd), []).  259:- use_module(library(clpb), []).  260:- if(exists_source(library(dcg/high_order))).  261:- use_module(library(dcg/high_order), []).  262:- endif.  263:- use_module(lib/swish_chr, []).  264
  265% load rendering modules
  266
  267:- use_module(swish(lib/render/sudoku),	  []).  268:- use_module(swish(lib/render/chess),	  []).  269:- use_module(swish(lib/render/table),	  []).  270:- use_module(swish(lib/render/codes),	  []).  271:- use_module(swish(lib/render/svgtree),  []).  272:- use_module(swish(lib/render/graphviz), []).  273:- use_module(swish(lib/render/c3),	  []).  274:- use_module(swish(lib/render/url),	  []).  275:- use_module(swish(lib/render/bdd),	  []).  276:- use_module(swish(lib/render/mathjax),  []).  277
  278%:- use_module(library(trill)).
  279:- use_module(library(clpb)).  280
  281                 /*******************************
  282                 *         ADD COLOURING        *
  283                 *******************************/
  284
  285:- multifile prolog_colour:term_colours/2.  286
  287prolog_colour:term_colours((:- trill),
  288	neck(directive)-[trill_directive]):-!.
  289
  290prolog_colour:term_colours((:- trillp),
  291	neck(directive)-[trill_directive]):-!.
  292
  293prolog_colour:term_colours((:- tornado),
  294	neck(directive)-[trill_directive]):-!.
  295
  296prolog_colour:term_colours(owl_rdf(_), olwrdf_predicate-[classify]):-!.
  297
  298:- multifile prolog_colour:style/2.  299
  300prolog_colour:style(trill_directive,                  [colour(firebrick),bold(true)]).
  301prolog_colour:style(olwrdf_predicate,                  [colour(firebrick),bold(true)]).
  302
  303:- multifile swish_highlight:style/3.  304
  305swish_highlight:style(trill_directive,  trill_directive, [text, base(atom)]).
  306swish_highlight:style(olwrdf_predicate, olwrdf_predicate, [text, base(symbol)]).
  307
  308
  309:- use_module(swish(lib/render/gvterm),   []).