Skip to content

Commit

Permalink
Deprecate Alchemy.enable_searchable
Browse files Browse the repository at this point in the history
Instead, use the `Alchemy.config.page_searchable_checkbox` Boolean.
  • Loading branch information
mamhoff committed Feb 10, 2025
1 parent 3af20de commit 4f69f7c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
22 changes: 9 additions & 13 deletions lib/alchemy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,6 @@ module Alchemy

YAML_PERMITTED_CLASSES = %w[Symbol Date Regexp]

# Enable full text search configuration
#
# It enables a searchable checkbox in the page form to toggle
# the searchable field. These information can used in a search
# plugin (e.g. https://github.com/AlchemyCMS/alchemy-pg_search).
#
# == Example
#
# # config/initializers/alchemy.rb
# Alchemy.enable_searchable = true
#
mattr_accessor :enable_searchable, default: false

# JS Importmap instance
singleton_class.attr_accessor :importmap
self.importmap = Importmap::Map.new
Expand All @@ -37,6 +24,15 @@ def configure(&blk)
yield config
end

enable_searchable_deprecation_msg = "Use `Alchemy.config.show_page_searchable_checkbox` instead."
def enable_searchable = config.show_page_searchable_checkbox
deprecate :enable_searchable= => enable_searchable_deprecation_msg, :deprecator => Alchemy::Deprecation

def enable_searchable=(other)
config.show_page_searchable_checkbox = other
end
deprecate enable_searchable: enable_searchable_deprecation_msg, deprecator: Alchemy::Deprecation

# Define page preview sources
#
# A preview source is a Ruby class returning an URL
Expand Down
12 changes: 12 additions & 0 deletions lib/alchemy/configurations/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,18 @@ class Main < Alchemy::Configuration

# The sizes for the preview size select in the page editor.
option :page_preview_sizes, :integer_list, default: [360, 640, 768, 1024, 1280, 1440]

# Enable full text search configuration
#
# It enables a searchable checkbox in the page form to toggle
# the searchable field. These information can used in a search
# plugin (e.g. https://github.com/AlchemyCMS/alchemy-pg_search).
#
# == Example
#
# # config/initializers/alchemy.rb
# Alchemy.config.page_searchable_checkbox = true
option :show_page_searchable_checkbox, :boolean, default: false
end
end
end
9 changes: 9 additions & 0 deletions spec/libraries/alchemy/configurations/main_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@
end.to change { subject.output_image_quality }.from(85).to(90)
end
end

describe "default values" do
let(:configuration) { described_class.new }

describe "#page_searchable_checkbox" do
subject { configuration.show_page_searchable_checkbox }
it { is_expected.to be false }
end
end
end
17 changes: 17 additions & 0 deletions spec/libraries/alchemy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,21 @@
expect(Alchemy::Config).to eq(Alchemy.config)
end
end

describe "legacy configuration methods" do
around do |example|
Alchemy::Deprecation.silence { example.run }
end
describe ".enable_searchable" do
it "forwards to config.page_searchable_checkbox" do
expect do
Alchemy.enable_searchable = true
end.to change(Alchemy.config, :show_page_searchable_checkbox).to(true)
# Reset
expect do
Alchemy.enable_searchable = false
end.to change(Alchemy, :enable_searchable).to(false)
end
end
end
end

0 comments on commit 4f69f7c

Please sign in to comment.