Skip to content

Commit 5e38190

Browse files
committed
Rename PageLayout into PageDefinition
Page layout has been the name for the layout partial of a page type (also misleadingly named a layout, but this is a much bigger change). Element definitions and ingredient definitions already exist and the page already has a definition getter method. Let's name the duck as it quacks.
1 parent 35b7527 commit 5e38190

23 files changed

Lines changed: 78 additions & 72 deletions

File tree

app/controllers/alchemy/admin/pages_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class PagesController < ResourcesController
3838
only: [:show]
3939

4040
add_alchemy_filter :by_page_layout, type: :select, options: ->(_q) do
41-
PageLayout.all.map { |p| [Alchemy.t(p[:name], scope: "page_layout_names"), p[:name]] }
41+
PageDefinition.all.map { |p| [Alchemy.t(p[:name], scope: "page_layout_names"), p[:name]] }
4242
end
4343

4444
add_alchemy_filter :updated_at_gteq, type: :datepicker

app/helpers/alchemy/pages_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def language_links(options = {})
4646
def render_page_layout
4747
render @page, page: @page
4848
rescue ActionView::MissingTemplate
49-
warning("PageLayout: '#{@page.page_layout}' not found. Rendering standard page_layout.")
49+
warning("[alchemy]: '#{@page.page_layout}' page layout not found. Rendering 'standard' page layout.")
5050
render "alchemy/page_layouts/standard", page: @page
5151
end
5252

app/models/alchemy/page.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#
3737

3838
require_dependency "alchemy/page/fixed_attributes"
39-
require_dependency "alchemy/page/page_layouts"
39+
require_dependency "alchemy/page/definitions"
4040
require_dependency "alchemy/page/page_scopes"
4141
require_dependency "alchemy/page/page_natures"
4242
require_dependency "alchemy/page/page_naming"
@@ -156,7 +156,7 @@ class Page < BaseRecord
156156
after_update :touch_nodes
157157

158158
# Concerns
159-
include PageLayouts
159+
include Definitions
160160
include PageScopes
161161
include PageNatures
162162
include PageNaming
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ module Alchemy
44
class Page < BaseRecord
55
# Module concerning page layouts
66
#
7-
module PageLayouts
7+
module Definitions
88
extend ActiveSupport::Concern
99

1010
module ClassMethods
1111
# Register a custom page layouts repository
1212
#
13-
# The default repository is Alchemy::PageLayout
13+
# The default repository is Alchemy::PageDefinition
1414
#
1515
def layouts_repository=(klass)
1616
@_layouts_repository = klass
@@ -64,7 +64,7 @@ def human_layout_name(layout)
6464
private
6565

6666
def layouts_repository
67-
@_layouts_repository ||= PageLayout
67+
@_layouts_repository ||= PageDefinition
6868
end
6969

7070
# Returns true if the given layout is unique and not already taken or it should be hidden.

app/models/alchemy/page/page_natures.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ def status_title(status_type)
8080

8181
# Returns the self#page_layout definition from config/alchemy/page_layouts.yml file.
8282
def definition
83-
definition = PageLayout.get(page_layout)
83+
definition = PageDefinition.get(page_layout)
8484
if definition.nil?
8585
log_warning "Page definition for `#{page_layout}` not found. Please check `page_layouts.yml` file."
86-
return PageLayout.new(name: page_layout)
86+
return PageDefinition.new(name: page_layout)
8787
end
8888
definition
8989
end
@@ -146,7 +146,7 @@ def last_modified_at
146146
def cache_page?
147147
return false unless caching_enabled?
148148

149-
page_layout = PageLayout.get(self.page_layout)
149+
page_layout = PageDefinition.get(self.page_layout)
150150
page_layout.cache != false && page_layout.searchresults != true
151151
end
152152

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
module Alchemy
4-
class PageLayout
4+
class PageDefinition
55
include ActiveModel::Model
66
include ActiveModel::Attributes
77

@@ -49,7 +49,7 @@ def map(...)
4949
#
5050
# === Usage Example
5151
#
52-
# Call +Alchemy::PageLayout.add(your_definition)+ in your engine.rb file.
52+
# Call +Alchemy::PageDefinition.add(your_definition)+ in your engine.rb file.
5353
#
5454
# @param [Array || Hash]
5555
# You can pass a single layout definition as Hash, or a collection of page layouts as Array.

app/models/alchemy/site/layout.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ def page_layout_names(layoutpages: false)
5151
#
5252
def page_layout_definitions
5353
if definition["page_layouts"].presence
54-
Alchemy::PageLayout.all.select do |layout|
54+
Alchemy::PageDefinition.all.select do |layout|
5555
layout.name.in?(definition["page_layouts"])
5656
end
5757
else
58-
Alchemy::PageLayout.all
58+
Alchemy::PageDefinition.all
5959
end
6060
end
6161

app/views/alchemy/admin/languages/_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<% end %>
1313
<%= f.input :frontpage_name %>
1414
<%= f.input :page_layout,
15-
collection: Alchemy::PageLayout.all,
15+
collection: Alchemy::PageDefinition.all,
1616
label_method: ->(p) { Alchemy::Page.human_layout_name(p['name']) },
1717
value_method: ->(p) { p['name'] },
1818
input_html: {is: 'alchemy-select'} %>

config/alchemy/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ auto_logout_time: 30
1313
#
1414
# Enable/Disable page caching globally.
1515
#
16-
# NOTE: You can enable/disable page caching for single Alchemy::PageLayouts in the page_layout.yml file.
16+
# NOTE: You can enable/disable page caching for single Alchemy::Definitions in the page_layout.yml file.
1717
#
1818
cache_pages: true
1919

@@ -110,7 +110,7 @@ default_language:
110110
#
111111
# ==== Options:
112112
#
113-
# page_layout_name: [String] # A +Alchemy::PageLayout+ name. Used to render the contactform on a page with this layout.
113+
# page_layout_name: [String] # A +Alchemy::PageDefinition+ name. Used to render the contactform on a page with this layout.
114114
# fields: [Array] # An Array of fieldnames.
115115
# validate_fields: [Array] # An Array of fieldnames to be validated on presence.
116116
#

lib/alchemy/cache_digests/template_tracker.rb

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@ def initialize(name, template)
1414
def dependencies
1515
case @name.to_s
1616
when /^alchemy\/pages\/show/
17-
PageLayout.all.map { |p| "alchemy/page_layouts/_#{p["name"]}" }
17+
PageDefinition.all.map { "alchemy/page_layouts/_#{_1.name}" }
1818
when /^alchemy\/page_layouts\/_(\w+)/
19-
page_layout = PageLayout.get($1)
20-
layout_elements = page_layout.fetch("elements", [])
21-
layout_elements.map { |name| "alchemy/elements/_#{name}" }
19+
page_definition = PageDefinition.get($1)
20+
page_definition.elements.map { "alchemy/elements/_#{_1}" }
2221
when /^alchemy\/elements\/_(\w+)/
23-
ingredient_types($1).map { |type|
24-
"alchemy/ingredients/_#{type.underscore}_view"
25-
}.uniq
22+
ingredient_types($1).map { "alchemy/ingredients/_#{_1.underscore}_view" }.tap(&:uniq!)
2623
else
2724
ActionView::DependencyTracker::ERBTracker.call(@name, @template)
2825
end
@@ -31,10 +28,10 @@ def dependencies
3128
private
3229

3330
def ingredient_types(name)
34-
element = Element.definitions.detect { |e| e["name"] == name }
31+
element = Element.definitions.detect { _1["name"] == name }
3532
return [] unless element
3633

37-
element.fetch("ingredients", []).collect { |c| c["type"] }
34+
element.fetch("ingredients", []).map { _1["type"] }
3835
end
3936
end
4037
end

0 commit comments

Comments
 (0)