Skip to content

Commit

Permalink
Allow to set a custom Page::UrlPath class
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdeyen committed Aug 7, 2020
1 parent 9ece5d4 commit ba62872
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
17 changes: 16 additions & 1 deletion app/models/alchemy/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ class Page < BaseRecord
# Class methods
#
class << self
# The url_path class
# @see Alchemy::Page::UrlPath
def url_path_class
@_url_path_class ||= Alchemy::Page::UrlPath
end

# Set a custom url path class
#
# # config/initializers/alchemy.rb
# Alchemy::Page.url_path_class = MyPageUrlPathClass
#
def url_path_class=(klass)
@_url_path_class = klass
end

# Used to store the current page previewed in the edit page template.
#
def current_preview=(page)
Expand Down Expand Up @@ -298,7 +313,7 @@ def find_elements(options = {})
#
# @see Alchemy::Page::UrlPath#call
def url_path
Alchemy::Page::UrlPath.new(self).call
self.class.url_path_class.new(self).call
end

# The page's view partial is dependent from its page layout
Expand Down
18 changes: 18 additions & 0 deletions spec/models/alchemy/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,24 @@ module Alchemy

# ClassMethods (a-z)

describe ".url_path_class" do
subject { described_class.url_path_class }

it { is_expected.to eq(Alchemy::Page::UrlPath) }

context "if set to another url path class" do
class AnotherUrlPathClass; end

before do
described_class.url_path_class = AnotherUrlPathClass
end

it { is_expected.to eq(AnotherUrlPathClass) }

after { described_class.instance_variable_set(:@_url_path_class, nil) }
end
end

describe ".all_from_clipboard_for_select" do
context "with clipboard holding pages having non unique page layout" do
it "should return the pages" do
Expand Down

0 comments on commit ba62872

Please sign in to comment.