View source with raw comments or as raw
    1/*  Part of SWI-Prolog
    2
    3    Author:        Jan Wielemaker
    4    E-mail:        J.Wielemaker@vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (c)  2012, VU University Amsterdam
    7    All rights reserved.
    8
    9    Redistribution and use in source and binary forms, with or without
   10    modification, are permitted provided that the following conditions
   11    are met:
   12
   13    1. Redistributions of source code must retain the above copyright
   14       notice, this list of conditions and the following disclaimer.
   15
   16    2. Redistributions in binary form must reproduce the above copyright
   17       notice, this list of conditions and the following disclaimer in
   18       the documentation and/or other materials provided with the
   19       distribution.
   20
   21    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   22    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   23    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   24    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   25    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   26    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   27    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   28    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   29    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   30    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   31    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   32    POSSIBILITY OF SUCH DAMAGE.
   33*/
   34
   35:- module(pldoc_pack,
   36	  [ doc_pack/1                  % +Pack
   37	  ]).   38:- if(exists_source(library(http/http_dispatch))).   39:- use_module(library(http/http_dispatch)).   40:- endif.   41:- use_module(library(prolog_pack)).   42:- use_module(library(http/html_write)).   43:- use_module(library(http/html_head)).   44:- use_module(doc_html).   45:- use_module(doc_index).

PlDoc for Prolog extension packs

This module profiles PlDoc support specific to Prolog extension packs. It extends the PlDoc web-browser with the ability to lists the installed packs and provide an overview of a pack, whether loaded or not. The predicate doc_pack/1 can be used to generate stand-alone HTML documentation for a pack. */

   56:- if(current_predicate(http_handler/3)).   57:- http_handler(pldoc(pack),     http_redirect(moved, pldoc('pack/')), []).   58:- http_handler(pldoc('pack/'),  pldoc_pack, [prefix]).
 pldoc_pack(+Request)
HTTP handler that handles /pack/ in the PlDoc server. Without an additional path, it lists the installed packs. With an additional package name, it lists the content of a pack and finally, /pack/<pack>/<file> can be used to get documentation or the source of a pack file.
   68pldoc_pack(Request) :-
   69    memberchk(path_info(PackPath), Request),
   70    PackPath \== '',
   71    !,
   72    (   pack_path(Pack, PackFile, PackPath)
   73    ->  list_pack(Pack, PackFile, Request)
   74    ;   http_404([], Request)
   75    ).
   76pldoc_pack(_Request) :-
   77    reply_html_page(
   78	pldoc(packs),
   79	title('Installed extension packs'),
   80	\pack_page([])).
   81
   82pack_path(Pack, PackFile, PackPath) :-
   83    sub_atom(PackPath, B, _, A, /),
   84    !,
   85    sub_atom(PackPath, 0, B, _, Pack),
   86    sub_atom(PackPath, _, A, 0, PackFile).
   87
   88pack_page(Options) -->
   89    html_requires(pldoc),
   90    object_page_header(-, Options),
   91    html([ h1('Installed extension packs'),
   92	   p([ 'The following extension packages are installed in ',
   93	       'the this Prolog system.  Other packages can be found at ',
   94	       a(href('http://www.swi-prolog.org/pack/list'),
   95		 'the SWI-Prolog website')
   96	     ]),
   97	   \pack_table(Options)
   98	 ]).
 pack_table(+Options)// is det
Generate a table with installed packages
  105pack_table(_Options) -->
  106    { findall(Pack, pack_property(Pack, directory(_)), Packs0),
  107      sort(Packs0, Packs)
  108    },
  109    html(table(class(packs),
  110	       [ tr([th('Pack'), th('Version'), th('Title')])
  111	       | \packs(Packs)
  112	       ])).
  113
  114packs([]) --> [].
  115packs([H|T]) --> pack(H), packs(T).
  116
  117pack(Pack) -->
  118    { uri_encoded(path, Pack, HREF),
  119      pack_property(Pack, version(Version)),
  120      (   pack_property(Pack, title(Title))
  121      ->  true
  122      ;   Title = '<no title>'
  123      )
  124    },
  125    html(tr([ td(class(pack_name),    a(href(HREF+'/'), Pack)),
  126	      td(class(pack_version), Version),
  127	      td(class(pack_title),   Title)
  128	    ])).
 list_pack(+Pack, +PackFile, +Request)
List a directory or file in a pack
  135list_pack(Pack, '', _) :-
  136    !,
  137    reply_html_page(
  138	pldoc(pack),
  139	title('Documentation for pack ~w'-[Pack]),
  140	\pack_doc(Pack)).
  141list_pack(Pack, File, Request) :-
  142    pack_property(Pack, directory(PackDir)),
  143    directory_file_path(PackDir, File, Path0),
  144    absolute_file_name(Path0, Path),        % Canonical
  145    sub_atom(Path, 0, _, _, PackDir),
  146    pldoc_http:doc_reply_file(Path, Request).
  147
  148pack_doc(Pack) -->
  149    { pack_property(Pack, directory(PackDir)),
  150      pack_title(Pack, Title),
  151      findall(O, pack_option(Pack, O), Options)
  152    },
  153    dir_index(PackDir,
  154	      [ if(true),
  155		recursive(true),
  156		title(Title)
  157	      | Options
  158	      ]).
  159:- endif.			% server facilities
  160
  161
  162		 /*******************************
  163		 *        STAND ALONE DOCS      *
  164		 *******************************/
 doc_pack(+Pack)
Generate stand-alone documentation for the package Pack. The documentation is generated in a directory doc inside the pack. The index page consists of the content of readme or readme.txt in the main directory of the pack and an index of all files and their public predicates.
  174doc_pack(Pack) :-
  175    pack_property(Pack, directory(PackDir)),
  176    pack_title(Pack, PackTitle),
  177    findall(O, pack_option(Pack, O), Options),
  178    directory_file_path(PackDir, prolog, SourceDir),
  179    directory_file_path(PackDir, doc, DocDir),
  180    doc_save(SourceDir,
  181	     [ title(PackTitle),
  182	       doc_root(DocDir),
  183	       if(true),
  184	       recursive(true)
  185	     | Options
  186	     ]).
  187
  188pack_title(Pack, PackTitle) :-
  189    pack_property(Pack, title(Title)),
  190    !,
  191    format(atom(PackTitle), 'Pack ~w -- ~w', [Pack, Title]).
  192pack_title(Pack, PackTitle) :-
  193    format(atom(PackTitle), 'Pack ~w', [Pack]).
  194
  195pack_option(Pack, Option) :-
  196    pack_option(Option),
  197    pack_property(Pack, Option).
  198
  199pack_option(readme(_)).
  200pack_option(todo(_))