diff options
-rw-r--r-- | data/assets/js/admin/tabs/posts.js | 9 | ||||
-rw-r--r-- | src/guff/views/admin-page.cr | 79 | ||||
-rw-r--r-- | src/views/admin-page.ecr | 31 |
3 files changed, 60 insertions, 59 deletions
diff --git a/data/assets/js/admin/tabs/posts.js b/data/assets/js/admin/tabs/posts.js index 1cabc31..96d3a3c 100644 --- a/data/assets/js/admin/tabs/posts.js +++ b/data/assets/js/admin/tabs/posts.js @@ -85,12 +85,7 @@ jQuery(function($) { ], }); - var POST_TYPE_ICONS = { - blog: 'fa-sticky-note-o', - page: 'fa-bookmark-o', - project: 'fa-cube', - }; - + // FIXME: move this to DATA as well? var POST_STATES = { draft: { css: 'bg-warning', @@ -154,7 +149,7 @@ jQuery(function($) { return TEMPLATES.run('post', $.extend(row, { css: css, label: label, - icon: POST_TYPE_ICONS[row.post_type], + icon: DATA.post_types[row.post_type].icon, post_url: post_url, })); }).join('')); diff --git a/src/guff/views/admin-page.cr b/src/guff/views/admin-page.cr index 7761994..b9dc6f2 100644 --- a/src/guff/views/admin-page.cr +++ b/src/guff/views/admin-page.cr @@ -3,6 +3,26 @@ require "./html" class Guff::Views::AdminPageView < Guff::Views::HTMLView TITLE = "Guff Admin" + POST_TYPES = { + blog: { + id: "blog", + name: "Blog Post", + icon: "fa-sticky-note-o", + }, + + page: { + id: "page", + name: "Page", + icon: "fa-file-text-o", + }, + + project: { + id: "project", + name: "Project", + icon: "fa-cube", + }, + } + TABS = { "admin" => [{ :id => "home", @@ -69,6 +89,20 @@ class Guff::Views::AdminPageView < Guff::Views::HTMLView }], } + NEW_POST_MENU_ITEM = " + <li> + <a + href='#' + title='Create new %s.' + class='add-post' + data-type='%s' + > + <i class='fa fa-fw %s'></i> + %s + </a> + </li> + " + TEMPLATES = { :option => " <option value='%s'>%s</option> @@ -86,42 +120,11 @@ class Guff::Views::AdminPageView < Guff::Views::HTMLView <i class='fa fa-fw fa-caret-down'></i> </a> - <ul class='dropdown-menu'> - <li> - <a - href='#' - title='Create new blog post.' - class='add-post' - data-type='blog' - > - <i class='fa fa-fw fa-sticky-note-o'></i> - Blog Post - </a> - </li> - - <li> - <a - href='#' - title='Create new page.' - class='add-post' - data-type='page' - > - <i class='fa fa-fw fa-bookmark-o'></i> - Page - </a> - </li> - - <li> - <a - href='#' - title='Create new project.' - class='add-post' - data-type='project' - > - <i class='fa fa-fw fa-cube'></i> - Project - </a> - </li> + <ul class='dropdown-menu'>" + %i{blog page project}.map { |id| + NEW_POST_MENU_ITEM % %i{name id icon name}.map { |key| + POST_TYPES[id][key] + } + }.join + " </ul> ", @@ -215,5 +218,9 @@ class Guff::Views::AdminPageView < Guff::Views::HTMLView }.join("") end + private def page_data + { post_types: POST_TYPES}.to_json + end + ECR.def_to_s("src/views/admin-page.ecr") end diff --git a/src/views/admin-page.ecr b/src/views/admin-page.ecr index 8581c01..00f2796 100644 --- a/src/views/admin-page.ecr +++ b/src/views/admin-page.ecr @@ -106,22 +106,16 @@ :text => "Show all types.", }, { :type => "divider", - }, { - :id => "blog", - :name => "Blog Post", - :icon => "fa-sticky-note-o", - :text => "Show blog posts.", - }, { - :id => "page", - :name => "Page", - :icon => "fa-bookmark-o", - :text => "Show pages.", - }, { - :id => "project", - :name => "Project", - :icon => "fa-cube", - :text => "Show projects.", - }], + }] + %i{blog page project}.map { |id| + name = POST_TYPES[id][:name] + + { + :id => POST_TYPES[id][:id], + :name => name, + :icon => POST_TYPES[id][:icon], + :text => "Show #{name}s.", + } + } ) %></div><!-- btn-group --> @@ -1431,6 +1425,11 @@ </div><!-- modal --> </body> + + <script type='text/javascript'><!-- + var DATA = <%= page_data %>; + // --> + </script> <%= scripts %w{ assets/jquery-2.2.1.min.js |