Skip to content

Commit 3291598

Browse files
committed
Add wildcard_url to page definition
Add a new attribute to page definition to allow the usage of wildcard_urls (e.g. :user_id/profile). They can have different configurations (simple string or a hash structure). Add also more page layouts to the dummy to test the different configuration later.
1 parent a320457 commit 3291598

5 files changed

Lines changed: 47 additions & 3 deletions

File tree

app/models/alchemy/page_definition.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class PageDefinition
2020
attribute :hide, :boolean, default: false
2121
attribute :editable_by
2222
attribute :hint
23+
attribute :wildcard_url, Alchemy::WildcardUrlType.new
2324

2425
# Needs to be down here in order to have the attribute reader
2526
# available after the attribute is defined.

spec/dummy/config/alchemy/page_layouts.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,37 @@
5959
- menu
6060
layoutpage: true
6161

62+
- name: product_detail
63+
wildcard_url:
64+
pattern: ":id"
65+
params: integer
66+
elements: [article]
67+
68+
- name: user_profile
69+
wildcard_url:
70+
pattern: ":uuid/profile"
71+
params:
72+
uuid: "uuid"
73+
elements: [article]
74+
75+
- name: blog_post
76+
wildcard_url:
77+
pattern: ":year/:slug"
78+
params:
79+
year: "integer"
80+
slug: "string"
81+
elements: [article]
82+
83+
- name: product_by_slug
84+
wildcard_url: ":slug"
85+
elements: [article]
86+
87+
- name: product_by_sku
88+
wildcard_url:
89+
pattern: ":sku"
90+
params:
91+
sku: !ruby/regexp /\A[A-Z]{2}-\d{4}\z/
92+
elements: [article]
93+
6294
- name: <%= 'erb_' + 'layout' %>
6395
unique: true

spec/libraries/alchemy/tasks/usage_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,18 @@
5555
{"page_layout" => "standard", "count" => 2},
5656
{"page_layout" => "home", "count" => 1},
5757
{"page_layout" => "index", "count" => 1},
58+
{"page_layout" => "blog_post", "count" => 0},
5859
{"page_layout" => "contact", "count" => 0},
5960
{"page_layout" => "erb_layout", "count" => 0},
6061
{"page_layout" => "everything", "count" => 0},
6162
{"page_layout" => "footer", "count" => 0},
6263
{"page_layout" => "news", "count" => 0},
64+
{"page_layout" => "product_by_sku", "count" => 0},
65+
{"page_layout" => "product_by_slug", "count" => 0},
66+
{"page_layout" => "product_detail", "count" => 0},
6367
{"page_layout" => "readonly", "count" => 0},
64-
{"page_layout" => "search", "count" => 0}
68+
{"page_layout" => "search", "count" => 0},
69+
{"page_layout" => "user_profile", "count" => 0}
6570
]
6671
end
6772
end

spec/models/alchemy/page_definition_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module Alchemy
2020
it { is_expected.to have_key(:hide) }
2121
it { is_expected.to have_key(:editable_by) }
2222
it { is_expected.to have_key(:hint) }
23+
it { is_expected.to have_key(:wildcard_url) }
2324
end
2425

2526
describe "#blank?" do

spec/models/alchemy/site_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ module Alchemy
170170

171171
it "returns all non 'layoutpage' page layout names" do
172172
allow(Site).to receive(:definitions).and_return([])
173-
expect(site.page_layout_names).to eq(%w[index readonly standard everything news search contact erb_layout])
173+
expect(site.page_layout_names).to eq(%w[index readonly standard everything news search contact product_detail user_profile blog_post product_by_slug product_by_sku erb_layout])
174174
end
175175

176176
context "when layoutpages are requested" do
@@ -211,7 +211,12 @@ module Alchemy
211211
"contact",
212212
"footer",
213213
"erb_layout",
214-
"search"
214+
"search",
215+
"product_detail",
216+
"user_profile",
217+
"blog_post",
218+
"product_by_slug",
219+
"product_by_sku"
215220
])
216221
end
217222
end

0 commit comments

Comments
 (0)