1:- module(simple_bootstrap,
    2    [
    3    ]
    4).    5
    6% Assert app dir so it can be run from anywhere
    7:- prolog_load_context(directory, Dir),
    8   asserta(user:file_search_path(bs_app, Dir)),
    9   asserta(user:file_search_path(bs_templates, bs_app(templates))),
   10   asserta(user:file_search_path(bs_static, bs_app(static))).   11
   12:- use_module(library(sw/simple_web)).   13
   14% Allow optional blocks
   15:- asserta(sw_config_handling:config(st_undefined, false)).   16
   17% Override render_reply for bootstrap base
   18:- asserta((sw_template_handling:render_reply(bootstrap_base, Data, Opts) :- bootstrap_reply(Data, Opts))).   19
   20
   21:- use_module(library(st/st_expr)).   22:- use_module(library(st/st_render)).   23
   24% Register template function
   25:- st_set_function(sw_templates, 1, sw_templates).   26:- st_set_function(bootstrap, 1, bootstrap).   27
   28% Expand dynamic_included paths to user app templates
   29sw_templates(File, Path) :-
   30    absolute_file_name(sweb_templates(File), Path, []).
   31
   32% Expand dynamic_include path to bootstrap templates
   33bootstrap(File, Path) :-
   34    absolute_file_name(bs_templates(File), Path, []).
 bootstrap_reply(Data, Opts) is semidet
Render the file with the local bootstrap base and user templates
   39bootstrap_reply(Data, Opts) :-
   40    current_output(Out),
   41    format("Content-type: text/html~n~n"),
   42    st_render_file(bs_templates(bootstrap_base), Data, Out, Opts).
   43
   44% Setup static handling
   45:- use_module(library(http/http_dispatch)).   46:- use_module(library(http/http_files)).   47
   48http:location(bootstrap_static, "/bootstrap", []).
   49
   50:- http_handler(bootstrap_static(.),
   51                http_reply_from_files(bs_static(.), []),
   52                [prefix]).