Module: BootstrapBuilders::ButtonsHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/bootstrap_builders/buttons_helper.rb

Instance Method Summary collapse

Instance Method Details

#bb_btn(*args) ⇒ Object



2
3
4
5
6
7
8
# File 'app/helpers/bootstrap_builders/buttons_helper.rb', line 2

def bb_btn(*args)
  args = BootstrapBuilders::Button.parse_url_args(args)
  args[:context] = self
  button = BootstrapBuilders::Button.new(args)
  button.classes.add("bb-btn")
  button.html
end

#bb_btn_drop_down(*args) {|btn_drop_down| ... } ⇒ Object

Yields:

  • (btn_drop_down)


10
11
12
13
14
15
16
# File 'app/helpers/bootstrap_builders/buttons_helper.rb', line 10

def bb_btn_drop_down(*args)
  btn_drop_down = BootstrapBuilders::ButtonDropDown.new(*args)
  btn_drop_down.view_context = self

  yield btn_drop_down
  btn_drop_down.html
end

#bb_destroy_btn(*args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/helpers/bootstrap_builders/buttons_helper.rb', line 31

def bb_destroy_btn(*args)
  args = BootstrapBuilders::Button.parse_url_args(args)
  args[:label] = t("delete") unless args.key?(:label)
  args[:title] ||= t("delete") if args[:mini]

  args[:data] ||= {}
  args[:data][:confirm] ||= t("are_you_sure")

  button = BootstrapBuilders::Button.new(args.merge(icon: "remove", context: self, can_type: :destroy, method: :delete))
  button.classes.remove(["btn-default"])
  button.classes.add(["btn-danger", "bb-btn", "bb-btn-destroy"])
  button.classes.add("bb-btn-destroy-#{button.can_model_class.name.tableize.singularize}") if button.can_model_class
  button.classes.add("bb-btn-destroy-#{button.can_model_class.name.tableize.singularize}-#{button.can_model.id}") if button.can_model
  button.html
end

#bb_edit_btn(*args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/bootstrap_builders/buttons_helper.rb', line 18

def bb_edit_btn(*args)
  args = BootstrapBuilders::Button.parse_url_args(args)
  args[:label] = t("edit") unless args.key?(:label)
  args[:title] ||= t("edit") if args[:mini]
  args[:url] = [:edit, args.fetch(:url)] if args[:url] && !args[:url].is_a?(Array) && BootstrapBuilders::IsAChecker.is_a?(args[:url], "ActiveRecord::Base")

  button = BootstrapBuilders::Button.new(args.merge(icon: "wrench", context: self, can_type: :edit))
  button.classes.add(["bb-btn", "bb-btn-edit"])
  button.classes.add("bb-btn-edit-#{button.can_model_class.name.tableize.singularize}") if button.can_model_class
  button.classes.add("bb-btn-edit-#{button.can_model_class.name.tableize.singularize}-#{button.can_model.id}") if button.can_model
  button.html
end

#bb_index_btn(*args) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/helpers/bootstrap_builders/buttons_helper.rb', line 58

def bb_index_btn(*args)
  args = BootstrapBuilders::Button.parse_url_args(args)
  args[:title] ||= t("index") if args[:mini]

  button = BootstrapBuilders::Button.new(args.merge(icon: "table", context: self, can_type: :index))

  if button.label.to_s.strip.empty?
    if button.can_model_class
      button.label = button.can_model_class.model_name.human(count: 2)
    else
      button.label = t("index")
    end
  end

  button.classes.add(["bb-btn", "bb-btn-index"])
  button.classes.add("bb-btn-index-#{button.can_model_class.name.tableize}") if button.can_model_class
  button.html
end

#bb_new_btn(*args) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'app/helpers/bootstrap_builders/buttons_helper.rb', line 47

def bb_new_btn(*args)
  args = BootstrapBuilders::Button.parse_url_args(args)
  args[:label] = t("add_new") unless args.key?(:label)
  args[:title] ||= t("new") if args[:mini]

  button = BootstrapBuilders::Button.new(args.merge(icon: "plus", context: self, can_type: :new))
  button.classes.add(["bb-btn", "bb-btn-new"])
  button.classes.add("bb-btn-new-#{button.can_model_class.name.tableize.singularize}") if button.can_model_class
  button.html
end

#bb_show_btn(*args) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'app/helpers/bootstrap_builders/buttons_helper.rb', line 77

def bb_show_btn(*args)
  args = BootstrapBuilders::Button.parse_url_args(args)
  args[:label] = t("show") unless args.key?(:label)
  args[:title] ||= t("show") if args[:mini]

  button = BootstrapBuilders::Button.new(args.merge(icon: "square-o", context: self, can_type: :show))
  button.classes.add(["bb-btn", "bb-btn-show"])
  button.classes.add("bb-btn-show-#{button.can_model_class.name.tableize.singularize}") if button.can_model_class
  button.classes.add("bb-btn-show-#{button.can_model_class.name.tableize.singularize}-#{button.can_model.id}") if button.can_model
  button.html
end