View source with formatted comments or as raw
    1/*  Part of ClioPatria SeRQL and SPARQL server
    2
    3    Author:        Jan Wielemaker
    4    E-mail:        J.Wielemaker@vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (c)  2010-2018, University of Amsterdam,
    7                              VU University 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
   36:- module(cp_skin,
   37          [ server_address//1,          % +Component
   38            current_page_doc_link//0
   39          ]).   40:- use_module(library(http/html_write)).   41:- use_module(library(http/html_head)).   42:- use_module(library(http/http_wrapper)).   43:- use_module(library(http/http_dispatch)).   44:- use_module(library(http/http_path)).   45:- use_module(library(version)).   46:- use_module(components(menu)).   47:- use_module(components(simple_search)).   48:- use_module(applications(help/version)).   49
   50/** <module> ClioPatria skin
   51
   52This page defines the overall layout of  ClioPatria pages. All pages are
   53returned using reply_html_page/3, using the   page class cliopatria(Id),
   54where Id is currently  always  =default=.   Pages  can  be  redefined by
   55providing a rule for user:body//2, where   the first argument must unify
   56with the page class.
   57
   58The default skin provides the overall menu,   a  simple search form, the
   59content and the `server-address'. Because the   search-form uses the YUI
   60autocomplete widgets, the body must include class =|yui-skin-sam|=.  The
   61default body has the classes =|yui-skin-sam|= and =cliopatria=.
   62
   63The default skin provided by this can be overruled using two hooks:
   64
   65        $ cliopatria:page_body//1 :
   66        Emit a page from the given content.  This hook can be used to modify
   67        the overall page layout beyond what can be achieved with CSS.
   68        $ cliopatria:server_address//0 :
   69        Write the address of the server.
   70
   71This   library   also   provides   building     blocks,    notably   for
   72server_address//0:
   73
   74        $ server_address//1 :
   75        Presents the version info and a link to a GIT module.
   76        $ current_page_doc_link//0 :
   77        Presents a link to the documentation of a page if the
   78        self-documentation facilities are loaded.  See run.pl.in.
   79
   80The CSS file css('cliopatria.css') contains the ClioPatria style that is
   81makes ClioPatria look pretty to our  eyes,   but  is  not essential. The
   82plugin config-available/fix_menu.pl contains example code  to extend the
   83ClioPatria skin.
   84*/
   85
   86:- http_handler('/favicon.ico',
   87                http_reply_file(icons('favicon.ico'), []),
   88                []).   89
   90:- html_resource(js('cliopatria.js'),
   91                 [ requires([jquery])
   92                 ]).   93:- html_resource(plain,
   94                 [ virtual(true),
   95                   requires([ css('plain.css')
   96                            ])
   97                 ]).   98:- html_resource(cliopatria,
   99                 [ virtual(true),
  100                   requires([ css('cliopatria.css'),
  101                              js('cliopatria.js')
  102                            ])
  103                 ]).  104
  105%!  user:body(+Style, :Body)// is det.
  106%
  107%   The multi-file implementation defines the overall layout of HTML
  108%   pages with the Style cliopatria(_).
  109
  110:- multifile
  111    user:body//2.  112
  113user:body(cliopatria(Style), Body) -->
  114    cliopatria:page_body(cliopatria(Style), Body),
  115    !.
  116user:body(cliopatria(_), Body) -->
  117    cliopatria:page_body(Body),
  118    !.
  119user:body(cliopatria(plain), Body) -->
  120    html_requires(plain),
  121    html(body(class(['yui-skin-sam', cliopatria]),
  122              [ div([id('cp-menu'), class(menu)], \cp_logo_and_menu),
  123                \simple_search_form([value(p(q))]),
  124                br(clear(all)),
  125                div([id('cp-content'), class(content)], Body),
  126                br(clear(all)),
  127                div([id('cp-footer'), class(footer)], \address)
  128              ])).
  129user:body(cliopatria(_), Body) -->
  130    html_requires(cliopatria),
  131    html(body(class(['yui-skin-sam', cliopatria]),
  132              [ div([id('cp-menu'), class(menu)], \cp_logo_and_menu),
  133                \simple_search_form([value(p(q))]),
  134                br(clear(all)),
  135                div([id('cp-content'), class(content)], Body),
  136                br(clear(all)),
  137                div([id('cp-footer'), class(footer)], \address)
  138              ])).
  139
  140cp_logo_and_menu -->
  141    cp_logo,
  142    cp_menu.
  143
  144cp_logo -->
  145    cliopatria:logo,
  146    !.
  147cp_logo -->
  148    { File = 'cliopatria-logo.png',
  149      absolute_file_name(icons(File), _Logo,
  150                         [access(read), file_errors(fail)]),
  151      http_absolute_location(icons(File), Src, []),
  152      http_link_to_id(home, [], Home)
  153    },
  154    html(a([class(logo), href(Home), style('float:left')
  155           ],
  156           img([src(Src)]))).
  157
  158%!  address//
  159%
  160%   Emit an element =address= with   class  =cliopatria=. This first
  161%   class  the  hook  cliopatria:server_address//0.  If  this  hooks
  162%   fails, it calls server_address('ClioPatria').
  163%
  164%   @see version.pl
  165
  166address -->
  167    cliopatria:server_address,
  168    !.
  169address -->
  170    server_address('ClioPatria').
  171
  172
  173%!  server_address(+Component)//
  174%
  175%   HTML component that emits the   default ClioPatria address link.
  176%   This provides a link to the ClioPatria   home page and the (GIT)
  177%   version information. ClioPatria  is  registered   with  the  GIT
  178%   module =|ClioPatria|= and the default server address is provided
  179%   by calling:
  180%
  181%       ==
  182%           ...,
  183%           server_address('ClioPatria'),
  184%           ...
  185%       ==
  186%
  187%   @see register_git_module/2 for registering a GIT module.
  188
  189server_address(Component) -->
  190    html([ address(class(footer),
  191                   [ \component_address(Component),
  192                     \current_page_doc_link
  193                   ])
  194         ]).
  195
  196%!  component_address(+Name)//
  197%
  198%   The label ClioPatria as a link to its home-page on the web.
  199
  200component_address(Component) -->
  201    (   { git_module_property(Component, home_url(Home)) }
  202    ->  html(a([ class(home), href(Home),
  203                 title(Component+' home')
  204               ], Component))
  205    ;   html(span(class(home), Component))
  206    ),
  207    html(' (version '),
  208    component_version(Component),
  209    html(')').
  210
  211
  212%!  component_version(+Name)//
  213%
  214%   Give verion information and link to detailed version info
  215
  216component_version(Component) -->
  217    { (   git_module_property(Component, version(Version))
  218      ->  true
  219      ;   Version = 'no GIT?'
  220      ),
  221      http_link_to_id(version_info, [], VREF)
  222    },
  223    html(a([title('About versions'),
  224            class(version),
  225            href(VREF)],
  226           Version)).
  227
  228
  229
  230%!  current_page_doc_link//
  231%
  232%   Create a link to  the  documentation   (and  from  there  to the
  233%   implementation) of this page. This link   is created only if the
  234%   library applications(help/http_help) is loaded.
  235
  236:- if(current_predicate(http_help:page_documentation_link//1)).  237current_page_doc_link -->
  238    { http_current_request(Request) },
  239    http_help:page_documentation_link(Request).
  240:- else.  241current_page_doc_link --> [].
  242:- endif.