Class: Storefront::Components::Nav
- Defined in:
- lib/storefront/components/nav.rb
Constant Summary
Constants included from Helpers::ContentHelper
Helpers::ContentHelper::SCOPES, Helpers::ContentHelper::SCOPES_WITH_NAMESPACE, Helpers::ContentHelper::SCOPES_WITH_NAMESPACE_AND_NESTED_MODEL, Helpers::ContentHelper::SCOPES_WITH_NESTED_MODEL
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#component_name, #extract_classes!, #initialize, #inside?, #pointer, #render_with_pointer, #to_s
Methods included from Helpers::ContentHelper
#encoded_contents, #font_face_data_uri, #html5_time, #read_binary_file, #read_image_size, #rendered_text, #sanitize, #t?
Constructor Details
This class inherits a constructor from Storefront::Components::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Storefront::Components::Base
Instance Method Details
#extract_options!(*args) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 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 |
# File 'lib/storefront/components/nav.rb', line 25 def (*args) = args. key, path = args = .delete(:locale_options) || {} text = t?(key, .reverse_merge(:scope => :"widgets.nav")) as = .delete(:as) || :span separator = .delete(:separator) if .has_key?(:current) current = .delete(:current) == true else current = on_current_page?(path) end inner_html = .delete(:inner_html) || {} outer_html = .delete(:outer_html) || {} inner_html.merge! clone_attributes() merge_class! outer_html, *[ config.nav_class, current ? config.active_class : nil ].compact.uniq if config.include_aria outer_html[:role] ||= if pointer.include?("menu") :menuitem else :listitem end end text.strip! if config.auto_id_nav outer_html[:id] ||= [text.underscore.parameterize, config.nav_class].join(config.separator).gsub(/[\s|_]+/, config.separator).squeeze(config.separator) end .merge( :inner_html => inner_html, :outer_html => outer_html, :separator => separator, :current => current, :as => as, :value => text, :path => path, :tag => config.nav_tag ) end |
#render(&block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/storefront/components/nav.rb', line 4 def render(&block) template.capture_haml do template.haml_tag [:tag], [:outer_html] do if block_given? case block.arity when 1 yield([:value].strip) else yield end elsif [:current] && [:as] == :span template.haml_tag :span, [:value], [:inner_html] else # inner_html[:title] ||= "Link to the #{text.strip} page." template.haml_concat link_to([:value], [:path], [:inner_html]) end template.haml_tag :span, [:separator] if [:separator] end end end |