Skip to content

Commit b21623e

Browse files
author
stackdump
committed
refactor to use events without registry or acl
1 parent 596d0b0 commit b21623e

File tree

11 files changed

+182
-67
lines changed

11 files changed

+182
-67
lines changed

projects/gnoland/gno.land/p/eve000/event/component/calendar.gno

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package component
22

33
import (
4-
"net/url"
5-
"strings"
6-
"strconv"
7-
"time"
4+
"net/url"
5+
"strconv"
6+
"strings"
7+
"time"
88

9-
"gno.land/p/demo/ufmt"
9+
"gno.land/p/demo/ufmt"
1010
)
1111

1212
func CalenderDataUrl(path string, a *Flyer) string {
13-
if path == "" {
14-
path = "?format=ics"
15-
}
13+
if path == "" {
14+
path = "?format=ics"
15+
}
1616
data := IcsCalendarFile(path, a)
1717
return "data:text/calendar;charset=utf-8," + url.QueryEscape(data)
1818
}

projects/gnoland/gno.land/p/eve000/event/component/component.gno

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package component
22

33
import (
4-
"std"
54
"net/url"
65
"regexp"
6+
"std"
77
"strconv"
88
"strings"
99
"time"
@@ -15,7 +15,7 @@ import (
1515
// Interfaces
1616

1717
type IcsFileProvider interface {
18-
ToIcs() string // returns the content of the ICS file
18+
ToIcs() string // returns the content of the ICS file
1919
}
2020

2121
type ContentProvider interface {
@@ -102,8 +102,8 @@ func RenderPage(path string, c interface{}, body ...Content) string {
102102
format := q.Get("format")
103103

104104
if c == nil {
105-
panic("RenderPage: component is nil")
106-
}
105+
panic("RenderPage: component is nil")
106+
}
107107

108108
switch {
109109
case format == "ics" && implementsIcsFileProvider(c):
@@ -248,11 +248,11 @@ func ParseQuery(path string) url.Values {
248248

249249
func EscapeHtml(s string) string {
250250
replacements := map[string]string{
251-
"&": "&",
252-
"<": "&lt;",
253-
">": "&gt;",
251+
"&": "&amp;",
252+
"<": "&lt;",
253+
">": "&gt;",
254254
"\"": "&quot;",
255-
"'": "&#39;",
255+
"'": "&#39;",
256256
}
257257
for old, new := range replacements {
258258
s = strings.ReplaceAll(s, old, new)
@@ -313,8 +313,8 @@ func FormatDate(date time.Time) string {
313313
// Helper Functions
314314

315315
func implementsIcsFileProvider(c interface{}) bool {
316-
_, ok := c.(IcsFileProvider)
317-
return ok
316+
_, ok := c.(IcsFileProvider)
317+
return ok
318318
}
319319

320320
func implementsJsonProvider(c interface{}) bool {
@@ -338,28 +338,28 @@ func implementsMarkdownProvider(c interface{}) bool {
338338
}
339339

340340
func renderBody(body []Content) string {
341-
var sb strings.Builder
342-
for _, content := range body {
343-
if content.Published {
344-
sb.WriteString("\n\n" + content.Render() + "\n\n")
345-
sb.WriteString("---\n\n")
346-
}
347-
}
348-
return sb.String()
341+
var sb strings.Builder
342+
for _, content := range body {
343+
if content.Published {
344+
sb.WriteString("\n\n" + content.Render() + "\n\n")
345+
sb.WriteString("---\n\n")
346+
}
347+
}
348+
return sb.String()
349349
}
350350

351351
func renderIcsFile(c interface{}, body []Content) string {
352-
var sb strings.Builder
353-
sb.WriteString("```ics\n" + c.(IcsFileProvider).ToIcs() + "\n```")
354-
sb.WriteString(renderBody(body))
355-
return sb.String()
352+
var sb strings.Builder
353+
sb.WriteString("```ics\n" + c.(IcsFileProvider).ToIcs() + "\n```")
354+
sb.WriteString(renderBody(body))
355+
return sb.String()
356356
}
357357

358358
func renderJsonLD(c interface{}, body []Content) string {
359-
var sb strings.Builder
360-
sb.WriteString("```jsonld\n" + c.(JsonLdProvider).ToJsonLD() + "\n```")
361-
sb.WriteString(renderBody(body))
362-
return sb.String()
359+
var sb strings.Builder
360+
sb.WriteString("```jsonld\n" + c.(JsonLdProvider).ToJsonLD() + "\n```")
361+
sb.WriteString(renderBody(body))
362+
return sb.String()
363363
}
364364

365365
// Show data as Json next to the body content:w
@@ -376,4 +376,26 @@ func renderJsonLd(c interface{}, body []Content) string {
376376
sb.WriteString("```\n" + c.(JsonLdProvider).ToJsonLD() + "\n```")
377377
sb.WriteString(renderBody(body))
378378
return sb.String()
379-
}
379+
}
380+
381+
func GetQueryParam(q url.Values, param string) (string, bool) {
382+
if values, ok := q[param]; ok && len(values) > 0 {
383+
return values[0], true
384+
}
385+
return "", false
386+
}
387+
388+
func HasQueryParam(q url.Values, param string) bool {
389+
if values, ok := q[param]; ok && len(values) > 0 {
390+
return true
391+
}
392+
return false
393+
}
394+
395+
func QueryValues(fullURL string) url.Values {
396+
u, err := url.Parse(fullURL)
397+
if err != nil {
398+
panic("Error Parsing URL")
399+
}
400+
return u.Query()
401+
}

projects/gnoland/gno.land/p/eve000/event/component/flyer.gno

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package component
22

33
import (
4+
"net/url"
45
"std"
56
"strings"
67
"time"
7-
"net/url"
88

99
"gno.land/p/demo/ufmt"
1010
)
1111

12-
1312
type Flyer struct {
1413
Name string
1514
Location *Location
@@ -188,9 +187,9 @@ func (a *Flyer) SetRenderOpts(opts map[string]interface{}) {
188187
}
189188

190189
func (a *Flyer) ToJsonLD() string {
191-
return EventJsonLD("?format=jsonld", a)
190+
return EventJsonLD("?format=jsonld", a)
192191
}
193192

194193
func (a *Flyer) ToIcs() string {
195-
return IcsCalendarFile("?format=ics", a)
194+
return IcsCalendarFile("?format=ics", a)
196195
}

projects/gnoland/gno.land/p/eve000/event/component/jsonld.gno

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package component
22

33
import (
4-
"strings"
4+
"strings"
55

6-
"gno.land/p/demo/ufmt"
6+
"gno.land/p/demo/ufmt"
77
)
88

99
const DateFormatJsonLD = "2006-01-02T15:04:05-07:00"

projects/gnoland/gno.land/p/eve000/event/event.gno

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"gno.land/p/eve000/event/component"
1010
)
1111

12-
1312
// FIXME either change interface or satisfy it
1413
//var _ Api = (*Event)(nil)
1514

@@ -170,7 +169,7 @@ func (evt *Event) Flyer() *component.Flyer {
170169
Status: evt.Status,
171170
Description: evt.Description,
172171
Sessions: evt.Sessions,
173-
Images: evt.Images,
172+
Images: evt.Images,
174173
}
175174
flyer.SetRenderOpts(evt.renderOpts)
176175
return flyer
@@ -196,7 +195,5 @@ func (evt *Event) ToAnchor() string {
196195

197196
// Render provides a syntactic sugar for rendering a Flyer using a template function.
198197
func (evt *Event) Render(path string, tpl func(path string, flyer *component.Flyer) string) string {
199-
return tpl(path, evt.Flyer())
198+
return tpl(path, evt.Flyer())
200199
}
201-
202-

projects/gnoland/gno.land/p/eve000/event/registry.gno

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,6 @@ type Registry struct {
1919
patchRealm string // realm that is allowed to update the patch level, used for debugging and content management
2020
}
2121

22-
func getQueryParam(q url.Values, param string) (string, bool) {
23-
if q == nil {
24-
return "", false
25-
}
26-
value := q.Get(param)
27-
if value == "" {
28-
return "", false
29-
}
30-
return value, true
31-
}
32-
33-
func hasQueryParam(q url.Values, param string) bool {
34-
_, ok := getQueryParam(q, param)
35-
return ok
36-
}
37-
3822
func (r *Registry) Render(path string, body ...component.Content) string {
3923
fullURL := std.CurrentRealm().PkgPath() + path // REVIEW: is this really needed?
4024
u, err := url.Parse(fullURL)
@@ -48,11 +32,11 @@ func (r *Registry) Render(path string, body ...component.Content) string {
4832
}
4933
evt := r.GetEvent(event_id)
5034
switch {
51-
case hasQueryParam(q, "session"):
35+
case component.HasQueryParam(q, "session"):
5236
return component.RenderComponent(path, evt.GetSession(q.Get("session")))
53-
case hasQueryParam(q, "location"):
37+
case component.HasQueryParam(q, "location"):
5438
return component.RenderComponent(path, evt.GetLocation(q.Get("location")))
55-
case hasQueryParam(q, "speaker"):
39+
case component.HasQueryParam(q, "speaker"):
5640
return component.RenderComponent(path, evt.GetSpeaker(q.Get("speaker")))
5741
default:
5842
return component.RenderPage(path, evt.Flyer(), body...)

projects/gnoland/gno.land/r/buidlthefuture000/events/gnolandlaunch/public.gno

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ func RenderCalendar(path string) string {
1111

1212
func Render(path string) (out string) {
1313
return app.Render(path)
14-
}
14+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package gnoplan
2+
3+
import (
4+
"time"
5+
6+
"gno.land/p/eve000/event"
7+
eve "gno.land/p/eve000/event/component"
8+
)
9+
10+
func init() {
11+
evt.SetRenderOpts(map[string]interface{}{
12+
"Speaker": struct{}{},
13+
"SvgFooter": struct{}{},
14+
"CalendarDataUrl": struct{}{},
15+
//"CalendarHost": "webcal://127.0.0.1:8080",
16+
})
17+
}
18+
19+
var banner = eve.Content{
20+
Published: true,
21+
Markdown: "\n\n#### REVIEW: this is a read-only event - suitable to deploy as private realm \n\n" +
22+
" Calender is a direct data URL download, no external server needed.\n\n",
23+
}
24+
25+
var evt = &event.Event{
26+
Name: "Gnoland Launch Preplanning",
27+
Location: locations["gnowhere"],
28+
Status: eve.EventScheduled,
29+
AttendanceMode: eve.OnlineEventAttendanceMode,
30+
StartDate: time.Date(2025, 7, 14, 0, 0, 0, 0, time.UTC),
31+
EndDate: time.Date(2025, 8, 29, 0, 0, 0, 0, time.UTC),
32+
Description: "Join this event to become a beta tester for Gnoland, help us think about planning the launch, and provide feedback on the platform. \n\n This is a pre-planning event to gather ideas and feedback from the community.",
33+
Sessions: []*eve.Session{
34+
sessions["kickoff"],
35+
sessions["retro"],
36+
},
37+
}
38+
39+
func Render(path string) string {
40+
return render(path, banner)
41+
}
42+
43+
func RenderCalendar(path string) string {
44+
return evt.Render(path, eve.IcsCalendarFile)
45+
}
46+
47+
func render(path string, body ...eve.Content) string {
48+
q := eve.QueryValues(path)
49+
switch {
50+
case eve.HasQueryParam(q, "session"):
51+
return eve.RenderComponent(path, evt.GetSession(q.Get("session")))
52+
case eve.HasQueryParam(q, "location"):
53+
return eve.RenderComponent(path, evt.GetLocation(q.Get("location")))
54+
case eve.HasQueryParam(q, "speaker"):
55+
return eve.RenderComponent(path, evt.GetSpeaker(q.Get("speaker")))
56+
default:
57+
return eve.RenderPage(path, evt.Flyer(), body...)
58+
}
59+
}
60+
61+
var locations = map[string]*eve.Location{
62+
"gnowhere": {
63+
Name: "Gnowhere",
64+
Description: "",
65+
},
66+
"discord": {
67+
Name: "Discord ",
68+
Description: "",
69+
},
70+
}
71+
72+
var speakerBios = map[string]*eve.Speaker{
73+
"mason": {
74+
Name: "Mason",
75+
Biography: "Nathan is a member of AIBLabs working on Eve event platform.",
76+
Affiliation: "allinbits.com",
77+
PictureURL: "",
78+
},
79+
"nathan": {
80+
Name: "Nathan",
81+
Biography: "Nathan is a member of AIBLabs working on Eve event platform.",
82+
Affiliation: "allinbits.com",
83+
PictureURL: "",
84+
},
85+
"matt": {
86+
Name: "Matt",
87+
Biography: "Matt is a member of AIBLabs working on Eve event platform.",
88+
Affiliation: "allinbits.com",
89+
PictureURL: "https://stackdump.com/profile.jpg",
90+
Address: "g1e8vw6gh284q7ggzqs8ne6r8j9aqhnmvl6rzzmz",
91+
},
92+
}
93+
94+
var sessions = map[string]*eve.Session{
95+
"kickoff": {
96+
Title: "Test our Tools: Gno.land and Gnoland",
97+
Description: "This is a kickoff of an internal beta.",
98+
Speaker: speakerBios["matt"],
99+
StartTime: time.Date(2025, 7, 17, 13, 0, 0, 0, time.UTC),
100+
EndTime: time.Date(2025, 7, 17, 13, 30, 0, 0, time.UTC),
101+
Location: locations["gnowhere"],
102+
},
103+
"retro": {
104+
Title: "Review and Retrospective",
105+
Description: "Let's review the beta and gather feedback.",
106+
Speaker: speakerBios["mason"],
107+
StartTime: time.Date(2025, 8, 29, 13, 0, 0, 0, time.UTC),
108+
EndTime: time.Date(2025, 8, 29, 13, 30, 0, 0, time.UTC),
109+
Location: locations["gnowhere"],
110+
},
111+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module = "gno.land/r/buidlthefuture000/events/gnopriv001"
2+
gno = "0.9"

projects/gnoland/gno.land/r/buidlthefuture000/events/index.gno

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var upcoming = `
2222
- (current) [gno.land Pre-Launch Event](/r/buidlthefuture000/events/gnoplan001)
2323
- (future) [gno.land Launch Event](/r/buidlthefuture000/events/gnolandlaunch)
2424
- (fictional) [demo OnSite Event](/r/buidlthefuture000/events/onsite001)
25+
- (private) [event w/o registry or acl](/r/buidlthefuture000/events/gnopriv001)
2526
`
2627

2728
var intro = `

0 commit comments

Comments
 (0)