Skip to content

Commit 7a1d3bb

Browse files
committed
switch to liquid
1 parent 104aea3 commit 7a1d3bb

5 files changed

Lines changed: 121 additions & 124 deletions

File tree

Gopkg.lock

Lines changed: 33 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929
branch = "master"
3030
name = "github.com/akerl/go-lambda"
3131

32-
[[constraint]]
33-
name = "github.com/aymerick/raymond"
34-
version = "2.0.2"
35-
3632
[[constraint]]
3733
name = "github.com/google/go-github"
3834
version = "18.2.0"
@@ -49,6 +45,10 @@
4945
branch = "master"
5046
name = "golang.org/x/oauth2"
5147

48+
[[constraint]]
49+
name = "gopkg.in/osteele/liquid.v1"
50+
version = "1.2.4"
51+
5252
[prune]
5353
go-tests = true
5454
unused-packages = true

assets/index.html.hbs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,29 @@
1111
<body>
1212
<div class="content">
1313
<h1 class="title">OAuth Handler</h1>
14-
{{#if session.login}}
15-
<p>You're already logged in, {{session.login}}</p>
16-
{{#if session.memberships}}
14+
{% if session.login != "" %}
15+
<p>You're already logged in, {{ session.login }}</p>
16+
{% if orgs.size > 0 %}
1717
<p>Your memberships:</p>
1818
<ul>
19-
{{#each_team session.memberships as |teams org|}}
20-
<li>{{org}}
19+
{% for org in orgs %}
20+
<li>{{ org }}
2121
<ul>
22-
{{#each teams as |team|}}
23-
<li>{{team}}</li>
24-
{{/each}}
22+
{% assign teams = session.memberships[org] | sort %}
23+
{% for team in teams %}
24+
<li>{{ team }}</li>
25+
{% endfor %}
2526
</ul>
2627
</li>
27-
{{/each}}
28+
{% endfor %}
2829
</ul>
29-
{{else}}
30+
{% else %}
3031
<p>You don't seem to have any memberships</p>
31-
{{/if}}
32+
{% endif %}
3233
<p><a href="/logout">Click here</a> to log out</p>
33-
{{else}}
34+
{% else %}
3435
<a href="/auth">Click here to log in</a>
35-
{{/if}}
36+
{% endif %}
3637
</div>
3738
</body>
3839
</html>

static.go

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ func init() {
607607
fi: FileInfo{
608608
name: "favicon.ico",
609609
size: 5558,
610-
modTime: time.Unix(0, 1523457789513995842),
610+
modTime: time.Unix(0, 1527090282022963545),
611611
isDir: false,
612612
},
613613
}, "/index.html.hbs": File{
@@ -687,73 +687,73 @@ func init() {
687687
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x75, 0x6c,
688688
0x3e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
689689
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
690-
0x20, 0x20, 0x7b, 0x7b, 0x23, 0x65, 0x61, 0x63, 0x68, 0x20, 0x73, 0x65,
691-
0x73, 0x73, 0x69, 0x6f, 0x6e, 0x2e, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72,
692-
0x73, 0x68, 0x69, 0x70, 0x73, 0x20, 0x61, 0x73, 0x20, 0x7c, 0x74, 0x65,
693-
0x61, 0x6d, 0x73, 0x20, 0x6f, 0x72, 0x67, 0x7c, 0x7d, 0x7d, 0x0a, 0x20,
690+
0x20, 0x20, 0x7b, 0x7b, 0x23, 0x65, 0x61, 0x63, 0x68, 0x5f, 0x74, 0x65,
691+
0x61, 0x6d, 0x20, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x2e, 0x6d,
692+
0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x73, 0x20, 0x61,
693+
0x73, 0x20, 0x7c, 0x74, 0x65, 0x61, 0x6d, 0x73, 0x20, 0x6f, 0x72, 0x67,
694+
0x7c, 0x7d, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
694695
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
696+
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x6c, 0x69, 0x3e,
697+
0x7b, 0x7b, 0x6f, 0x72, 0x67, 0x7d, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20,
695698
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
696-
0x20, 0x20, 0x20, 0x3c, 0x6c, 0x69, 0x3e, 0x7b, 0x7b, 0x6f, 0x72, 0x67,
697-
0x7d, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
698699
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
699-
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c,
700-
0x75, 0x6c, 0x3e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
700+
0x20, 0x20, 0x20, 0x20, 0x3c, 0x75, 0x6c, 0x3e, 0x0a, 0x20, 0x20, 0x20,
701701
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
702702
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
703-
0x20, 0x20, 0x20, 0x20, 0x7b, 0x7b, 0x23, 0x65, 0x61, 0x63, 0x68, 0x20,
704-
0x74, 0x65, 0x61, 0x6d, 0x73, 0x20, 0x61, 0x73, 0x20, 0x7c, 0x74, 0x65,
705-
0x61, 0x6d, 0x7c, 0x7d, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
703+
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7b, 0x7b, 0x23,
704+
0x65, 0x61, 0x63, 0x68, 0x20, 0x74, 0x65, 0x61, 0x6d, 0x73, 0x20, 0x61,
705+
0x73, 0x20, 0x7c, 0x74, 0x65, 0x61, 0x6d, 0x7c, 0x7d, 0x7d, 0x0a, 0x20,
706706
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
707707
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
708-
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x6c,
709-
0x69, 0x3e, 0x7b, 0x7b, 0x74, 0x65, 0x61, 0x6d, 0x7d, 0x7d, 0x3c, 0x2f,
710-
0x6c, 0x69, 0x3e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
711708
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
709+
0x20, 0x20, 0x20, 0x3c, 0x6c, 0x69, 0x3e, 0x7b, 0x7b, 0x74, 0x65, 0x61,
710+
0x6d, 0x7d, 0x7d, 0x3c, 0x2f, 0x6c, 0x69, 0x3e, 0x0a, 0x20, 0x20, 0x20,
712711
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
713-
0x20, 0x20, 0x20, 0x20, 0x7b, 0x7b, 0x2f, 0x65, 0x61, 0x63, 0x68, 0x7d,
714-
0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
715712
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
716-
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x2f,
717-
0x75, 0x6c, 0x3e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
713+
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7b, 0x7b, 0x2f,
714+
0x65, 0x61, 0x63, 0x68, 0x7d, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
718715
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
719-
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x2f, 0x6c, 0x69,
720-
0x3e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
721716
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
722-
0x20, 0x20, 0x7b, 0x7b, 0x2f, 0x65, 0x61, 0x63, 0x68, 0x7d, 0x7d, 0x0a,
717+
0x20, 0x20, 0x20, 0x3c, 0x2f, 0x75, 0x6c, 0x3e, 0x0a, 0x20, 0x20, 0x20,
723718
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
724-
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x2f, 0x75, 0x6c,
725-
0x3e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
726-
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7b, 0x7b, 0x65, 0x6c, 0x73, 0x65,
727-
0x7d, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
728-
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c,
729-
0x70, 0x3e, 0x59, 0x6f, 0x75, 0x20, 0x64, 0x6f, 0x6e, 0x27, 0x74, 0x20,
730-
0x73, 0x65, 0x65, 0x6d, 0x20, 0x74, 0x6f, 0x20, 0x68, 0x61, 0x76, 0x65,
731-
0x20, 0x61, 0x6e, 0x79, 0x20, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73,
732-
0x68, 0x69, 0x70, 0x73, 0x3c, 0x2f, 0x70, 0x3e, 0x0a, 0x20, 0x20, 0x20,
733719
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
734-
0x20, 0x7b, 0x7b, 0x2f, 0x69, 0x66, 0x7d, 0x7d, 0x0a, 0x20, 0x20, 0x20,
720+
0x20, 0x3c, 0x2f, 0x6c, 0x69, 0x3e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
735721
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
736-
0x20, 0x3c, 0x70, 0x3e, 0x3c, 0x61, 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d,
737-
0x22, 0x2f, 0x6c, 0x6f, 0x67, 0x6f, 0x75, 0x74, 0x22, 0x3e, 0x43, 0x6c,
738-
0x69, 0x63, 0x6b, 0x20, 0x68, 0x65, 0x72, 0x65, 0x3c, 0x2f, 0x61, 0x3e,
739-
0x20, 0x74, 0x6f, 0x20, 0x6c, 0x6f, 0x67, 0x20, 0x6f, 0x75, 0x74, 0x3c,
740-
0x2f, 0x70, 0x3e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
741-
0x20, 0x20, 0x20, 0x20, 0x7b, 0x7b, 0x65, 0x6c, 0x73, 0x65, 0x7d, 0x7d,
742-
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
743-
0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x61, 0x20, 0x68, 0x72, 0x65, 0x66,
744-
0x3d, 0x22, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x22, 0x3e, 0x43, 0x6c, 0x69,
745-
0x63, 0x6b, 0x20, 0x68, 0x65, 0x72, 0x65, 0x20, 0x74, 0x6f, 0x20, 0x6c,
746-
0x6f, 0x67, 0x20, 0x69, 0x6e, 0x3c, 0x2f, 0x61, 0x3e, 0x0a, 0x20, 0x20,
747-
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7b, 0x7b,
748-
0x2f, 0x69, 0x66, 0x7d, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
749-
0x20, 0x20, 0x3c, 0x2f, 0x64, 0x69, 0x76, 0x3e, 0x0a, 0x20, 0x20, 0x20,
750-
0x20, 0x3c, 0x2f, 0x62, 0x6f, 0x64, 0x79, 0x3e, 0x0a, 0x3c, 0x2f, 0x68,
751-
0x74, 0x6d, 0x6c, 0x3e, 0x0a,
722+
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7b, 0x7b, 0x2f, 0x65, 0x61,
723+
0x63, 0x68, 0x7d, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
724+
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
725+
0x20, 0x3c, 0x2f, 0x75, 0x6c, 0x3e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
726+
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7b,
727+
0x7b, 0x65, 0x6c, 0x73, 0x65, 0x7d, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20,
728+
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
729+
0x20, 0x20, 0x20, 0x20, 0x3c, 0x70, 0x3e, 0x59, 0x6f, 0x75, 0x20, 0x64,
730+
0x6f, 0x6e, 0x27, 0x74, 0x20, 0x73, 0x65, 0x65, 0x6d, 0x20, 0x74, 0x6f,
731+
0x20, 0x68, 0x61, 0x76, 0x65, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x6d, 0x65,
732+
0x6d, 0x62, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x73, 0x3c, 0x2f, 0x70,
733+
0x3e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
734+
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7b, 0x7b, 0x2f, 0x69, 0x66, 0x7d,
735+
0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
736+
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x70, 0x3e, 0x3c, 0x61, 0x20,
737+
0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, 0x2f, 0x6c, 0x6f, 0x67, 0x6f, 0x75,
738+
0x74, 0x22, 0x3e, 0x43, 0x6c, 0x69, 0x63, 0x6b, 0x20, 0x68, 0x65, 0x72,
739+
0x65, 0x3c, 0x2f, 0x61, 0x3e, 0x20, 0x74, 0x6f, 0x20, 0x6c, 0x6f, 0x67,
740+
0x20, 0x6f, 0x75, 0x74, 0x3c, 0x2f, 0x70, 0x3e, 0x0a, 0x20, 0x20, 0x20,
741+
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7b, 0x7b, 0x65,
742+
0x6c, 0x73, 0x65, 0x7d, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
743+
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x61,
744+
0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, 0x2f, 0x61, 0x75, 0x74, 0x68,
745+
0x22, 0x3e, 0x43, 0x6c, 0x69, 0x63, 0x6b, 0x20, 0x68, 0x65, 0x72, 0x65,
746+
0x20, 0x74, 0x6f, 0x20, 0x6c, 0x6f, 0x67, 0x20, 0x69, 0x6e, 0x3c, 0x2f,
747+
0x61, 0x3e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
748+
0x20, 0x20, 0x20, 0x7b, 0x7b, 0x2f, 0x69, 0x66, 0x7d, 0x7d, 0x0a, 0x20,
749+
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x2f, 0x64, 0x69, 0x76,
750+
0x3e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x2f, 0x62, 0x6f, 0x64, 0x79,
751+
0x3e, 0x0a, 0x3c, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0x0a,
752752
},
753753
fi: FileInfo{
754754
name: "index.html.hbs",
755-
size: 1637,
756-
modTime: time.Unix(0, 1525693943159555283),
755+
size: 1642,
756+
modTime: time.Unix(0, 1538445782252480969),
757757
isDir: false,
758758
},
759759
},

templates.go

Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@ package main
22

33
import (
44
"fmt"
5-
"sort"
6-
7-
"github.com/akerl/github-auth-lambda/session"
85

96
"github.com/akerl/go-lambda/apigw/events"
10-
"github.com/aymerick/raymond"
7+
"gopkg.in/osteele/liquid.v1"
118
)
129

1310
var (
11+
engine *liquid.Engine
1412
templateNames = []string{
1513
"/index.html",
1614
}
17-
templates = map[string]*raymond.Template{}
15+
templates = map[string]*liquid.Template{}
1816
)
1917

2018
func loadTemplate(name string) error {
@@ -25,11 +23,10 @@ func loadTemplate(name string) error {
2523
if !found {
2624
return fmt.Errorf("template not found: %s", tplFile)
2725
}
28-
templates[name], err = raymond.Parse(tplFile)
26+
templates[name], err = engine.ParseString(tplFile)
2927
if err != nil {
3028
return fmt.Errorf("template failed to parse (%s): %s", tplFile, err)
3129
}
32-
templates[name].RegisterHelper("each_team", eachTeamHelper)
3330
return nil
3431
}
3532

@@ -44,27 +41,30 @@ func loadTemplates() error {
4441
}
4542

4643
func init() {
44+
engine = liquid.NewEngine()
4745
err := loadTemplates()
4846
if err != nil {
4947
panic(err)
5048
}
5149
}
5250

53-
type templateContext struct {
54-
Session session.Session
55-
Request events.Request
56-
Config map[string]string
57-
}
58-
59-
func newTemplateContext(req events.Request) (templateContext, error) {
60-
tc := templateContext{
61-
Request: req,
62-
Config: config.TemplateData,
51+
func newTemplateContext(req events.Request) (map[string]interface{}, error) {
52+
tc := map[string]interface{}{
53+
"request": req,
54+
"config": config.TemplateData,
6355
}
6456

6557
var err error
66-
tc.Session, err = sm.Read(req)
67-
return tc, err
58+
tc["session"], err = sm.Read(req)
59+
if err != nil {
60+
return tc, err
61+
}
62+
tc["orgs"] = make([]string, len(tc["session"].Memberships))
63+
for idx, org := range tc["session"].Memberships {
64+
tc["orgs"][idx] = org
65+
}
66+
sort.Strings(tc["orgs"])
67+
return tc, nil
6868
}
6969

7070
func execTemplate(name string, req events.Request) (string, error) {
@@ -78,28 +78,6 @@ func execTemplate(name string, req events.Request) (string, error) {
7878
return "", fmt.Errorf("template does not exist: %s", name)
7979
}
8080

81-
page, err := tpl.Exec(ctx)
81+
page, err := tpl.RenderString(ctx)
8282
return page, err
8383
}
84-
85-
func eachTeamHelper(memberships map[string][]string, options *raymond.Options) string {
86-
result := ""
87-
88-
orgCount := len(memberships)
89-
orgs := make([]string, orgCount)
90-
idx := 0
91-
for key := range memberships {
92-
orgs[idx] = key
93-
idx++
94-
}
95-
sort.Strings(orgs)
96-
97-
for idx, key := range orgs {
98-
val := memberships[key]
99-
sort.Strings(val)
100-
data := options.newIterDataFrame(orgCount, idx, key)
101-
result += options.evalBlock(val, data, key)
102-
}
103-
104-
return result
105-
}

0 commit comments

Comments
 (0)