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 hierarchy.
- #admin_breadcrumbs ⇒ Object
- #admin_page_title ⇒ Object
- #configurations_menu_item(link_text, url, description = '') ⇒ Object
- #configurations_sidebar_menu_item(link_text, url, options = {}) ⇒ 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
- #solidus_icon(icon_name) ⇒ Object
-
#tab(*args, &block) ⇒ Object
Make an admin tab that covers 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 hierarchy
11 12 13 14 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 11 def (*ancestors, &block) .concat(ancestors) if ancestors.present? .push(capture(&block)) if block_given? end |
#admin_breadcrumbs ⇒ Object
6 7 8 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 6 def @admin_breadcrumbs ||= [] end |
#admin_page_title ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 30 def admin_page_title if content_for?(:title) content_for(:title) elsif content_for?(:page_title) content_for(:page_title) elsif .any? .map { || () }.reverse.join(' - ') else t(controller.controller_name, default: controller.controller_name.titleize, scope: 'spree') end end |
#configurations_menu_item(link_text, url, description = '') ⇒ Object
147 148 149 150 151 152 153 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 147 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
155 156 157 158 159 160 161 162 163 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 155 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 |
#link_to_clone(resource, options = {}) ⇒ Object
90 91 92 93 94 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 90 def link_to_clone(resource, = {}) [:data] = { action: 'clone' } [:method] = :post link_to_with_icon('copy', t('spree.clone'), clone_object_url(resource), ) end |
#link_to_delete(resource, options = {}) ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 112 def link_to_delete(resource, = {}) url = [:url] || object_url(resource) name = [:name] || t('spree.actions.delete') confirm = [:confirm] || t('spree.are_you_sure') [:class] = "#{[:class]} delete-resource".strip [:data] = { confirm:, action: 'remove' } link_to_with_icon 'trash', name, url, end |
#link_to_edit(resource, options = {}) ⇒ Object
101 102 103 104 105 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 101 def link_to_edit(resource, = {}) url = [:url] || edit_object_url(resource) [:data] = { action: 'edit' } link_to_with_icon('edit', t('spree.actions.edit'), url, ) end |
#link_to_edit_url(url, options = {}) ⇒ Object
107 108 109 110 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 107 def link_to_edit_url(url, = {}) [:data] = { action: 'edit' } link_to_with_icon('edit', t('spree.actions.edit'), url, ) end |
#link_to_new(resource) ⇒ Object
96 97 98 99 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 96 def link_to_new(resource) [:data] = { action: 'new' } link_to_with_icon('plus', t('spree.new'), edit_object_url(resource)) end |
#link_to_with_icon(icon_name, text, url, options = {}) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 121 def link_to_with_icon(icon_name, text, url, = {}) [:class] = "#{[:class]} icon_link with-tip".strip if icon_name.starts_with?('ri-') svg_map = image_path('spree/backend/themes/solidus_admin/remixicon.symbol.svg') icon_tag = tag.svg( tag.use('xlink:href': "#{svg_map}##{icon_name}"), 'aria-hidden': true, style: "fill: currentColor;", ) else [:class] << " fa fa-#{icon_name}" icon_tag = ''.html_safe end [: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(icon_tag + text, url, ) end |
#render_admin_breadcrumbs ⇒ Object
Render Bootstrap style breadcrumbs
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 17 def if content_for?(:page_title) (content_for(:page_title)) end content_tag :ol, class: 'breadcrumb' do segments = .map do |level| content_tag(:li, level, class: "breadcrumb-item #{level == .last ? 'active' : ''}") end safe_join(segments) end end |
#settings_tab_item(link_text, url, options = {}) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 165 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 [:data] ||= {} [:data][:hook] = "admin_settings_#{link_text.downcase.tr(' ', '_')}" content_tag(:li, ) do link_to(link_text, url) end end |
#solidus_icon(icon_name) ⇒ Object
143 144 145 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 143 def solidus_icon(icon_name) icon_name ? content_tag(:i, '', class: icon_name) : '' end |
#tab(*args, &block) ⇒ Object
Make an admin tab that covers 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)
* :match_path as an alternative way to control when the tab is active, /products would match /admin/products, /admin/products/5/variants etc.
* :match_path can also be a callable that takes a request and determines whether the menu item is selected for the request.
* :selected to explicitly control whether the tab is active
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 79 80 81 82 83 84 85 86 87 88 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 48 def tab(*args, &block) = args.last.is_a?(Hash) ? args.pop.dup : {} css_classes = Array([:css_class]) if .key?(:route) Spree.deprecator.warn "Passing a route to #tab is deprecated. Please pass a url instead." [:url] ||= spree.send("#{[:route]}_path") end if args.any? Spree.deprecator.warn "Passing resources to #tab is deprecated. Please use the `label:` and `match_path:` options instead." [:label] ||= args.first [:url] ||= spree.send("admin_#{args.first}_path") [:selected] = args.include?(controller.controller_name.to_sym) end [:url] ||= spree.send("admin_#{[:label]}_path") label = t([:label], scope: [:spree, :admin, :tab]) [:selected] ||= if [:match_path].is_a? Regexp request.fullpath =~ [:match_path] elsif [:match_path].respond_to?(:call) [:match_path].call(request) elsif [:match_path] request.fullpath.starts_with?("#{spree.admin_path}#{[:match_path]}") else request.fullpath.starts_with?([:url]) end css_classes << 'selected' if [:selected] if [:icon] link = link_to_with_icon([:icon], label, [:url]) css_classes << 'tab-with-icon' else link = link_to(label, [:url]) end block_content = capture(&block) if block_given? content_tag('li', link + block_content.to_s, class: css_classes.join(' ') ) end |