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