aboutsummaryrefslogtreecommitdiff
path: root/src/guff.cr
diff options
context:
space:
mode:
Diffstat (limited to 'src/guff.cr')
-rw-r--r--src/guff.cr79
1 files changed, 75 insertions, 4 deletions
diff --git a/src/guff.cr b/src/guff.cr
index 733a76f..09f2372 100644
--- a/src/guff.cr
+++ b/src/guff.cr
@@ -410,15 +410,41 @@ module Guff
def h(s : String) : String
HTML.escape(s)
end
+ end
+
+ class TabView < View
+ def initialize(
+ context : Context,
+ @prefix : String,
+ @tab : Hash(Symbol, String)
+ )
+ super(context)
+ @id = h("%s-tab-%s" % [@prefix, @tab[:id]]) as String
+ @target = h("%s-pane-%s" % [@prefix, @tab[:id]]) as String
+ end
+ private def v(id : Symbol) : String
+ raise "unknown id: #{id}" unless @tab.has_key?(id)
+ h(@tab[id])
+ end
+
+ ECR.def_to_s("src/views/tab.ecr")
+ end
+
+ abstract class HTMLView < View
TEMPLATES = {
script: "<script type='text/javascript' src='%s'></script>",
style: "<link rel='stylesheet' type='text/css' href='%s'/>",
}
private def assets(key : Symbol, paths : Array(String))
- paths.map { |path| TEMPLATES[key] % [h(path)] }.join
+ String.build do |io|
+ paths.each do |path|
+ io << TEMPLATES[key] % [h(path)]
+ end
+ end
end
+
def scripts(paths : Array(String))
assets(:script, paths)
end
@@ -426,14 +452,59 @@ module Guff
def styles(paths : Array(String))
assets(:style, paths)
end
+
+ def tabs(rows : Array(Hash(Symbol, String)))
+ String.build do |io|
+ rows.each do |row|
+ TabView.new(@context, "admin", row).to_s(io)
+ end
+ end
+ end
end
- class AdminPageView < View
+ class AdminPageView < HTMLView
TITLE = "Guff Admin"
+
+ TABS = [{
+ id: "home",
+ css: "active",
+ icon: "fa-home",
+ name: "Home",
+ text: "View home tab.",
+ }, {
+ id: "posts",
+ css: "",
+ icon: "fa-cubes",
+ name: "Posts",
+ text: "Manage blog, pages, and projects.",
+ }, {
+ id: "files",
+ css: "",
+ icon: "fa-files-o",
+ name: "Files",
+ text: "Manage files.",
+ }, {
+ id: "users",
+ css: "",
+ icon: "fa-users",
+ name: "Users",
+ text: "Manage users and permissions.",
+ }, {
+ id: "settings",
+ css: "",
+ icon: "fa-cog",
+ name: "Settings",
+ text: "Configure site settings.",
+ }]
+
+ def tabs
+ super(TABS)
+ end
+
ECR.def_to_s("src/views/admin-page.ecr")
end
- class LoginPageView < View
+ class LoginPageView < HTMLView
def initialize(context : Context, @error : String? = nil)
super(context)
end
@@ -445,7 +516,7 @@ module Guff
ECR.def_to_s("src/views/login-page.ecr")
end
- class LogoutPageView < View
+ class LogoutPageView < HTMLView
ECR.def_to_s("src/views/logout-page.ecr")
end
end