diff --git a/app/helpers/bootstrap_builders/application_helper.rb b/app/helpers/bootstrap_builders/application_helper.rb index 8b7c8c4..ac76e1a 100644 --- a/app/helpers/bootstrap_builders/application_helper.rb +++ b/app/helpers/bootstrap_builders/application_helper.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/lib/bootstrap_builders/configuration.rb b/lib/bootstrap_builders/configuration.rb index aa8ddbb..fa08e54 100644 --- a/lib/bootstrap_builders/configuration.rb +++ b/lib/bootstrap_builders/configuration.rb @@ -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 diff --git a/spec/features/bootstrap_builders/button_spec.rb b/spec/features/bootstrap_builders/button_spec.rb index 30e28f8..f866876 100644 --- a/spec/features/bootstrap_builders/button_spec.rb +++ b/spec/features/bootstrap_builders/button_spec.rb @@ -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