Skip to content

Commit

Permalink
Improve clarity around deprecated options (dialog vs modal)
Browse files Browse the repository at this point in the history
  • Loading branch information
spohlenz committed Sep 22, 2023
1 parent d485197 commit e55df3f
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/controllers/concerns/trestle/controller/modal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def modal_request?
end

def dialog_request?
ActiveSupport::Deprecation.warn("The #dialog_request? helper has been renamed to #modal_request?")
Trestle.deprecator.warn("The #dialog_request? helper has been renamed to #modal_request?")
modal_request?
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/trestle/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Configuration

def theme=(colors)
if [true, false].include?(colors)
ActiveSupport::Deprecation.warn("Passing a boolean to config.theme is deprecated. Please pass primary and secondary theme colors as a hash.")
Trestle.deprecator.warn("Passing a boolean to config.theme is deprecated. Please pass primary and secondary theme colors as a hash.")
else
original = fetch(:colors) || {}
colors = colors.transform_values { |color| Trestle::Color.parse(color) }
Expand Down
12 changes: 9 additions & 3 deletions lib/trestle/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@ def initialize(options={}, &block)
if @options[:modal] == true
@options[:modal] = {}
end

if options[:dialog]
Trestle.deprecator.warn("`form dialog: true` is deprecated. Please use `form modal: true` instead.")
@options.delete(:dialog)
@options[:modal] = {}
end
end

def modal?
options[:modal] || options[:dialog] == true
options[:modal]
end

def dialog?
ActiveSupport::Deprecation.warn("`Trestle::Form#dialog?` is deprecated. Please use `modal?` instead.")
options[:dialog] == true
Trestle.deprecator.warn("`Trestle::Form#dialog?` is deprecated. Please use `modal?` instead.")
options[:modal]
end

def render(template, instance)
Expand Down
2 changes: 1 addition & 1 deletion sandbox/app/admin/categories_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
actions
end

form dialog: true do
form modal: true do
text_field :name
color_field :color
end
Expand Down
2 changes: 1 addition & 1 deletion sandbox/app/admin/offices_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
actions
end

form dialog: true do
form modal: true do
row do
col { text_field :city }
col { text_field :country }
Expand Down
4 changes: 1 addition & 3 deletions spec/dummy/app/admin/modal_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
actions
end

form modal: true do |post|
modal_options!(class: "modal-lg")

form modal: { class: "modal-lg" } do |post|
text_field :title
text_area :body
end
Expand Down
4 changes: 2 additions & 2 deletions spec/trestle/admin/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ module TestHelper; end
context "without a block" do
it "builds an automatic form using the given options" do
Trestle::Admin::Builder.create(:test) do
form dialog: true
form modal: true
end

expect(::TestAdmin.form).to be_a(Trestle::Form::Automatic)
expect(::TestAdmin.form.options).to eq(dialog: true)
expect(::TestAdmin.form.options).to eq(modal: {})
end
end
end
Expand Down
9 changes: 7 additions & 2 deletions spec/trestle/form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Trestle::Form do
subject(:form) { Trestle::Form.new }

context "without options[:dialog]" do
context "without options[:modal]" do
it { is_expected.to_not be_modal }
end

Expand All @@ -12,8 +12,13 @@
it { is_expected.to be_modal }
end

context "with options[:dialog]" do
context "with options[:dialog] (deprecated)" do
before(:each) do
expect(Trestle.deprecator).to receive(:warn)
end

subject(:form) { Trestle::Form.new(dialog: true) }

it { is_expected.to be_modal }
end
end

0 comments on commit e55df3f

Please sign in to comment.