20f7b5880e9f30b2e746cc5c98448a9feb6c1432
1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2014-2015 Alexandre Terrasa <alexandre@moz-code.org>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Templates to display `GameEvent` kinds.
18 module templates_events
25 fun tpl_event
: TplEvent do
26 if kind
== "pull_open" then
27 return new TplPullOpened(self)
28 else if kind
== "pull_merged" then
29 return new TplPullMerged(self)
30 else if kind
== "pull_review" then
31 return new TplPullReview(self)
37 # A TplEvent factorizes HTML rendering methods for `GameEvent`.
44 var title
: String is lazy
do return "raw event"
46 # Load Player from event data.
47 var player
: nullable Player is lazy
do
48 return event
.game
.load_player
(event
.data
["player"].to_s
)
51 # Load reward from event data.
52 var reward
: Int is lazy
do return event
.data
["reward"].as(Int)
54 # Load `github_event` data key as a PullRequestEvent.
55 var pull_event
: PullRequestEvent is lazy
do
56 var obj
= event
.data
["github_event"].as(JsonObject)
57 return new PullRequestEvent.from_json
(event
.game
.api
, obj
)
60 # Load `github_event` data key as a IssueCommentEvent.
61 var issue_comment_event
: IssueCommentEvent is lazy
do
62 var obj
= event
.data
["github_event"].as(JsonObject)
63 return new IssueCommentEvent.from_json
(event
.game
.api
, obj
)
66 # Display a media item for a reward event.
67 fun media_item
: String do
68 return """<div class="media">
69 <a class="media-left" href="{{{player.url}}}">
70 <span class="badge progress-bar-success"
71 style=\"position: absolute\">+{{{reward}}}</span>
72 <img class=\"img-circle\" style="width:50px"
73 src="{{{player.user.avatar_url}}}" alt="{{{player.name}}}">
75 <div class="media-body">
76 <h4 class="media-heading">{{{title}}}</h4>
77 <span class="text-muted">at {{{event.time}}}</span>
87 redef var title
is lazy
do
88 var pull
= pull_event
.pull
89 return "{player.link} pushed {pull.link}"
97 redef var title
is lazy
do
98 var pull
= pull_event
.pull
99 return "{player.link} merged <strong>{pull.commits}</strong> commits with {pull.link}"
107 redef var title
is lazy
do
108 var issue
= issue_comment_event
.issue
109 return "{player.link} reviewed {issue.link}"