diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-05-21 16:40:43 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-05-21 16:40:43 -0400 |
commit | b11313e2fe62932d1a3fa2de21a57bcfd00c2371 (patch) | |
tree | b1d2a83852afbf8c76f9bc9c1615d8a25e6158da | |
parent | 9a5034a115d5e05eedd2ce8f3727660c08a943b6 (diff) | |
download | guff-b11313e2fe62932d1a3fa2de21a57bcfd00c2371.tar.bz2 guff-b11313e2fe62932d1a3fa2de21a57bcfd00c2371.zip |
add admin tabs
-rw-r--r-- | src/guff.cr | 79 | ||||
-rw-r--r-- | src/views/admin-page.ecr | 11 | ||||
-rw-r--r-- | src/views/tab.ecr | 13 |
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> |