Module: Storefront::Helpers::ComponentHelper
- Defined in:
- lib/storefront/helpers/component_helper.rb
Instance Method Summary collapse
- #cached_widget(*args, &block) ⇒ Object
- #flash? ⇒ Boolean
- #form(*args, &block) ⇒ Object (also: #form_for)
- #render_flash ⇒ Object
- #sidebar(*args, &block) ⇒ Object (also: #sidebar_for)
- #table(*args, &block) ⇒ Object (also: #table_for)
-
#widget(*args, &block) ⇒ Object
(also: #component, #cell)
Core widget method.
- #widget_cache_key(name, cache_key) ⇒ Object
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 (*args, &block) = args. unless [:cache_key] raise ArgumentError.new("Specify the :cache_key option with a unique id for fragment caching this widget.") end cached_content (args[0], [:cache_key]) do (*(args << ), &block) end end |
#flash? ⇒ 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_flash ⇒ Object
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| content_tag(:output, content, :class => "flash-#{type}") end.join end |
#sidebar(*args, &block) ⇒ Object Also known as:
25 26 27 |
# File 'lib/storefront/helpers/component_helper.rb', line 25 def (*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 (*args, &block) = args. path = args.shift name = path.to_s.gsub("/", "_") if self.respond_to?("#{name}_widget") send("#{name}_widget", name, , &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 (name, cache_key) key = [] key << "storefront/widget" key << "#{name}" # name of widget key << cache_key.to_s key.join("/") end |