Module: Storefront::Helpers::ComponentHelper

Defined in:
lib/storefront/helpers/component_helper.rb

Instance Method Summary collapse

Instance Method Details

#cached_widget(*args, &block) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/storefront/helpers/component_helper.rb', line 42

def cached_widget(*args, &block)
  options = args.extract_options!
  
  unless options[:cache_key]
    raise ArgumentError.new("Specify the :cache_key option with a unique id for fragment caching this widget.")
  end
  
  cached_content widget_cache_key(args[0], options[:cache_key]) do
    widget(*(args << options), &block)
  end
end

#flash?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/storefront/helpers/component_helper.rb', line 11

def flash?
  flash.present?
end

#form(*args, &block) ⇒ Object Also known as: form_for



15
16
17
# File 'lib/storefront/helpers/component_helper.rb', line 15

def form(*args, &block)
  Storefront::Components::Form.new(self, *args).render_with_pointer(&block)
end

#render_flashObject



4
5
6
7
8
9
# File 'lib/storefront/helpers/component_helper.rb', line 4

def render_flash
  flash_to_render = [:success, :failure, :notice, :error]
  flash.select { |type, _| flash_to_render.include?(type) }.map do |type, content|
    (:output, content, :class => "flash-#{type}")
  end.join
end


25
26
27
# File 'lib/storefront/helpers/component_helper.rb', line 25

def sidebar(*args, &block)
  Storefront::Components::Sidebar.new(self, *args).render_with_pointer(&block)
end

#table(*args, &block) ⇒ Object Also known as: table_for



20
21
22
# File 'lib/storefront/helpers/component_helper.rb', line 20

def table(*args, &block)
  Storefront::Components::Table.new(self, *args).render_with_pointer(&block)
end

#widget(*args, &block) ⇒ Object Also known as: component, cell

Core widget method

You can automatically cache this based on some fragment cache key, and it will invalidate the cache automatically If the widget is given a record, it will use that.



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/storefront/helpers/component_helper.rb', line 59

def widget(*args, &block)
  options = args.extract_options!
  path    = args.shift
  name    = path.to_s.gsub("/", "_")
  
  if self.respond_to?("#{name}_widget")
    send("#{name}_widget", name, options, &block)
  else
    raise "Please define a helper method 'def #{name}_widget(*args)'"
  end
end

#widget_cache_key(name, cache_key) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/storefront/helpers/component_helper.rb', line 73

def widget_cache_key(name, cache_key)
  key = []
  key << "storefront/widget"
  key << "#{name}" # name of widget
  key << cache_key.to_s
  key.join("/")
end