Daniel@0
|
1 /* Part of DML (Digital Music Laboratory)
|
Daniel@0
|
2 Copyright 2014-2015 Samer Abdallah, University of London
|
Daniel@0
|
3
|
Daniel@0
|
4 This program is free software; you can redistribute it and/or
|
Daniel@0
|
5 modify it under the terms of the GNU General Public License
|
Daniel@0
|
6 as published by the Free Software Foundation; either version 2
|
Daniel@0
|
7 of the License, or (at your option) any later version.
|
Daniel@0
|
8
|
Daniel@0
|
9 This program is distributed in the hope that it will be useful,
|
Daniel@0
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Daniel@0
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Daniel@0
|
12 GNU General Public License for more details.
|
Daniel@0
|
13
|
Daniel@0
|
14 You should have received a copy of the GNU General Public
|
Daniel@0
|
15 License along with this library; if not, write to the Free Software
|
Daniel@0
|
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
Daniel@0
|
17 */
|
Daniel@0
|
18
|
Daniel@0
|
19 :- module(htmlutils,
|
Daniel@0
|
20 [ link//2
|
Daniel@0
|
21 , style//1
|
Daniel@0
|
22 , script//1
|
Daniel@0
|
23 , use_font//2
|
Daniel@0
|
24 , use_font//3
|
Daniel@0
|
25 , paginator//3
|
Daniel@0
|
26 , element//2
|
Daniel@0
|
27 ]).
|
Daniel@0
|
28
|
Daniel@0
|
29 :- use_module(library(http/html_write)).
|
Daniel@0
|
30 :- use_module(library(http/html_head)).
|
Daniel@0
|
31 :- use_module(library(http/http_path)).
|
Daniel@0
|
32 :- use_module(library(http/http_dispatch)).
|
Daniel@0
|
33 :- use_module(library(http/http_server_files)).
|
Daniel@0
|
34
|
Daniel@0
|
35 :- multifile user:body//1, user:body//2.
|
Daniel@0
|
36 :- multifile user:head//1, user:head//2.
|
Daniel@0
|
37 % :- multifile user:style/2.
|
Daniel@0
|
38
|
Daniel@0
|
39 :- set_prolog_flag(double_quotes,string).
|
Daniel@0
|
40
|
Daniel@0
|
41 % :- setting(appname, string, "anApp", "Application name").
|
Daniel@0
|
42
|
Daniel@0
|
43 :- meta_predicate element(+,:,?,?).
|
Daniel@0
|
44 element(Element,Content) --> { Item=..[Element, Content] }, html(Item).
|
Daniel@0
|
45
|
Daniel@0
|
46 link(Id,Text) --> html(a(href(location_by_id(Id)),Text)).
|
Daniel@0
|
47 style(Loc) --> {http_absolute_location(Loc,Ref,[])}, html(link([rel(stylesheet), href(Ref)],[])).
|
Daniel@0
|
48 script(Loc) --> {http_absolute_location(Loc,Ref,[])}, html(script(src(Ref),[])).
|
Daniel@0
|
49
|
Daniel@0
|
50 http:location(googlefonts,"//fonts.googleapis.com",[]).
|
Daniel@0
|
51
|
Daniel@0
|
52 user:term_expansion((:- googlefont(Name,Family)), Decls) :-
|
Daniel@0
|
53 Decls = [ (:- html_resource(Name,[virtual(true),requires(googlefonts(Query))]))
|
Daniel@0
|
54 , (:- html_resource(googlefonts(Query),[mime_type(text/css)]))
|
Daniel@0
|
55 ],
|
Daniel@0
|
56 string_concat("css?family=",Family,Query).
|
Daniel@0
|
57
|
Daniel@0
|
58
|
Daniel@0
|
59 use_font(Family,Resource) -->
|
Daniel@0
|
60 html_requires(Resource),
|
Daniel@0
|
61 html_post(head, style(type="text/css","html,body,h1,h2,h3,h4,h5,h6,select,input,.btn {font-family: '~s';}"-[Family])).
|
Daniel@0
|
62
|
Daniel@0
|
63 use_font(Elements,Family,Resource) -->
|
Daniel@0
|
64 html_requires(Resource),
|
Daniel@0
|
65 html_post(head, style(type="text/css","~w {font-family: '~s';}"-[Elements,Family])).
|
Daniel@0
|
66
|
Daniel@0
|
67 paginator(_,_,1) --> [].
|
Daniel@0
|
68 paginator(Handler,Page,Pages) -->
|
Daniel@0
|
69 html(div(class('text-centered'),
|
Daniel@0
|
70 ul(class(pagination),
|
Daniel@0
|
71 [ li(\prev(Page,Pages,Handler))
|
Daniel@0
|
72 , li(\page_link(Handler,1,1))
|
Daniel@0
|
73 , li(span("~d of ~d"-[Page,Pages]))
|
Daniel@0
|
74 , li(\page_link(Handler,Pages,Pages))
|
Daniel@0
|
75 , li(\next(Page,Pages,Handler))
|
Daniel@0
|
76 ]))).
|
Daniel@0
|
77
|
Daniel@0
|
78 prev(1,_,_) --> !,html(span(class(inactive),&(larr))).
|
Daniel@0
|
79 prev(N,_,Handler) --> { succ(M,N) }, page_link(Handler,M,&(larr)).
|
Daniel@0
|
80
|
Daniel@0
|
81 next(N,N,_) --> !,html(span(class(inactive),&(rarr))).
|
Daniel@0
|
82 next(N,_,Handler) --> { succ(N,M) }, page_link(Handler,M,&(rarr)).
|
Daniel@0
|
83
|
Daniel@0
|
84 page_link(ID-Params,N,Content) -->
|
Daniel@0
|
85 { http_link_to_id(ID,[page(N)|Params],Link) },
|
Daniel@0
|
86 html(a(href(Link),Content)).
|
Daniel@0
|
87
|
Daniel@0
|
88
|