Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions app/helpers/bootstrap_builders/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def bb_edit_btn(*args)
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 = BootstrapBuilders::Button.new(args.merge(icon: BootstrapBuilders.configuration.btn_edit_icon, 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
Expand All @@ -42,7 +42,14 @@ def bb_destroy_btn(*args)
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 = BootstrapBuilders::Button.new(
args.merge(
icon: BootstrapBuilders.configuration.btn_destroy_icon,
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
Expand All @@ -55,7 +62,7 @@ def bb_new_btn(*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 = BootstrapBuilders::Button.new(args.merge(icon: BootstrapBuilders.configuration.btn_new_icon, 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
Expand All @@ -65,7 +72,7 @@ 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))
button = BootstrapBuilders::Button.new(args.merge(icon: BootstrapBuilders.configuration.btn_index_icon, context: self, can_type: :index))

if button.label.to_s.strip.empty?
if button.can_model_class
Expand All @@ -85,7 +92,7 @@ def bb_show_btn(*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 = BootstrapBuilders::Button.new(args.merge(icon: BootstrapBuilders.configuration.btn_show_icon, 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
Expand Down
8 changes: 7 additions & 1 deletion lib/bootstrap_builders/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
class BootstrapBuilders::Configuration
attr_accessor :default_table_classes
attr_accessor :default_table_classes, :btn_index_icon, :btn_show_icon, :btn_new_icon, :btn_edit_icon, :btn_destroy_icon

def initialize
@default_table_classes = [:bordered, :hover, :striped]

@btn_index_icon = :table
@btn_show_icon = :"square-o"
@btn_new_icon = :plus
@btn_edit_icon = :wrench
@btn_destroy_icon = :remove
end
end
130 changes: 93 additions & 37 deletions spec/features/bootstrap_builders/button_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,49 +23,105 @@
expect(button.text).to eq ""
end

it "#bb_destroy_btn" do
visit destroy_btn_bootstrap_builders_buttons_path(user_id: user.id)

button = find(".bb-btn-destroy")
expect(button[:href]).to eq "/test/destroy"
expect(button.text).to eq "Delete"
expect(button[:class]).not_to include "btn-default"

icon = find(".bb-btn-destroy i")
expect(icon[:class]).to eq "fa fa-remove"
describe "#bb_destroy_btn" do
it "renders with the correct data" do
visit destroy_btn_bootstrap_builders_buttons_path(user_id: user.id)

button = find(".bb-btn-destroy")
expect(button[:href]).to eq "/test/destroy"
expect(button.text).to eq "Delete"
expect(button[:class]).not_to include "btn-default"

icon = find(".bb-btn-destroy i")
expect(icon[:class]).to eq "fa fa-remove"
end

it "is possible to change the icon through the configuration" do
begin
BootstrapBuilders.configuration.btn_destroy_icon = :pencil
visit destroy_btn_bootstrap_builders_buttons_path(user_id: user.id)

icon = find(".bb-btn-destroy-user i")
expect(icon[:class]).to eq "fa fa-pencil"
ensure
BootstrapBuilders.configuration.btn_destroy_icon = :remove
end
end
end

it "#bb_edit_btn" do
visit edit_btn_bootstrap_builders_buttons_path(user_id: user.id)

button = find(".bb-btn-edit")
expect(button[:href]).to eq "/test/edit"
expect(button.text).to eq "Edit"

icon = find(".bb-btn-edit i")
expect(icon[:class]).to eq "fa fa-wrench"
describe "#bb_edit_btn" do
it "renders with the correct data" do
visit edit_btn_bootstrap_builders_buttons_path(user_id: user.id)

button = find(".bb-btn-edit")
expect(button[:href]).to eq "/test/edit"
expect(button.text).to eq "Edit"

icon = find(".bb-btn-edit i")
expect(icon[:class]).to eq "fa fa-wrench"
end

it "is possible to change the icon through the configuration" do
begin
BootstrapBuilders.configuration.btn_edit_icon = :pencil
visit edit_btn_bootstrap_builders_buttons_path(user_id: user.id)

icon = find(".bb-btn-edit-user i")
expect(icon[:class]).to eq "fa fa-pencil"
ensure
BootstrapBuilders.configuration.btn_edit_icon = :wrench
end
end
end

it "#bb_new_btn" do
visit new_btn_bootstrap_builders_buttons_path

button = find(".bb-btn-new-user")
expect(button[:href]).to eq "/test/new"
expect(button.text).to eq "Add new"

icon = find(".bb-btn-new-user i")
expect(icon[:class]).to eq "fa fa-plus"
describe "#bb_new_btn" do
it "renders with the correct data" do
visit new_btn_bootstrap_builders_buttons_path

button = find(".bb-btn-new-user")
expect(button[:href]).to eq "/test/new"
expect(button.text).to eq "Add new"

icon = find(".bb-btn-new-user i")
expect(icon[:class]).to eq "fa fa-plus"
end

it "is possible to change the icon through the configuration" do
begin
BootstrapBuilders.configuration.btn_new_icon = :pencil
visit new_btn_bootstrap_builders_buttons_path

icon = find(".bb-btn-new-user i")
expect(icon[:class]).to eq "fa fa-pencil"
ensure
BootstrapBuilders.configuration.btn_new_icon = :plus
end
end
end

it "#bb_show_btn" do
visit show_btn_bootstrap_builders_buttons_path(user_id: user.id)

button = find(".bb-btn-show-user")
expect(button[:href]).to eq "/test/show"
expect(button.text).to eq "Show"

icon = find(".bb-btn-show-user i")
expect(icon[:class]).to eq "fa fa-square-o"
describe "#bb_show_btn" do
it "renders with the correct data" do
visit show_btn_bootstrap_builders_buttons_path(user_id: user.id)

button = find(".bb-btn-show-user")
expect(button[:href]).to eq "/test/show"
expect(button.text).to eq "Show"

icon = find(".bb-btn-show-user i")
expect(icon[:class]).to eq "fa fa-square-o"
end

it "is possible to change the icon through the configuration" do
begin
BootstrapBuilders.configuration.btn_show_icon = :pencil
visit show_btn_bootstrap_builders_buttons_path(user_id: user.id)

icon = find(".bb-btn-show-user i")
expect(icon[:class]).to eq "fa fa-pencil"
ensure
BootstrapBuilders.configuration.btn_show_icon = :"square-o"
end
end
end

it "forwards the target argument" do
Expand Down