Module: BHM::Admin::SidebarHelper
- Defined in:
- lib/bhm/admin/sidebar_helper.rb
Instance Method Summary collapse
- #collection_sidebar ⇒ Object
- #container_classes ⇒ Object
- #container_classes_css ⇒ Object
- #current_parent_name ⇒ Object
- #current_resource_name ⇒ Object
- #full_width_page! ⇒ Object
- #hide_sidebar! ⇒ Object
- #menu_link(*args, &blk) ⇒ Object (also: #ml)
- #object_sidebar ⇒ Object
- #parent_sidebar_content ⇒ Object
- #resource_sidebar_content(name = current_resource_name) ⇒ Object
- #resources_sidebar_content(name = current_resource_name) ⇒ Object
- #sidebar_klass_name(klass) ⇒ Object
- #sidebar_menu(inner_content = nil, &blk) ⇒ Object
- #with_safe_buffer(&blk) ⇒ Object
Instance Method Details
#collection_sidebar ⇒ Object
21 22 23 |
# File 'lib/bhm/admin/sidebar_helper.rb', line 21 def ( + ) end |
#container_classes ⇒ Object
5 6 7 |
# File 'lib/bhm/admin/sidebar_helper.rb', line 5 def container_classes @container_classes ||= [] end |
#container_classes_css ⇒ Object
9 10 11 |
# File 'lib/bhm/admin/sidebar_helper.rb', line 9 def container_classes_css container_classes.uniq.join(' ').presence end |
#current_parent_name ⇒ Object
55 56 57 |
# File 'lib/bhm/admin/sidebar_helper.rb', line 55 def current_parent_name (parent_class).titleize end |
#current_resource_name ⇒ Object
51 52 53 |
# File 'lib/bhm/admin/sidebar_helper.rb', line 51 def current_resource_name (resource_class).titleize end |
#full_width_page! ⇒ Object
17 18 19 |
# File 'lib/bhm/admin/sidebar_helper.rb', line 17 def full_width_page! container_classes << 'full-width' end |
#hide_sidebar! ⇒ Object
13 14 15 |
# File 'lib/bhm/admin/sidebar_helper.rb', line 13 def content_for :sidebar, ' '.html_safe end |
#menu_link(*args, &blk) ⇒ Object Also known as: ml
31 32 33 |
# File 'lib/bhm/admin/sidebar_helper.rb', line 31 def (*args, &blk) content_tag(:li, link_to(*args, &blk), :class => 'menu-item') end |
#object_sidebar ⇒ Object
25 26 27 28 29 |
# File 'lib/bhm/admin/sidebar_helper.rb', line 25 def name = current_resource_name = + (name) + (name) () end |
#parent_sidebar_content ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/bhm/admin/sidebar_helper.rb', line 59 def with_safe_buffer do |content| if respond_to?(:parent?) && parent? parent_name = current_parent_name content << ml("View #{parent_name}", parent_url) content << ml("Edit #{parent_name}", File.join(parent_url, 'edit')) end end end |
#resource_sidebar_content(name = current_resource_name) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/bhm/admin/sidebar_helper.rb', line 76 def (name = current_resource_name) with_safe_buffer do |content| content << ml("View #{name}", resource_url) content << ml("Edit #{name}", edit_resource_url) content << ml("Remove #{name}", resource_url, :method => :delete, :confirm => BHM::Admin.t("confirmation.destroy", :object_name => name)) end end |
#resources_sidebar_content(name = current_resource_name) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/bhm/admin/sidebar_helper.rb', line 69 def (name = current_resource_name) with_safe_buffer do |content| content << ml("All #{name.pluralize}", collection_url) content << ml("Add #{name}", new_resource_url) end end |
#sidebar_klass_name(klass) ⇒ Object
46 47 48 49 |
# File 'lib/bhm/admin/sidebar_helper.rb', line 46 def (klass) controller_i18n_path = controller.controller_path.split("/").join(".") BHM::Admin.t(controller_i18n_path.to_sym, :scope => :model_name, :default => klass.model_name.human) end |
#sidebar_menu(inner_content = nil, &blk) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/bhm/admin/sidebar_helper.rb', line 36 def (inner_content = nil, &blk) content = [] content << content_for(:sidebar_menu_start) if content_for?(:sidebar_menu_start) content << inner_content.to_s if inner_content content << capture(&blk) if blk.present? content << content_for(:sidebar_menu_end) if content_for?(:sidebar_menu_end) content = content_tag(:ul, content.join("").html_safe, :class => 'sidebar-menu') content end |
#with_safe_buffer(&blk) ⇒ Object
85 86 87 |
# File 'lib/bhm/admin/sidebar_helper.rb', line 85 def with_safe_buffer(&blk) ActiveSupport::SafeBuffer.new.tap(&blk) end |