Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Moved path setup to lib/paths.pl
  • Loading branch information
Jan Wielemaker committed Feb 21, 2017
1 parent b951c77 commit 5014dbb
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 22 deletions.
97 changes: 97 additions & 0 deletions lib/paths.pl
@@ -0,0 +1,97 @@
/* Part of SWISH
Author: Jan Wielemaker
E-mail: J.Wielemaker@cs.vu.nl
WWW: http://www.swi-prolog.org
Copyright (C): 2017, VU University Amsterdam
CWI Amsterdam
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/

:- module(swish_paths, []).
:- use_module(library(http/http_path), []).

/** <module> Setup SWISH search paths
*/

:- initialization initialize_paths.

:- multifile
user:file_search_path/2,
http:location/3.

user:file_search_path(data, data).
user:file_search_path(swish_web, swish(web)).
user:file_search_path(js, swish_web(js)).
user:file_search_path(css, swish_web(css)).
user:file_search_path(icons, swish_web(icons)).

%! set_swish_path
%
% Setup the swish search path.

set_swish_path :-
absolute_file_name(swish('swish.pl'), _,
[file_errors(fail), access(read)]), !.
set_swish_path :-
prolog_load_context(directory, Dir),
asserta(user:file_search_path(swish, Dir)).

%! set_data_path
%
% Setup and possibly create a directory for storing dynamic data.

set_data_path :-
absolute_file_name(data(.), _,
[ file_type(directory),
access(write),
file_errors(fail)
]), !.
set_data_path :-
absolute_file_name(data(.), Dir,
[ solutions(all)
]),
\+ exists_directory(Dir),
catch(make_directory(Dir),
error(permission_error(create,directory,Dir), _),
fail), !,
print_message(informational, swish(created_data_dir(Dir))).
set_data_path :-
print_message(error, swish(no_data_dir)),
halt(1).

initialize_paths :-
set_swish_path,
set_data_path.

% HTTP paths

http:location(swish, root(.), [priority(-100)]).



24 changes: 2 additions & 22 deletions swish.pl
Expand Up @@ -37,10 +37,11 @@
]).
:- use_module(library(pengines)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_path)).
:- use_module(library(option)).
:- use_module(library(settings)).

:- use_module(lib/messages).
:- use_module(lib/paths).
:- use_module(lib/config, []).
:- use_module(lib/page, []).
:- use_module(lib/storage).
Expand All @@ -53,27 +54,6 @@
:- use_module(lib/template_hint, []).


/*******************************
* PATHS *
*******************************/

user:file_search_path(swish_web, swish(web)).
user:file_search_path(js, swish_web(js)).
user:file_search_path(css, swish_web(css)).
user:file_search_path(icons, swish_web(icons)).

set_swish_path :-
absolute_file_name(swish('swish.pl'), _,
[file_errors(fail), access(read)]), !.
set_swish_path :-
prolog_load_context(directory, Dir),
asserta(user:file_search_path(swish, Dir)).

:- set_swish_path.

http:location(swish, root(.), [priority(-100)]).


/*******************************
* CORS *
*******************************/
Expand Down

0 comments on commit 5014dbb

Please sign in to comment.