aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/guff.cr79
-rw-r--r--src/views/admin-page.ecr11
-rw-r--r--src/views/tab.ecr13
3 files changed, 96 insertions, 7 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
diff --git a/src/views/admin-page.ecr b/src/views/admin-page.ecr
index 287e35f..5e2ac2b 100644
--- a/src/views/admin-page.ecr
+++ b/src/views/admin-page.ecr
@@ -44,9 +44,14 @@
</div><!-- navbar -->
<div class='container'>
- <p>
- TODO
- </p>
+ <div class='col-md-12'>
+ <ul class='nav nav-tabs nav-justified' role='tablist'><%=
+ tabs
+ %></ul><!-- nav -->
+
+ <div class='tab-content'>
+ </div><!-- tab-content -->
+ </div><!-- col-md-12 -->
</div><!-- container -->
</body>
diff --git a/src/views/tab.ecr b/src/views/tab.ecr
new file mode 100644
index 0000000..9858920
--- /dev/null
+++ b/src/views/tab.ecr
@@ -0,0 +1,13 @@
+<li role='presentation' class='<%= v(:css) %>'>
+ <a
+ id='<%= @id %>'
+ href='#<%= @target %>'
+ title='<%= v(:text) %>'
+ aria-controls='<%= @target %>'
+ role='tab'
+ data-toggle='tab'
+ >
+ <i class='fa <%= v(:icon) %>'></i>
+ <%= v(:name) %>
+ </a>
+</li>