Module: Storefront::Helpers::DomHelper
- Included in:
- Form::Base
- Defined in:
- lib/storefront/helpers/dom_helper.rb
Overview
HTML Element Attribute Helper
Instance Method Summary collapse
- #aria(key) ⇒ Object
- #clone_attributes(hash) ⇒ Object
- #dom(attributes = {}) ⇒ Object
- #index_class(index, array_or_length) ⇒ Object
- #merge_class(attributes, *values) ⇒ Object
- #merge_class!(attributes, *values) ⇒ Object
-
#page(*args) ⇒ Object
calls
model.to_title
. - #resource_to_title(resource, options = {}) ⇒ Object
- #title_widget(*args, &block) ⇒ Object
- #title_widget_options ⇒ Object
Instance Method Details
#aria(key) ⇒ Object
57 58 59 |
# File 'lib/storefront/helpers/dom_helper.rb', line 57 def aria(key) {:role => key} end |
#clone_attributes(hash) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/storefront/helpers/dom_helper.rb', line 5 def clone_attributes(hash) result = {} return result if hash.blank? hash.each do |key, value| result[key] = value.is_a?(::Hash) ? clone_attributes(value) : value end result end |
#dom(attributes = {}) ⇒ Object
68 69 70 71 72 |
# File 'lib/storefront/helpers/dom_helper.rb', line 68 def dom(attributes = {}) @dom ||= {} @dom.deep_merge!(attributes) @dom end |
#index_class(index, array_or_length) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/storefront/helpers/dom_helper.rb', line 41 def index_class(index, array_or_length) length = array_or_length.is_a?(::Array) ? array_or_length.length : array_or_length return nil if length.blank? || (length <= 1) if index == 0 "first" elsif index == length - 1 "last" else nil end end |
#merge_class(attributes, *values) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/storefront/helpers/dom_helper.rb', line 21 def merge_class(attributes, *values) if values.present? if attributes[:class].present? classes = attributes[:class].split(/\s+/) else classes = [] end classes += values.compact.map(&:to_s) classes.uniq! else classes = nil end if classes.present? attributes.merge(:class => classes.join(" ")) else attributes end end |
#merge_class!(attributes, *values) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/storefront/helpers/dom_helper.rb', line 14 def merge_class!(attributes, *values) return {} if attributes.nil? hash = merge_class(attributes, *values) attributes[:class] = hash[:class] if hash attributes end |
#page(*args) ⇒ Object
calls model.to_title
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/storefront/helpers/dom_helper.rb', line 75 def page(*args) = args. title = args.shift [:action] ||= storefront_config.current_scope[:action] title = case title when ::String title when ::Symbol t?(title, :scope => :"pages.titles") else if [:title].present? [:title] else parent_name = !![:parent] ? resource_to_title(storefront_config.current_scope[:parent], ) : nil resource_name = resource_to_title(storefront_config.current_scope[:resource], ) [parent_name, resource_name].compact.join(storefront_config.) end end self.title([:browser] || title, ) = (.merge(:title => title)) [:header_html].reverse_merge!(:id => storefront_config.page_header_id) if storefront_config.page_header_id.present? [:title_html].reverse_merge!(:id => storefront_config.page_title_id) if storefront_config.page_title_id.present? [:subtitle_html].reverse_merge!(:id => storefront_config.page_subtitle_id) if storefront_config.page_subtitle_id.present? [:level] = 1 [:skip_format] = true .merge(:title => title) end |
#resource_to_title(resource, options = {}) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/storefront/helpers/dom_helper.rb', line 119 def resource_to_title(resource, = {}) if resource.present? # handle subdomains as well t?([:action].to_sym, :scope => :"pages.titles", :model => Storefront::ModelProxy.model_names(resource), :namespaces => storefront_config.current_scope[:namespace], :allow_blank => true, :action => "", :name => resource.is_a?(::Class) ? resource.name.titleize.pluralize : resource.to_title, :clazz => resource.is_a?(::Class) ? resource.name.titleize : resource.class.name ) end end |
#title_widget(*args, &block) ⇒ Object
108 109 110 111 112 113 |
# File 'lib/storefront/helpers/dom_helper.rb', line 108 def (*args, &block) = args. [:header_html] ||= {} merge_class! [:header_html], *("title-widget") (, &block) end |
#title_widget_options ⇒ Object
115 116 117 |
# File 'lib/storefront/helpers/dom_helper.rb', line 115 def end |