Class: Storefront::Components::Base
- Inherits:
-
Object
- Object
- Storefront::Components::Base
- Includes:
- Helpers::ContentHelper
- Defined in:
- lib/storefront/components/base.rb
Direct Known Subclasses
Breadcrumb, Button, DefinitionList, DefinitionListItem, Flash, Footer, Form, Form::Base, Header, Image, JavascriptTemplate, List, Menu, Nav, Sidebar, Table, Text, Time
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 collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
- #component_name ⇒ Object
- #extract_classes!(type) ⇒ Object
- #extract_options!(*args) ⇒ Object
-
#initialize(template, *args) ⇒ Base
constructor
A new instance of Base.
- #inside?(key) ⇒ Boolean
- #pointer ⇒ Object
-
#render(&block) ⇒ Object
The
to_s
actually renders the object to HAML. - #render_with_pointer(&block) ⇒ Object
- #to_s ⇒ Object
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
#initialize(template, *args) ⇒ Base
Returns a new instance of Base.
14 15 16 17 |
# File 'lib/storefront/components/base.rb', line 14 def initialize(template, *args) @template = template @options = (*args) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (protected)
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/storefront/components/base.rb', line 85 def method_missing(method, *args, &block) if view_context.respond_to?(method) self.class.class_eval %{ def #{method}(*args, &block) view_context.#{method}(*args, &block) end } send method, *args, &block else super end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/storefront/components/base.rb', line 12 def @options end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
12 13 14 |
# File 'lib/storefront/components/base.rb', line 12 def template @template end |
Instance Method Details
#component_name ⇒ Object
65 66 67 |
# File 'lib/storefront/components/base.rb', line 65 def component_name @component_name ||= self.class.name.split("::").last.underscore end |
#extract_classes!(type) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/storefront/components/base.rb', line 69 def extract_classes!(type) [ storefront_config., type.to_s.strip.gsub(/[\s|_]+/, storefront_config.separator).squeeze(storefront_config.separator) ] end |
#extract_options!(*args) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/storefront/components/base.rb', line 47 def (*args) = args. key = args.shift [:title] ||= false [:key] ||= key [:outer_html] ||= {} [:body_html] ||= {} [:footer_html] ||= {} unless [:widget_class] == false merge_class! [:outer_html], *extract_classes!(component_name) end end |
#inside?(key) ⇒ Boolean
34 35 36 37 |
# File 'lib/storefront/components/base.rb', line 34 def inside?(key) index = pointer.index(key) !!(index && index >= 0 && index < pointer.length - 1) end |
#pointer ⇒ Object
39 40 41 |
# File 'lib/storefront/components/base.rb', line 39 def pointer Storefront::Components.pointer end |
#render(&block) ⇒ Object
The to_s
actually renders the object to HAML.
This allows you to pass the widget into a variable the same way you would actually render it in HAML.
23 24 25 |
# File 'lib/storefront/components/base.rb', line 23 def render(&block) end |
#render_with_pointer(&block) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/storefront/components/base.rb', line 27 def render_with_pointer(&block) pointer.push(component_name) result = render(&block) pointer.pop result end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/storefront/components/base.rb', line 43 def to_s render end |