Class: Storefront::Components::Button

Inherits:
Base
  • Object
show all
Defined in:
lib/storefront/components/button.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!, #extract_options!, #inside?, #pointer, #render, #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

#initialize(*args, &block) ⇒ Button

Returns a new instance of Button.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/storefront/components/button.rb', line 4

def initialize(*args, &block)
  attributes = args.extract_options!
  label      = args.shift
  path       = args.shift
  tag        = attributes.delete(:as)

  inner_html = attributes.delete(:inner_html) || {}
  outer_html = attributes.delete(:outer_html) || {}
    
  inner_html.merge! clone_attributes(attributes)
  outer_html.merge! clone_attributes(attributes.except(:rel, :target))

  merge_class! outer_html, "button"
  
  capture_haml do
    haml_tag :div, :<, outer_html do
      result = succeed "<span></span>".html_safe do
        if block_given?
          haml_concat capture_haml(&block).gsub("\n", "").strip
        else
          if tag
            haml_tag tag, :>, :<, inner_html
          else
            haml_concat link_to(label, path, inner_html)
          end
        end
      end
      haml_concat result
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Storefront::Components::Base