-
Notifications
You must be signed in to change notification settings - Fork 10
/
styling_handlers.pl
101 lines (79 loc) · 2.45 KB
/
styling_handlers.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
:- module(styling_handlers, []).
/** <module> Demos of styling hooks, mailman, and resources
*/
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/html_write)).
%
% How can we include fixed elements in our pages?
% So far we've used reply_html_page/2, but we can pass
% an optional 'styling argument'
% we define a new clause for the multifile hook predicate
% user:body with our constant items
%
user:body(strangeloop_style, Body) -->
html(body([ div(id(top), h1('The Simple Web Page Site')),
div(id(content), Body)
])).
% we could define user:head if we wanted as well
%
:- http_handler(root(styled), styled , [id(styled)]).
styled(_Request) :-
reply_html_page(
strangeloop_style, % define the style of the page
[title('Howdy')],
p('this page has style')).
/*
So, you know that awkward moment when you realize you could
generate a second chunk of html at this moment, along with whatever
we're making, but nooo... we're not at that point.
Or those awkward 'stick this in the head, this at the bottom, this
right below the element, blah blah' complicatedjavascript driven
widgets that are always a nuisance?
Mailman to the rescue
*/
:- http_handler(root(mailman), mailman_demo, [id(mailman)]).
%% mailman_demo(+Request:request) is det
%
% demonstration of the mailman facility
mailman_demo(Request) :-
reply_html_page(
title('Howdy'),
[\page_content(Request)]).
page_content(_Request) -->
html(
[
h1('Demonstrating Mailman'),
%
% we generate both sets of buttons here
% and send them to...
div(\nav_bar),
p('The body goes here'),
%
% down here...
div(\html_receive(bottom_nav))
]).
nav_bar -->
{
% pretend this is painful
findall(Name, nav(Name, _), ButtonNames),
% and this is a handy place to make all the buttons
maplist(as_top_nav, ButtonNames, TopButtons),
maplist(as_bottom_nav, ButtonNames, BottomButtons)
},
html([\html_post(bottom_nav, BottomButtons) , TopButtons]).
nav('Home', '/home').
nav('About', '/about').
nav('Recipes', '/recipes').
as_top_nav(Name, a([href=HREF, class=topnav], Name)) :-
nav(Name, HREF).
as_bottom_nav(Name, a([href=HREF, class=bottomnav], Name)) :-
nav(Name, HREF).
% very useful - the default page generation includes an
% html_receive(head) in the head
%% TBD
% resources
% parameters
% sessions
% json
% backend
%