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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
require "ecr/macros"
require "../page"
class Guff::TestAuthHTMLView
TITLE = "Guff Auth Test"
FEATURES = %w{bootstrap font-awesome guff/util}
SCRIPTS = %w{
/guff-stuff/ckeditor-4.5.8-custom/ckeditor.js
/guff-stuff/js/search-field.js
/guff-stuff/test/tab-users.js
/guff-stuff/test/tab-posts.js
}
TEMPLATES = TemplateCache.new({
role: "
<option
value='%{name}'
title='%{text}'
%{selected}
>
%{name}
</option>
",
tab: "
<li role='presentation' class='%{css}'>
<a
id='%{prefix}-tab-%{id}'
href='#%{prefix}-tab-pane-%{id}'
title='%{text}'
aria-controls='%{prefix}-tab-pane-%{id}'
role='tab'
data-toggle='tab'
>
<i class='fa %{icon}'></i>
%{name}
</a>
</li>
",
new_post_button: "
<a
href='#'
class='btn btn-primary'
title='Create new blog post.'
data-toggle='modal'
data-target='#blog-edit-dialog'
>
<i class='fa fa-plus-circle'></i>
New Post
</a><!-- btn -->
<a
href='#'
class='btn btn-primary'
title='Show additonal options.'
data-toggle='dropdown'
>
<span class='hidden'>
<i class='fa fa-plus-circle'></i>
New
</span>
<i class='fa fa-caret-down'></i>
</a>
<ul class='dropdown-menu'>
<li class='hidden'>
<a
href='#'
title='Create new blog post.'
data-toggle='modal'
data-target='#blog-edit-dialog'
>
<i class='fa fa-fw fa-bullhorn'></i>
New Post
</a>
</li>
<li>
<a
href='#'
title='Create new page.'
data-toggle='modal'
data-target='#page-edit-dialog'
>
<i class='fa fa-fw fa-bookmark-o'></i>
New Page
</a>
</li>
<li>
<a
href='#'
title='Create new project.'
data-toggle='modal'
data-target='#project-edit-dialog'
>
<i class='fa fa-fw fa-cube'></i>
New Project
</a>
</li>
</ul>
",
})
def self.run(models, context : HTTP::Server::Context)
new(models).run(context)
end
def initialize(@models : Models)
end
def run(context)
page = PageHTMLView.new(TITLE, self.to_s)
page.add_features(FEATURES)
page.scripts.concat(SCRIPTS)
context.response.content_type = page.content_type
context.response.puts page
end
def h(s : String)
HTML.escape(s || "")
end
def get_roles
@models.role.get_roles.map { |row|
name = row["role_name"] as String
TEMPLATES[:role].run({
"name": h(name),
"text": h(row["role_desc"] as String),
"selected": (name == "guest") ? "selected='selected'" : ""
})
}.join
end
def get_tabs(id : Symbol, prefix : String)
@models.tab.get_tabs(id).map { |row|
TEMPLATES[:tab].run(row.merge({
"prefix": prefix,
"css": row["css"]? || "",
"name": h(row["name"]),
"text": h(row["text"]),
}))
}.join
end
def get_new_post_button
TEMPLATES[:new_post_button].run
end
ECR.def_to_s("./src/guff/views/ecrs/test/auth.ecr")
end
|