Class: Storefront::Components::Header

Inherits:
Base
  • Object
show all
Defined in:
lib/storefront/components/header.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

#options, #template

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



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
# File 'lib/storefront/components/header.rb', line 46

def extract_options!(*args)
  options = args.extract_options!
  return options if options[:skip_format]
  return {} if options[:title] == false
  
  header_html                       = options[:header_html] || {}
  header_html.reverse_merge!(:class => config.header_class)
  
  title_html                        = options[:title_html] || {}
  title_html.reverse_merge!(:class  => config.title_class)
  title_html[:value]                = options.delete(:title)
  
  title_html[:value] = t?(title_html[:value], :scope => :"widgets.headers") if title_html[:value].is_a?(::Symbol)

  subtitle_html = options[:subtitle_html] || {}
  if subtitle_html.present? || options[:subtitle].present?
    subtitle_html.reverse_merge!(:class  => config.subtitle_class)
    subtitle_html[:value]           = options.delete(:subtitle)
    subtitle_html[:value]           = t?(subtitle_html[:value], :scope => :"widgets.headers") if subtitle_html[:value].is_a?(::Symbol)
  end

  options.merge! :header_html => header_html, :title_html => title_html, :subtitle_html => subtitle_html

  options
end

#render(&block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/storefront/components/header.rb', line 4

def render(&block)
  return nil if options.blank?
  
  template.capture_haml do
    if block_given? && !pointer.include?("footer")
      template.haml_tag :header, options[:header_html], &block
    elsif options[:header] == false || pointer.include?("footer")
      render_titles
    else
      if options[:title_html][:value].present?
        template.haml_tag :header, options[:header_html] do
          render_titles
        end
      else
        template.haml_tag :header, options[:header_html]
      end
    end
  end
end

#render_titlesObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/storefront/components/header.rb', line 24

def render_titles
  level    = options[:level] || config.default_component_header_level
  title    = options[:title_html].delete(:value)
  subtitle = options[:subtitle_html].delete(:value)
  
  if title.present?
    if subtitle.present?
      if options[:header] == false || pointer.include?("footer")
        template.haml_tag :"h#{level}", title, options[:title_html]
        template.haml_tag :"h#{level + 1}", subtitle, options[:subtitle_html]
      else
        template.haml_tag :hgroup do
          template.haml_tag :"h#{level}", title, options[:title_html]
          template.haml_tag :"h#{level + 1}", subtitle, options[:subtitle_html]
        end
      end
    else
      template.haml_tag :"h#{level}", title, options[:title_html]
    end
  end
end