Class: UiHelpers::Button

Inherits:
Widget show all
Defined in:
lib/ui_helpers/elements/button.rb

Defined Under Namespace

Classes: OnlyIcon, PrimaryIcon, SecondaryIcon, Text

Instance Attribute Summary collapse

Attributes inherited from Widget

#corner, #state

Attributes inherited from Element

#html_options

Instance Method Summary collapse

Methods inherited from Element

#capture, #classes, #classes=, #initialize, #style=, #tag, #with_html_options

Constructor Details

This class inherits a constructor from UiHelpers::Element

Instance Attribute Details

#primary_iconObject

Returns the value of attribute primary_icon.



4
5
6
# File 'lib/ui_helpers/elements/button.rb', line 4

def primary_icon
  @primary_icon
end

#secondary_iconObject

Returns the value of attribute secondary_icon.



4
5
6
# File 'lib/ui_helpers/elements/button.rb', line 4

def secondary_icon
  @secondary_icon
end

#textObject

Returns the value of attribute text.



4
5
6
# File 'lib/ui_helpers/elements/button.rb', line 4

def text
  @text
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/ui_helpers/elements/button.rb', line 4

def title
  @title
end

#valueObject

Returns the value of attribute value.



4
5
6
# File 'lib/ui_helpers/elements/button.rb', line 4

def value
  @value
end

Instance Method Details

#any_icons?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/ui_helpers/elements/button.rb', line 54

def any_icons?
  primary_icon || secondary_icon
end

#content(&block) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ui_helpers/elements/button.rb', line 58

def content(&block)
  capture do |buffer|

    if scope == "icon-only"
      buffer << OnlyIcon.new(@template, :name => primary_icon).tag(:span)
    elsif scope.include?("icon") && primary_icon
      buffer << PrimaryIcon.new(@template, :name => primary_icon).tag(:span)
    end

    buffer << Text.new(@template).tag(:span, text||"&nbsp;", &block)

    if scope.include?("icon") && secondary_icon
      buffer << SecondaryIcon.new(@template, :name => secondary_icon).tag(:span)
    end

  end
end

#scopeObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ui_helpers/elements/button.rb', line 36

def scope
  if text && any_icons?
    if primary_icon && secondary_icon        
      "text-icons" # text + primary_icon + secondary_icon
    elsif primary_icon
      "text-icon-primary" # text + primary_icon
    elsif secondary_icon
      "text-icon-secondary" # text + secondary_icon
    end
  elsif text
    "text-only" # text only
  elsif primary_icon && secondary_icon
    "icons-only" # primary_icon + secondary_icon
  elsif any_icons? 
    "icon-only" # just 1 icon
  end
end