34
35:- module(pldoc_pack,
36 [ doc_pack/1 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).
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]).
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 ]).
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 ])).
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), 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. 160
161
162
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(_))
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. */