diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-05-24 20:42:20 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-05-24 20:42:20 -0400 |
commit | fbff52e48d4591a752d83fbebb49a3a355eef5ae (patch) | |
tree | 9549990f151888c98d2b5a2ad338a41f48c3e91e /src/guff.cr | |
parent | 83242fd94df0280e7793caef912d7a12b240fcec (diff) | |
download | guff-fbff52e48d4591a752d83fbebb49a3a355eef5ae.tar.bz2 guff-fbff52e48d4591a752d83fbebb49a3a355eef5ae.zip |
add dropdown class and post type dropdown
Diffstat (limited to 'src/guff.cr')
-rw-r--r-- | src/guff.cr | 105 |
1 files changed, 99 insertions, 6 deletions
diff --git a/src/guff.cr b/src/guff.cr index b5ea71a..121f150 100644 --- a/src/guff.cr +++ b/src/guff.cr @@ -274,12 +274,14 @@ module Guff JOIN states b ON (b.state_id = a.state_id) - LEFT JOIN blogs c - ON (c.post_id = a.post_id) - LEFT JOIN pages d - ON (d.post_id = a.post_id) - LEFT JOIN projects e - ON (e.post_id = a.post_id) + JOIN sites c + ON (c.site_id = a.site_id) + LEFT JOIN blogs x + ON (x.post_id = a.post_id) + LEFT JOIN pages y + ON (y.post_id = a.post_id) + LEFT JOIN projects z + ON (z.post_id = a.post_id) WHERE %s ", @@ -485,6 +487,9 @@ module Guff "y.post_id IS NOT NULL" when "project" "z.post_id IS NOT NULL" + when "all" + # allow "all" + "1" else raise "unknown post type: #{post_type}" end @@ -1648,6 +1653,73 @@ module Guff ECR.def_to_s("src/views/tab.ecr") end + module Dropdown + module Icon + ICON_TEMPLATE = "<i class='fa fa-fw %s'></i>" + + def self.icon(id : String?) + if id && id.size > 0 + ICON_TEMPLATE % [HTML.escape(id.not_nil!)] + else + "" + end + end + end + + class ItemView < View + def initialize( + context : Context, + @active : Bool, + @item : Hash(Symbol, String) + ) + super(context) + end + + private def v(id : Symbol) + h(@item[id]) + end + + private def li_css + @active ? "class='active'" : "" + end + + ECR.def_to_s("src/views/dropdown/item.ecr") + end + + class MenuView < View + def initialize( + context : Context, + @id : String, + @name : String, + @text : String, + @css : String, + @icon : String, + @default : String, + @items : Array(Hash(Symbol, String)) + ) + super(context) + + @default_name = @items.reduce("") do |r, row| + (row[:id]? == @default) ? row[:name] : r + end as String + end + + private def items + String.build do |io| + @items.each do |item| + io << ItemView.new( + context: @context, + active: @default == item[:id]?, + item: item + ).to_s + end + end + end + + ECR.def_to_s("src/views/dropdown/menu.ecr") + end + end + abstract class HTMLView < View TEMPLATES = { script: "<script type='text/javascript' src='%s'></script>", @@ -1677,6 +1749,27 @@ module Guff end end end + + def dropdown( + id : String, + name : String, + text : String, + icon : String, + css : String, + default : String, + items : Array(Hash(Symbol, String)) + ) + Dropdown::MenuView.new( + context: @context, + id: id, + name: name, + text: text, + icon: icon, + css: css, + default: default, + items: items + ).to_s + end end class AdminPageView < HTMLView |