/
a16x88.krl
137 lines (116 loc) · 3.62 KB
/
a16x88.krl
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
ruleset a16x88 {
meta {
name "KBlog"
description <<
Ruleset for creating the main pages for KBlog, a demo blog app written in KRL
>>
author "Phil Windley"
logging on
//use css resource "http://www.windley.com/kblog/kblog.css"
//use javascript resource "http://www.windley.com/kblog/jquery.hashchange-1.js"
//use module a16x89 alias blogdata
use module a16x93 alias blogconfig
}
dispatch {
domain "windley.com"
}
global {
}
rule init_html {
select when pageview ".*" setting ()
{
replace_inner("#about", blogconfig:about_text);
blogconfig:place_button("Home");
blogconfig:place_button("Contact");
emit <|
self.document.location.hash='!/';
$KOBJ(window).hashchange(function() {
if(KOBJ.a16x88.previous == undefined || KOBJ.a16x88.previous != self.document.location.hash) {
var app = KOBJ.get_application("a16x88");
app.raise_event("hash_change",{"newhash": self.document.location.hash});
KOBJ.a16x88.previous = self.document.location.hash;
}
});
|>;
}
always {
raise explicit event blog_ready
}
}
rule hash_change is inactive {
select when web hash_change
pre {
hash = event:param("newhash");
}
notify("The hash changed!",hash)
}
rule show_contact {
select when web click "#siteNavContact"
or web hash_change newhash "/contact$"
pre {
contact_html = <<
<h2 class="mainheading">Contact</h2>
<article class="post">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas a diam eget velit fringilla consequat. Duis nec justo urna, at tempus augue. Curabitur tristique, mi vitae ultrices lacinia, ante odio auctor odio, quis bibendum nulla augue quis diam. Aenean commodo justo ac leo cursus porttitor.
</p>
</article>
>>;
title = config:blogtitle + " - Contact";
}
{
blogconfig:paint_container(title, contact_html);
blogconfig:update_frag("/contact");
}
}
rule show_home {
select when web click "#siteNavHome"
or web hash_change newhash "/$"
or explicit blog_ready
pre {
container = <<
<h2 class="mainheading">Latest from the blog</h2>
<div id="blogarticles">Code Monkey was here :)</div>
>>;
title = config:blogtitle;
}
{
blogconfig:paint_container(title, container);
blogconfig:update_frag("/");
}
always {
raise explicit event container_ready;
raise explicit event need_blog_data for a16x89
}
}
rule show_new_article {
select when explicit new_article_added
pre {}
always {
raise explicit event blog_ready
}
}
rule show_articles {
select when explicit container_ready
and explicit blog_data_ready
foreach event:param("blogdata") setting (postKey,postHash)
pre {
postArticle = <<
<article class="post">
<header>
<h3>Title: #{postHash.pick("$.title")}</h3>
<span class="author">by #{postHash.pick("$.author")}</span>
</header>
<p>#{postHash.pick("$.body")}</p>
<footer>
<p class="postinfo">Published on <time>#{postHash.pick("$.time")}</time></p>
</footer>
</article>
>>;
}
{
//notify("author: ", postAuthor) with sticky = true;
prepend("div#blogarticles", postArticle);
}
}
}