-
Notifications
You must be signed in to change notification settings - Fork 0
/
bofm.sample_consumer.krl
93 lines (93 loc) · 2.01 KB
/
bofm.sample_consumer.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
ruleset bofm.consumer {
meta {
use module bofm.data alias bofm
shares __testing, refs, refs_page, txt_page, shortcuts
}
global {
__testing =
{ "queries": [ { "name": "__testing" }
, { "name": "refs" }
, { "name": "refs_page" }
, { "name": "shortcuts" }
, { "name": "txt_page", "args": [ "ref" ] }
]
, "events": [
]
}
shortcuts = function() {
url = "/io.picolabs.rewrite/picoRewrites?picoID=" + meta:picoId;
http:get(meta:host + url){"content"}.decode()
}
refs = function() {
ent:refs.values().sort(bofm:ref_cmp)
}
ref_option = function(ref) {
<< <option>#{ref}</option>
>>
}
refs_select = function() {
<< <select name="ref">
#{refs().map(function(r){ref_option(r)}).join("")} </select>
>>
}
refs_form = function() {
<<<form action="txt_page.html">
#{refs_select()} <input type="submit" value="txt">
</form>
>>
}
refs_intro = function() {
timestamps = ent:refs.keys();
<<<p>
Collected between #{timestamps.head()}
and #{timestamps[timestamps.length()-1]}
(#{timestamps.length().as("String")})
</p>
>>
}
refs_page = function() {
<<<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Collected verses</title>
</head>
<body>
#{refs_intro()}#{refs_form()}</body>
</html>
>>
}
txt_page = function(ref) {
<<<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>#{ref}</title>
</head>
<body>
<dl style="width:400px">
<dt>#{ref}</dt>
<dd>#{ent:txts{ref}}</dd>
</dl>
</body>
</html>
>>
}
}
rule initialize {
select when wrangler ruleset_added where rids >< meta:rid
or pico ruleset_added where rid == meta:rid
fired {
ent:refs := {};
ent:txts := {};
}
}
rule bofm_verse {
select when bofm verse
foreach event:attrs setting(txt,ref)
fired {
ent:refs{time:now()} := ref;
ent:txts{ref} := txt;
}
}
}