Module: Spree::Admin::NavigationHelper
- Defined in:
- app/helpers/spree/admin/navigation_helper.rb
Instance Method Summary collapse
-
#admin_breadcrumb(*ancestors, &block) ⇒ Object
Add items to current page breadcrumb heirarchy.
- #admin_breadcrumbs ⇒ Object
- #admin_page_title ⇒ Object
- #button(text, icon_name = nil, button_type = 'submit', options = {}) ⇒ Object
- #button_link_to(text, url, html_options = {}) ⇒ Object
- #configurations_menu_item(link_text, url, description = '') ⇒ Object
- #configurations_sidebar_menu_item(link_text, url, options = {}) ⇒ Object
- #icon(icon_name) ⇒ Object
- #link_to_clone(resource, options = {}) ⇒ Object
- #link_to_delete(resource, options = {}) ⇒ Object
- #link_to_edit(resource, options = {}) ⇒ Object
- #link_to_edit_url(url, options = {}) ⇒ Object
- #link_to_new(resource) ⇒ Object
- #link_to_with_icon(icon_name, text, url, options = {}) ⇒ Object
-
#render_admin_breadcrumbs ⇒ Object
Render Bootstrap style breadcrumbs.
- #settings_tab_item(link_text, url, options = {}) ⇒ Object
-
#tab(*args, &_block) ⇒ Object
Make an admin tab that coveres one or more resources supplied by symbols Option hash may follow.
Instance Method Details
#admin_breadcrumb(*ancestors, &block) ⇒ Object
Add items to current page breadcrumb heirarchy
9 10 11 12 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 9 def (*ancestors, &block) .concat(ancestors) if ancestors.present? .push(capture(&block)) if block_given? end |
#admin_breadcrumbs ⇒ Object
4 5 6 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 4 def ||= [] end |
#admin_page_title ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 27 def admin_page_title if content_for?(:title) content_for(:title) elsif content_for?(:page_title) content_for(:page_title) elsif .any? .map{ |x| (x) }.reverse.join(' - ') else Spree.t(controller.controller_name, default: controller.controller_name.titleize) end end |
#button(text, icon_name = nil, button_type = 'submit', options = {}) ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 123 def (text, icon_name = nil, = 'submit', = {}) class_names = "button" if icon_name Spree::Deprecation.warn "Using icon_name arg is deprecated. Icons could not be visible in future versions.", caller class_names.prepend "fa fa-#{icon_name} " end (text, .merge(type: , class: class_names)) end |
#button_link_to(text, url, html_options = {}) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 132 def (text, url, = {}) = { class: '' }.merge() if [:method] && [:method].to_s.downcase != 'get' && ![:remote] form_tag(url, method: .delete(:method)) do (text, .delete(:icon), nil, ) end else [:class] += ' button' if [:icon] Spree::Deprecation.warn "Using :icon option is deprecated. Icons could not be visible in future versions.", caller [:class] += " fa fa-#{html_options[:icon]}" end link_to(text, url, ) end end |
#configurations_menu_item(link_text, url, description = '') ⇒ Object
151 152 153 154 155 156 157 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 151 def (link_text, url, description = '') %(<tr> <td>#{link_to(link_text, url)}</td> <td>#{description}</td> </tr> ).html_safe end |
#configurations_sidebar_menu_item(link_text, url, options = {}) ⇒ Object
159 160 161 162 163 164 165 166 167 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 159 def (link_text, url, = {}) is_active = url.ends_with?(controller.controller_name) || url.ends_with?("#{controller.controller_name}/edit") || url.ends_with?("#{controller.controller_name.singularize}/edit") [:class] = is_active ? 'active' : nil content_tag(:li, ) do link_to(link_text, url) end end |
#icon(icon_name) ⇒ Object
119 120 121 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 119 def icon(icon_name) icon_name ? content_tag(:i, '', class: icon_name) : '' end |
#link_to_clone(resource, options = {}) ⇒ Object
80 81 82 83 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 80 def link_to_clone(resource, = {}) [:data] = { action: 'clone' } link_to_with_icon('copy', Spree.t(:clone), clone_object_url(resource), ) end |
#link_to_delete(resource, options = {}) ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 101 def link_to_delete(resource, = {}) url = [:url] || object_url(resource) name = [:name] || Spree.t('actions.delete') confirm = [:confirm] || Spree.t(:are_you_sure) [:class] = "delete-resource" [:data] = { confirm: confirm, action: 'remove' } link_to_with_icon 'trash', name, url, end |
#link_to_edit(resource, options = {}) ⇒ Object
90 91 92 93 94 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 90 def link_to_edit(resource, = {}) url = [:url] || edit_object_url(resource) [:data] = { action: 'edit' } link_to_with_icon('edit', Spree.t('actions.edit'), url, ) end |
#link_to_edit_url(url, options = {}) ⇒ Object
96 97 98 99 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 96 def link_to_edit_url(url, = {}) [:data] = { action: 'edit' } link_to_with_icon('edit', Spree.t('actions.edit'), url, ) end |
#link_to_new(resource) ⇒ Object
85 86 87 88 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 85 def link_to_new(resource) [:data] = { action: 'new' } link_to_with_icon('plus', Spree.t(:new), edit_object_url(resource)) end |
#link_to_with_icon(icon_name, text, url, options = {}) ⇒ Object
110 111 112 113 114 115 116 117 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 110 def link_to_with_icon(icon_name, text, url, = {}) [:class] = ([:class].to_s + " fa fa-#{icon_name} icon_link with-tip").strip [:class] += ' no-text' if [:no_text] [:title] = text if [:no_text] text = [:no_text] ? '' : content_tag(:span, text, class: 'text') .delete(:no_text) link_to(text, url, ) end |
#render_admin_breadcrumbs ⇒ Object
Render Bootstrap style breadcrumbs
15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 15 def if content_for?(:page_title) (content_for(:page_title)) end content_tag :ol, class: 'breadcrumb' do safe_join .map { |level| content_tag(:li, level, class: "breadcrumb-item #{level == admin_breadcrumbs.last ? 'active' : ''}") } end end |
#settings_tab_item(link_text, url, options = {}) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 169 def settings_tab_item(link_text, url, = {}) is_active = url.ends_with?(controller.controller_name) || url.ends_with?("#{controller.controller_name}/edit") || url.ends_with?("#{controller.controller_name.singularize}/edit") [:class] = 'fa' [:class] += ' active' if is_active [:datahook] = "admin_settings_#{link_text.downcase.tr(' ', '_')}" content_tag(:li, ) do link_to(link_text, url) end end |
#tab(*args, &_block) ⇒ Object
Make an admin tab that coveres one or more resources supplied by symbols Option hash may follow. Valid options are
* :label to override link text, otherwise based on the first resource name (translated)
* :route to override automatically determining the default route
* :match_path as an alternative way to control when the tab is active, /products would match /admin/products, /admin/products/5/variants etc.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 44 def tab(*args, &_block) = { label: args.first.to_s } if args.last.is_a?(Hash) = .merge(args.pop) end [:route] ||= "admin_#{args.first}" destination_url = [:url] || spree.send("#{options[:route]}_path") label = Spree.t([:label], scope: [:admin, :tab]) css_classes = [] if [:icon] link = link_to_with_icon([:icon], label, destination_url) css_classes << 'tab-with-icon' else link = link_to(label, destination_url) end selected = if [:match_path].is_a? Regexp request.fullpath =~ [:match_path] elsif [:match_path] request.fullpath.starts_with?("#{spree.admin_path}#{options[:match_path]}") else request.fullpath.starts_with?(destination_url) || args.include?(controller.controller_name.to_sym) end css_classes << 'selected' if selected if [:css_class] css_classes << [:css_class] end content_tag('li', link + (yield if block_given?), class: css_classes.join(' ') ) end |