-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestion-answer.app
55 lines (52 loc) · 1.48 KB
/
question-answer.app
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
module question-answer
template answers(q:Question){
gridRow{
gridSpan(12){
comments(q.comments)
<hr/>
header3{
if(q.answers.length == 1){ "1 Answer" }
else {
if(q.answers.length > 1){
output(q.answers.length) " Answers"
}
}
}
for(a:Answer in q.answers order by a.votes desc){
gridContainer{
gridRow{
gridSpan(2){
answerInfo(a)
}
gridSpan(8){
output(a.content)
}
}
}
comments(a.comments)
<hr/>
}
yourAnswer(q)
}
}
}
template yourAnswer(q:Question){
var answer := Answer{ user := securityContext.principal }
if(loggedIn()){
horizontalForm("Your Answer"){
input(answer.content)[onkeyup := action{ replace(answerPreview, showContent(answer.content)); }]
block{ "Preview: " }
placeholder answerPreview {}
formActions{
submit action{ q.answers.add(answer); } [class="btn btn-primary"] {"Submit"}
}
}
}
}
template answerInfo(a:Answer){
well{
block{ "answered by " navigate user(a.user) { output(a.user) } }
block{ output(age(a.created)) " ago" }
block{ output(a.voters.length) " votes" voting(a.voters) }
}
}