Class: BootstrapBuilders::Button

Inherits:
Object
  • Object
show all
Defined in:
lib/bootstrap_builders/button.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Button

Returns a new instance of Button.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bootstrap_builders/button.rb', line 16

def initialize(args)
  @label = args[:label]
  @class = args[:class]
  @url = args.fetch(:url)
  @args = args
  @context = args.fetch(:context)
  @icon = args[:icon]
  @can = args[:can]
  @small = args[:small]
  @mini = args[:mini]
end

Instance Attribute Details

#label ⇒ Object

Returns the value of attribute label.



2
3
4
# File 'lib/bootstrap_builders/button.rb', line 2

def label
  @label
end

Class Method Details

.parse_url_args(args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/bootstrap_builders/button.rb', line 4

def self.parse_url_args(args)
  if args.last.is_a?(Hash)
    real_args = args.pop
  else
    real_args = {}
  end

  real_args[:url] ||= args.shift if args.first
  real_args[:label] ||= args.shift if args.first
  real_args
end

Instance Method Details

#can_model ⇒ Object



51
52
53
54
# File 'lib/bootstrap_builders/button.rb', line 51

def can_model
  can_object unless @can_model
  @can_model
end

#can_model_class ⇒ Object



56
57
58
59
# File 'lib/bootstrap_builders/button.rb', line 56

def can_model_class
  can_object unless @can_model_class
  @can_model_class
end

#classes ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/bootstrap_builders/button.rb', line 28

def classes
  unless @classes
    @classes = BootstrapBuilders::ClassAttributeHandler.new(class: ["btn", "btn-default"])
    @classes.add("btn-xs") if @mini || @small
    @classes.add(@class) if @class
  end

  @classes
end

#html ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/bootstrap_builders/button.rb', line 38

def html
  return unless can?

  handle_confirm_argument

  @context.link_to(@url, class: classes.classes, data: @args[:data], method: @args[:method], remote: @args[:remote], title: @args[:title]) do
    html = ""
    html << @context.(:i, nil, class: ["fa", "fa-#{@icon}"]) if @icon
    html << " #{@label}" if @label && !@mini
    html.strip.html_safe
  end
end