View source with raw 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)).

ClioPatria skin

This page defines the overall layout of ClioPatria pages. All pages are returned using reply_html_page/3, using the page class cliopatria(Id), where Id is currently always default. Pages can be redefined by providing a rule for user:body//2, where the first argument must unify with the page class.

The default skin provides the overall menu, a simple search form, the content and the `server-address'. Because the search-form uses the YUI autocomplete widgets, the body must include class yui-skin-sam. The default body has the classes yui-skin-sam and cliopatria.

The default skin provided by this can be overruled using two hooks:

cliopatria:page_body//1
Emit a page from the given content. This hook can be used to modify the overall page layout beyond what can be achieved with CSS.
cliopatria:server_address//0
Write the address of the server.

This library also provides building blocks, notably for server_address//0:

server_address//1
Presents the version info and a link to a GIT module.
current_page_doc_link//0
Presents a link to the documentation of a page if the self-documentation facilities are loaded. See run.pl.in.

The CSS file css('cliopatria.css') contains the ClioPatria style that is makes ClioPatria look pretty to our eyes, but is not essential. The plugin config-available/fix_menu.pl contains example code to extend the ClioPatria skin. */

   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                 ]).
 user:body(+Style, :Body)// is det
The multi-file implementation defines the overall layout of HTML pages with the Style cliopatria(_).
  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)]))).
 address//
Emit an element address with class cliopatria. This first class the hook cliopatria:server_address//0. If this hooks fails, it calls server_address('ClioPatria').
See also
- version.pl
  166address -->
  167    cliopatria:server_address,
  168    !.
  169address -->
  170    server_address('ClioPatria').
 server_address(+Component)//
HTML component that emits the default ClioPatria address link. This provides a link to the ClioPatria home page and the (GIT) version information. ClioPatria is registered with the GIT module ClioPatria and the default server address is provided by calling:
    ...,
    server_address('ClioPatria'),
    ...
See also
- register_git_module/2 for registering a GIT module.
  189server_address(Component) -->
  190    html([ address(class(footer),
  191                   [ \component_address(Component),
  192                     \current_page_doc_link
  193                   ])
  194         ]).
 component_address(+Name)//
The label ClioPatria as a link to its home-page on the web.
  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(')').
 component_version(+Name)//
Give verion information and link to detailed version info
  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)).
 current_page_doc_link//
Create a link to the documentation (and from there to the implementation) of this page. This link is created only if the library applications(help/http_help) is loaded.
  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.