Module: BHM::Admin::SidebarHelper

Defined in:
lib/bhm/admin/sidebar_helper.rb

Instance Method Summary collapse

Instance Method Details

#collection_sidebarObject



21
22
23
# File 'lib/bhm/admin/sidebar_helper.rb', line 21

def collection_sidebar
  sidebar_menu(parent_sidebar_content + resources_sidebar_content)
end

#container_classesObject



5
6
7
# File 'lib/bhm/admin/sidebar_helper.rb', line 5

def container_classes
  @container_classes ||= []
end

#container_classes_cssObject



9
10
11
# File 'lib/bhm/admin/sidebar_helper.rb', line 9

def container_classes_css
  container_classes.uniq.join(' ').presence
end

#current_parent_nameObject



55
56
57
# File 'lib/bhm/admin/sidebar_helper.rb', line 55

def current_parent_name
  sidebar_klass_name(parent_class).titleize
end

#current_resource_nameObject



51
52
53
# File 'lib/bhm/admin/sidebar_helper.rb', line 51

def current_resource_name
  sidebar_klass_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 hide_sidebar!
  content_for :sidebar, '&nbsp;'.html_safe
end


31
32
33
# File 'lib/bhm/admin/sidebar_helper.rb', line 31

def menu_link(*args, &blk)
  (:li, link_to(*args, &blk), :class => 'menu-item')
end

#object_sidebarObject



25
26
27
28
29
# File 'lib/bhm/admin/sidebar_helper.rb', line 25

def object_sidebar
  name = current_resource_name
  inner_menu = parent_sidebar_content + resources_sidebar_content(name) + resource_sidebar_content(name)
  sidebar_menu(inner_menu)
end

#parent_sidebar_contentObject



59
60
61
62
63
64
65
66
67
# File 'lib/bhm/admin/sidebar_helper.rb', line 59

def parent_sidebar_content
  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 resource_sidebar_content(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 resources_sidebar_content(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


46
47
48
49
# File 'lib/bhm/admin/sidebar_helper.rb', line 46

def sidebar_klass_name(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


36
37
38
39
40
41
42
43
44
# File 'lib/bhm/admin/sidebar_helper.rb', line 36

def sidebar_menu(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 = (: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