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)
32 else if kind
== "achievement_unlocked" then
33 return new TplAchievementUnlocked(self)
39 # A TplEvent factorizes HTML rendering methods for `GameEvent`.
46 var title
: String is lazy
do return "raw event"
48 # Load Player from event data.
49 var player
: nullable Player is lazy
do
50 return event
.game
.load_player
(event
.data
["player"].to_s
)
53 # Load reward from event data.
54 var reward
: Int is lazy
do return event
.data
["reward"].as(Int)
56 # Load `github_event` data key as a PullRequestEvent.
57 var pull_event
: PullRequestEvent is lazy
do
58 var obj
= event
.data
["github_event"].as(JsonObject)
59 return new PullRequestEvent.from_json
(event
.game
.api
, obj
)
62 # Load `github_event` data key as a IssueCommentEvent.
63 var issue_comment_event
: IssueCommentEvent is lazy
do
64 var obj
= event
.data
["github_event"].as(JsonObject)
65 return new IssueCommentEvent.from_json
(event
.game
.api
, obj
)
68 # Load `achievement` data key as an Achievement.
69 var achievement
: Achievement is lazy
do
70 return player
.load_achievement
(event
.data
["achievement"].to_s
).as(not null)
73 # Display a media item for a reward event.
74 fun media_item
: String do
75 return """<div class="media">
76 <a class="media-left" href="{{{player.url}}}">
77 <span class="badge progress-bar-success"
78 style=\"position: absolute\">+{{{reward}}}</span>
79 <img class=\"img-circle\" style="width:50px"
80 src="{{{player.user.avatar_url}}}" alt="{{{player.name}}}">
82 <div class="media-body">
83 <h4 class="media-heading">{{{title}}}</h4>
84 <span class="text-muted">at {{{event.time}}}</span>
94 redef var title
is lazy
do
95 var pull
= pull_event
.pull
96 return "{player.link} pushed {pull.link}"
104 redef var title
is lazy
do
105 var pull
= pull_event
.pull
106 return "{player.link} merged <strong>{pull.commits}</strong> commits with {pull.link}"
114 redef var title
is lazy
do
115 var issue
= issue_comment_event
.issue
116 return "{player.link} reviewed {issue.link}"
120 # Event: achievement_unlocked
121 class TplAchievementUnlocked
124 redef var title
is lazy
do
125 return "{player.link} unlocked {achievement.link}"