refinerycms-pages 4.0.2 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/app/controllers/refinery/admin/page_parts_controller.rb +2 -1
- data/app/controllers/refinery/admin/pages_controller.rb +12 -11
- data/app/controllers/refinery/admin/pages_dialogs_controller.rb +8 -8
- data/app/controllers/refinery/pages/admin/preview_controller.rb +7 -0
- data/app/controllers/refinery/pages_controller.rb +4 -1
- data/app/helpers/refinery/admin/pages_helper.rb +29 -7
- data/app/models/refinery/page.rb +39 -51
- data/app/models/refinery/page_part.rb +12 -6
- data/app/presenters/refinery/pages/menu_presenter.rb +2 -2
- data/app/views/refinery/admin/pages/_form.html.erb +10 -10
- data/app/views/refinery/admin/pages/_page.html.erb +17 -45
- data/app/views/refinery/admin/pages/_sortable_list.html.erb +1 -1
- data/app/views/refinery/admin/pages/children.html.erb +1 -1
- data/app/views/refinery/admin/pages_dialogs/_page_link.html.erb +1 -1
- data/app/views/refinery/admin/pages_dialogs/link_to.html.erb +28 -21
- data/config/locales/en.yml +3 -3
- data/config/locales/sk.yml +4 -2
- data/db/migrate/20100913234708_create_refinerycms_pages_schema.rb +27 -30
- data/db/seeds.rb +1 -1
- data/lib/generators/refinery/pages/pages_generator.rb +1 -1
- data/lib/generators/refinery/pages/templates/config/initializers/refinery/pages.rb.erb +10 -3
- data/lib/refinery/pages/configuration.rb +8 -5
- data/lib/refinery/pages/engine.rb +2 -1
- data/lib/refinery/pages/finder.rb +95 -96
- data/lib/refinery/pages/instance_methods.rb +6 -4
- data/lib/refinery/pages.rb +3 -3
- data/lib/refinerycms/pages.rb +1 -0
- data/refinerycms-pages.gemspec +16 -22
- data/spec/controllers/refinery/pages_controller_spec.rb +23 -6
- data/spec/factories/page_parts.rb +2 -2
- data/spec/helpers/refinery/pages/admin/pages_helper_spec.rb +8 -18
- data/spec/models/refinery/page_menu_spec.rb +2 -2
- data/spec/models/refinery/page_url_spec.rb +4 -4
- data/spec/support/refinery/pages/caching_helpers.rb +1 -1
- data/spec/support/selector_helpers.rb +43 -0
- data/spec/{features → system}/refinery/admin/pages_spec.rb +164 -155
- data/spec/{features → system}/refinery/pages_spec.rb +10 -10
- metadata +48 -102
- checksums.yaml.gz.sig +0 -3
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -2
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
<input type="radio" name="link_to" value="email_address" id="link_to_email_address" <%= 'checked="true"'.html_safe if @email_address_area_selected %> />
|
|
14
14
|
<label for="link_to_email_address" class="stripped"><%= t('tab_name', :scope => 'refinery.admin.pages_dialogs.link_to.email_address') %></label>
|
|
15
15
|
</span>
|
|
16
|
-
<% if ::Refinery::Plugins.registered.names.include?("refinery_files")
|
|
16
|
+
<% if ::Refinery::Plugins.registered.names.include?("refinery_files") && (@resources.any? || searching?) %>
|
|
17
17
|
<span id="resource_file_radio" class="radio<%= ' selected_radio' if @resource_area_selected %>">
|
|
18
18
|
<input type="radio" name="link_to" value="resource_file" id="link_to_resource_file" <%= 'checked="true"'.html_safe if @resource_area_selected %> />
|
|
19
19
|
<label for="link_to_resource_file" class="stripped"><%= t('tab_name', :scope => 'refinery.admin.pages_dialogs.link_to.your_resource') %></label>
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
<div id="your_page_content" class="clearfix">
|
|
28
28
|
<div id="pages_list" class="pages_list">
|
|
29
29
|
<ul class="link_list">
|
|
30
|
-
<%= render :
|
|
31
|
-
:
|
|
32
|
-
:
|
|
33
|
-
:
|
|
30
|
+
<%= render partial: '/refinery/admin/pages_dialogs/page_link', collection: @pages, cached: true,
|
|
31
|
+
locals: {
|
|
32
|
+
child: 0,
|
|
33
|
+
link_to_arguments: {}
|
|
34
34
|
} %>
|
|
35
35
|
</ul>
|
|
36
36
|
<%= will_paginate @pages, :id => 'pages_paginate' %>
|
|
@@ -86,24 +86,31 @@
|
|
|
86
86
|
</ol>
|
|
87
87
|
</div>
|
|
88
88
|
</div>
|
|
89
|
-
<% if ::Refinery::Plugins.registered.names.include?("refinery_files")
|
|
89
|
+
<% if ::Refinery::Plugins.registered.names.include?("refinery_files") && (@resources.any? || searching?) %>
|
|
90
90
|
<div id="resource_file_area"<%= ' style="display:none"'.html_safe unless @resource_area_selected %> class="dialog_area">
|
|
91
|
+
<%= render '/refinery/admin/search', url: refinery.insert_admin_resources_path(params.to_unsafe_h.dup.except('resource')) %>
|
|
92
|
+
|
|
91
93
|
<div id="resources_list" class="pages_list">
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
<%
|
|
95
|
-
|
|
96
|
-
<%=
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
94
|
+
<% if @resources.any? %>
|
|
95
|
+
<ul class="link_list">
|
|
96
|
+
<% @resources.each do |resource| -%>
|
|
97
|
+
<% resource_linked = (resource.url == params[:current_link]) unless params[:current_link].blank? %>
|
|
98
|
+
<li<%= ' class="linked"'.html_safe if resource_linked %>>
|
|
99
|
+
<%= link_to "#{resource.title}.#{resource.ext}", path_to_asset(resource.url),
|
|
100
|
+
:title => t('link_to_this_resource', :scope => 'refinery.admin.pages_dialogs.link_to.your_resource'),
|
|
101
|
+
:rel => resource.title,
|
|
102
|
+
:class => "page_link #{resource.ext}" %>
|
|
103
|
+
</li>
|
|
104
|
+
<% end %>
|
|
105
|
+
</ul>
|
|
106
|
+
|
|
107
|
+
<%= will_paginate @resources,
|
|
108
|
+
:param_name => :resource_page,
|
|
109
|
+
:params => {:paginating => "resource_file"},
|
|
110
|
+
:id => 'resouces_paginate' %>
|
|
111
|
+
<% elsif searching? %>
|
|
112
|
+
<%= t('no_results', :scope => 'refinery.admin.search') %>
|
|
113
|
+
<% end %>
|
|
107
114
|
</div>
|
|
108
115
|
</div>
|
|
109
116
|
<% end %>
|
data/config/locales/en.yml
CHANGED
|
@@ -32,15 +32,15 @@ en:
|
|
|
32
32
|
tab_name: Your file
|
|
33
33
|
link_to_this_resource: Link to this file
|
|
34
34
|
pages:
|
|
35
|
-
delete: Remove this page forever
|
|
36
|
-
edit: Edit this page
|
|
37
|
-
new: Add a new child page
|
|
38
35
|
expand_collapse: Expand or collapse sub pages
|
|
39
36
|
page:
|
|
40
37
|
draft: draft
|
|
41
38
|
hidden: hidden
|
|
42
39
|
redirected: Redirected
|
|
43
40
|
skip_to_first_child: Skip to first child
|
|
41
|
+
delete: Remove this page forever
|
|
42
|
+
edit: Edit this page
|
|
43
|
+
new: Add a new child page
|
|
44
44
|
view_live_html: View this page live <br/><em>(opens in a new window)</em>
|
|
45
45
|
form:
|
|
46
46
|
preview: Preview
|
data/config/locales/sk.yml
CHANGED
|
@@ -37,9 +37,11 @@ sk:
|
|
|
37
37
|
new: Pridať novú podstránku
|
|
38
38
|
expand_collapse: Rozbaliť alebo zbaliť podstránky
|
|
39
39
|
page:
|
|
40
|
-
view_live_html: Zobraziť stránku <br/><em>(otvorí sa v novom okne)</em>
|
|
41
|
-
hidden: skrytá
|
|
42
40
|
draft: pracovná verzia
|
|
41
|
+
hidden: skrytá
|
|
42
|
+
redirected: Presmerovanie
|
|
43
|
+
skip_to_first_child: Presmerovať na prvú substránku
|
|
44
|
+
view_live_html: Zobraziť stránku <br/><em>(otvorí sa v novom okne)</em>
|
|
43
45
|
form:
|
|
44
46
|
preview: Náhľad
|
|
45
47
|
preview_changes: Zobraziť náhľad s vykonanými zmenami
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
class CreateRefinerycmsPagesSchema < ActiveRecord::Migration[4.2]
|
|
2
|
-
def
|
|
2
|
+
def change
|
|
3
3
|
create_table :refinery_page_parts do |t|
|
|
4
4
|
t.integer :refinery_page_id
|
|
5
5
|
t.string :title
|
|
@@ -38,38 +38,35 @@ class CreateRefinerycmsPagesSchema < ActiveRecord::Migration[4.2]
|
|
|
38
38
|
add_index :refinery_pages, :parent_id
|
|
39
39
|
add_index :refinery_pages, :rgt
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
::Refinery::PagePart.create_translation_table!({
|
|
43
|
-
:body => :text
|
|
44
|
-
})
|
|
45
|
-
rescue NameError
|
|
46
|
-
warn "Refinery::PagePart was not defined!"
|
|
47
|
-
end
|
|
41
|
+
create_table :refinery_page_part_translations do |t|
|
|
48
42
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
:title => :string,
|
|
52
|
-
:custom_slug => :string,
|
|
53
|
-
:menu_title => :string,
|
|
54
|
-
:slug => :string
|
|
55
|
-
})
|
|
56
|
-
rescue NameError
|
|
57
|
-
warn "Refinery::Page was not defined!"
|
|
58
|
-
end
|
|
59
|
-
end
|
|
43
|
+
# Translated attribute(s)
|
|
44
|
+
t.text :body
|
|
60
45
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
::Refinery::PagePart.drop_translation_table!
|
|
66
|
-
rescue NameError
|
|
67
|
-
warn "Refinery::PagePart was not defined!"
|
|
46
|
+
t.string :locale, null: false
|
|
47
|
+
t.integer :refinery_page_part_id, null: false
|
|
48
|
+
|
|
49
|
+
t.timestamps null: false
|
|
68
50
|
end
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
51
|
+
|
|
52
|
+
add_index :refinery_page_part_translations, :locale, name: :index_refinery_page_part_translations_on_locale
|
|
53
|
+
add_index :refinery_page_part_translations, [:refinery_page_part_id, :locale], name: :index_93b7363baf444ecab114aab0bbdedc79d0ec4f4b, unique: true
|
|
54
|
+
|
|
55
|
+
create_table :refinery_page_translations do |t|
|
|
56
|
+
|
|
57
|
+
# Translated attribute(s)
|
|
58
|
+
t.string :title
|
|
59
|
+
t.string :custom_slug
|
|
60
|
+
t.string :menu_title
|
|
61
|
+
t.string :slug
|
|
62
|
+
|
|
63
|
+
t.string :locale, null: false
|
|
64
|
+
t.integer :refinery_page_id, null: false
|
|
65
|
+
|
|
66
|
+
t.timestamps null: false
|
|
73
67
|
end
|
|
68
|
+
|
|
69
|
+
add_index :refinery_page_translations, :locale, name: :index_refinery_page_translations_on_locale
|
|
70
|
+
add_index :refinery_page_translations, [:refinery_page_id, :locale], name: :index_refinery_page_t10s_on_refinery_page_id_and_locale, unique: true
|
|
74
71
|
end
|
|
75
72
|
end
|
data/db/seeds.rb
CHANGED
|
@@ -15,7 +15,7 @@ module Refinery
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def append_load_seed_data
|
|
18
|
-
create_file "db/seeds.rb" unless File.
|
|
18
|
+
create_file "db/seeds.rb" unless File.exist?(File.join(destination_root, 'db', 'seeds.rb'))
|
|
19
19
|
append_file 'db/seeds.rb', :verbose => true do
|
|
20
20
|
<<-EOH
|
|
21
21
|
|
|
@@ -18,6 +18,9 @@ Refinery::Pages.configure do |config|
|
|
|
18
18
|
# This only applies when marketable_urls is enabled.
|
|
19
19
|
# config.friendly_id_reserved_words = <%= Refinery::Pages.friendly_id_reserved_words.inspect %>
|
|
20
20
|
|
|
21
|
+
# You can specify reserved paths that won't interfere with others routes like ActiveStorage route
|
|
22
|
+
# config.reserved_paths = <%= Refinery::Pages.reserved_paths.inspect %>
|
|
23
|
+
|
|
21
24
|
# Configure how many pages per page should be displayed when a dialog is presented that contains a links to pages
|
|
22
25
|
# config.pages_per_dialog = <%= Refinery::Pages.pages_per_dialog.inspect %>
|
|
23
26
|
|
|
@@ -67,12 +70,16 @@ Refinery::Pages.configure do |config|
|
|
|
67
70
|
# config.show_title_in_body = <%= Refinery::Pages.show_title_in_body.inspect %>
|
|
68
71
|
|
|
69
72
|
# You can add new HTML elements not already supported by Loofah::HTML5::WhiteList::ALLOWED_ELEMENTS
|
|
70
|
-
# For more information on whitelist see ALLOWED_ELEMENTS
|
|
73
|
+
# For more information on whitelist see ALLOWED_ELEMENTS
|
|
71
74
|
# (https://github.com/flavorjones/loofah/blob/v2.0.3/lib/loofah/html5/whitelist.rb#L151)
|
|
72
75
|
# config.add_whitelist_elements = <%= Refinery::Pages.add_whitelist_elements.inspect %>
|
|
73
|
-
|
|
76
|
+
|
|
74
77
|
# You can add new HTML attributes not already supported by Loofah::HTML5::WhiteList::ALLOWED_ATTRIBUTES
|
|
75
|
-
# For more information on whitelist see ALLOWED_ATTRIBUTES
|
|
78
|
+
# For more information on whitelist see ALLOWED_ATTRIBUTES
|
|
76
79
|
# (https://github.com/flavorjones/loofah/blob/v2.0.3/lib/loofah/html5/whitelist.rb#L152)
|
|
77
80
|
# config.add_whitelist_attributes = <%= Refinery::Pages.add_whitelist_attributes.inspect %>
|
|
81
|
+
|
|
82
|
+
# You can configure the site so that the home page is a model-index page
|
|
83
|
+
# config.home_page_path = <%= Refinery::Pages.home_page_path.inspect %>
|
|
84
|
+
|
|
78
85
|
end
|
|
@@ -8,8 +8,9 @@ module Refinery
|
|
|
8
8
|
:cache_pages_full, :layout_template_whitelist,
|
|
9
9
|
:use_layout_templates, :page_title, :absolute_page_links, :types,
|
|
10
10
|
:auto_expand_admin_tree, :show_title_in_body,
|
|
11
|
-
:friendly_id_reserved_words, :layout_templates_pattern, :view_templates_pattern,
|
|
12
|
-
:add_whitelist_elements, :add_whitelist_attributes, :whitelist_elements, :whitelist_attributes
|
|
11
|
+
:friendly_id_reserved_words, :reserved_paths, :layout_templates_pattern, :view_templates_pattern,
|
|
12
|
+
:add_whitelist_elements, :add_whitelist_attributes, :whitelist_elements, :whitelist_attributes,
|
|
13
|
+
:home_page_path
|
|
13
14
|
|
|
14
15
|
self.pages_per_dialog = 14
|
|
15
16
|
self.pages_per_admin_index = 20
|
|
@@ -25,15 +26,16 @@ module Refinery
|
|
|
25
26
|
self.add_whitelist_elements = %w[ source track ]
|
|
26
27
|
# Note: "data-" attributes are whitelisted by default. See https://github.com/refinery/refinerycms/pull/3187
|
|
27
28
|
self.add_whitelist_attributes = %w[ kind srclang placeholder controls required ]
|
|
29
|
+
self.home_page_path = "/"
|
|
28
30
|
|
|
29
31
|
|
|
30
32
|
class << self
|
|
31
33
|
def whitelist_elements
|
|
32
|
-
Loofah::HTML5::
|
|
34
|
+
Loofah::HTML5::SafeList::ALLOWED_ELEMENTS.merge(config.add_whitelist_elements)
|
|
33
35
|
end
|
|
34
36
|
|
|
35
37
|
def whitelist_attributes
|
|
36
|
-
Loofah::HTML5::
|
|
38
|
+
Loofah::HTML5::SafeList::ALLOWED_ATTRIBUTES.merge(config.add_whitelist_attributes)
|
|
37
39
|
end
|
|
38
40
|
|
|
39
41
|
def layout_template_whitelist
|
|
@@ -59,9 +61,10 @@ module Refinery
|
|
|
59
61
|
self.absolute_page_links = false
|
|
60
62
|
self.types = Types.registered
|
|
61
63
|
self.auto_expand_admin_tree = true
|
|
64
|
+
self.reserved_paths = %w(/rails/active_storage)
|
|
62
65
|
self.friendly_id_reserved_words = %w(
|
|
63
66
|
index new session login logout users refinery admin images
|
|
64
|
-
)
|
|
67
|
+
) | self.reserved_paths.map { |path| path.split('/').reject(&:blank?).first}.flatten.uniq
|
|
65
68
|
self.layout_templates_pattern = 'app', 'views', '{layouts,refinery/layouts}', '*html*'
|
|
66
69
|
self.view_templates_pattern = 'app', 'views', '{pages,refinery/pages}', '*html*'
|
|
67
70
|
end
|
|
@@ -48,7 +48,8 @@ module Refinery
|
|
|
48
48
|
|
|
49
49
|
def append_marketable_routes
|
|
50
50
|
Refinery::Core::Engine.routes.append do
|
|
51
|
-
get '*path', :to => 'pages#show', :as => :marketable_page
|
|
51
|
+
get '*path', :to => 'pages#show', :as => :marketable_page,
|
|
52
|
+
constraints: lambda { |request| !Refinery::Pages.config.reserved_paths.any? { |path| request.path.start_with?(path) } }
|
|
52
53
|
end
|
|
53
54
|
end
|
|
54
55
|
|
|
@@ -17,7 +17,7 @@ module Refinery
|
|
|
17
17
|
FinderBySlug.new(slug, conditions).find
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
def self.
|
|
20
|
+
def self.with_mobility(conditions = {})
|
|
21
21
|
Finder.new(conditions).find
|
|
22
22
|
end
|
|
23
23
|
|
|
@@ -26,15 +26,15 @@ module Refinery
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def find
|
|
29
|
-
|
|
29
|
+
with_mobility
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
def
|
|
33
|
-
|
|
34
|
-
translations_conditions = translations_conditions(
|
|
32
|
+
def with_mobility
|
|
33
|
+
mobility_conditions = {:locale => ::Mobility.locale.to_s}.merge(conditions)
|
|
34
|
+
translations_conditions = translations_conditions(mobility_conditions)
|
|
35
35
|
|
|
36
36
|
# A join implies readonly which we don't really want.
|
|
37
|
-
Page.where(
|
|
37
|
+
Page.i18n.where(mobility_conditions).
|
|
38
38
|
joins(:translations).
|
|
39
39
|
where(translations_conditions).
|
|
40
40
|
readonly(false)
|
|
@@ -44,136 +44,135 @@ module Refinery
|
|
|
44
44
|
attr_accessor :conditions
|
|
45
45
|
|
|
46
46
|
def translated_attributes
|
|
47
|
-
Page.
|
|
47
|
+
[*Page.mobility_attributes, 'locale']
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
def translations_conditions(original_conditions)
|
|
51
51
|
translations_conditions = {}
|
|
52
52
|
original_conditions.keys.each do |key|
|
|
53
53
|
if translated_attributes.include? key.to_s
|
|
54
|
-
translations_conditions["#{Page.
|
|
54
|
+
translations_conditions["#{Page::Translation.table_name}.#{key}"] = original_conditions.delete(key)
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
57
|
translations_conditions
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
class FinderByTitle < Finder
|
|
61
|
+
def initialize(title)
|
|
62
|
+
@title = title
|
|
63
|
+
@conditions = default_conditions
|
|
64
|
+
end
|
|
61
65
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
@conditions = default_conditions
|
|
66
|
-
end
|
|
66
|
+
def default_conditions
|
|
67
|
+
{ :title => title }
|
|
68
|
+
end
|
|
67
69
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
private
|
|
71
|
+
attr_accessor :title
|
|
70
72
|
end
|
|
71
73
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
class FinderBySlug < Finder
|
|
75
|
+
def initialize(slug, conditions)
|
|
76
|
+
@slug = slug
|
|
77
|
+
@conditions = default_conditions.merge(conditions)
|
|
78
|
+
end
|
|
75
79
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
def default_conditions
|
|
81
|
+
{
|
|
82
|
+
:locale => Refinery::I18n.frontend_locales.map(&:to_s),
|
|
83
|
+
:slug => slug
|
|
84
|
+
}
|
|
85
|
+
end
|
|
81
86
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
:locale => Refinery::I18n.frontend_locales.map(&:to_s),
|
|
85
|
-
:slug => slug
|
|
86
|
-
}
|
|
87
|
+
private
|
|
88
|
+
attr_accessor :slug
|
|
87
89
|
end
|
|
88
90
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
class FinderByPath
|
|
94
|
-
def initialize(path)
|
|
95
|
-
@path = path
|
|
96
|
-
end
|
|
91
|
+
class FinderByPath
|
|
92
|
+
def initialize(path)
|
|
93
|
+
@path = path
|
|
94
|
+
end
|
|
97
95
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
def find
|
|
97
|
+
if slugs_scoped_by_parent?
|
|
98
|
+
FinderByScopedPath.new(path).find
|
|
99
|
+
else
|
|
100
|
+
FinderByUnscopedPath.new(path).find
|
|
101
|
+
end
|
|
103
102
|
end
|
|
104
|
-
end
|
|
105
103
|
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
private
|
|
105
|
+
attr_accessor :path
|
|
108
106
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
107
|
+
def slugs_scoped_by_parent?
|
|
108
|
+
::Refinery::Pages.scope_slug_by_parent
|
|
109
|
+
end
|
|
112
110
|
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
def by_slug(slug_path, conditions = {})
|
|
112
|
+
Finder.by_slug(slug_path, conditions)
|
|
113
|
+
end
|
|
115
114
|
end
|
|
116
|
-
end
|
|
117
115
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
116
|
+
class FinderByScopedPath < FinderByPath
|
|
117
|
+
def find
|
|
118
|
+
# With slugs scoped to the parent page we need to find a page by its full path.
|
|
119
|
+
# For example with about/example we would need to find 'about' and then its child
|
|
120
|
+
# called 'example' otherwise it may clash with another page called /example.
|
|
121
|
+
page = parent_page
|
|
122
|
+
while page && path_segments.any? do
|
|
123
|
+
page = next_page(page)
|
|
124
|
+
end
|
|
125
|
+
page
|
|
126
126
|
end
|
|
127
|
-
page
|
|
128
|
-
end
|
|
129
127
|
|
|
130
|
-
|
|
128
|
+
private
|
|
131
129
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
130
|
+
def path_segments
|
|
131
|
+
@path_segments ||= path.split('/').select(&:present?)
|
|
132
|
+
end
|
|
135
133
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
134
|
+
def parent_page
|
|
135
|
+
parent_page_segment = path_segments.shift
|
|
136
|
+
if parent_page_segment.friendly_id?
|
|
137
|
+
by_slug(parent_page_segment, :parent_id => nil).first
|
|
138
|
+
else
|
|
139
|
+
Page.find(parent_page_segment)
|
|
140
|
+
end
|
|
142
141
|
end
|
|
143
|
-
end
|
|
144
142
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
143
|
+
def next_page(page)
|
|
144
|
+
slug_or_id = path_segments.shift
|
|
145
|
+
page.children.by_slug(slug_or_id).first || page.children.find(slug_or_id)
|
|
146
|
+
end
|
|
148
147
|
end
|
|
149
|
-
end
|
|
150
148
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
149
|
+
class FinderByUnscopedPath < FinderByPath
|
|
150
|
+
def find
|
|
151
|
+
by_slug(path).first
|
|
152
|
+
end
|
|
154
153
|
end
|
|
155
|
-
end
|
|
156
154
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
155
|
+
class FinderByPathOrId
|
|
156
|
+
def initialize(path, id)
|
|
157
|
+
@path = path
|
|
158
|
+
@id = id
|
|
159
|
+
end
|
|
162
160
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
161
|
+
def find
|
|
162
|
+
if path.present?
|
|
163
|
+
if path.friendly_id?
|
|
164
|
+
FinderByPath.new(path).find
|
|
165
|
+
else
|
|
166
|
+
Page.friendly.find(path)
|
|
167
|
+
end
|
|
168
|
+
elsif id.present?
|
|
169
|
+
Page.friendly.find(id)
|
|
169
170
|
end
|
|
170
|
-
elsif id.present?
|
|
171
|
-
Page.friendly.find(id)
|
|
172
171
|
end
|
|
173
|
-
end
|
|
174
172
|
|
|
175
|
-
|
|
176
|
-
|
|
173
|
+
private
|
|
174
|
+
attr_accessor :id, :path
|
|
175
|
+
end
|
|
177
176
|
end
|
|
178
177
|
end
|
|
179
178
|
end
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Refinery
|
|
2
4
|
module Pages
|
|
3
5
|
module InstanceMethods
|
|
4
6
|
|
|
5
7
|
def error_404(exception = nil)
|
|
6
|
-
if (@page = ::Refinery::Page.where(:
|
|
8
|
+
if (@page = ::Refinery::Page.where(menu_match: "^/404$").includes(:parts).first).present?
|
|
7
9
|
# render the application's custom 404 page with layout and meta.
|
|
8
10
|
if self.respond_to? :render_with_templates?, true
|
|
9
|
-
render_with_templates? @page, :
|
|
11
|
+
render_with_templates? @page, status: 404
|
|
10
12
|
else
|
|
11
|
-
render :
|
|
13
|
+
render template: '/refinery/pages/show', format: :html, status: 404
|
|
12
14
|
end
|
|
13
15
|
return false
|
|
14
16
|
else
|
|
@@ -16,7 +18,7 @@ module Refinery
|
|
|
16
18
|
end
|
|
17
19
|
end
|
|
18
20
|
|
|
19
|
-
def render(*args)
|
|
21
|
+
def render(*args, &block)
|
|
20
22
|
present @page unless admin? || @meta
|
|
21
23
|
super
|
|
22
24
|
end
|
data/lib/refinery/pages.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
require 'refinerycms
|
|
2
|
-
require '
|
|
1
|
+
require 'refinerycms/core'
|
|
2
|
+
require 'mobility'
|
|
3
3
|
|
|
4
4
|
module Refinery
|
|
5
5
|
autoload :PagesGenerator, 'generators/refinery/pages/pages_generator'
|
|
@@ -51,4 +51,4 @@ end
|
|
|
51
51
|
require 'friendly_id'
|
|
52
52
|
require 'seo_meta'
|
|
53
53
|
require 'babosa'
|
|
54
|
-
require 'speakingurl-rails'
|
|
54
|
+
require 'speakingurl-rails'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require_relative '../refinery/pages'
|
data/refinerycms-pages.gemspec
CHANGED
|
@@ -1,38 +1,32 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path('../core/lib/refinery/version', __dir__)
|
|
3
4
|
|
|
4
5
|
version = Refinery::Version.to_s
|
|
5
6
|
|
|
6
7
|
Gem::Specification.new do |s|
|
|
7
8
|
s.platform = Gem::Platform::RUBY
|
|
8
|
-
s.name =
|
|
9
|
+
s.name = 'refinerycms-pages'
|
|
9
10
|
s.version = version
|
|
10
|
-
s.summary =
|
|
11
|
-
s.description =
|
|
12
|
-
s.email =
|
|
13
|
-
s.homepage =
|
|
14
|
-
s.
|
|
15
|
-
s.
|
|
16
|
-
s.
|
|
17
|
-
s.require_paths = %w(lib)
|
|
11
|
+
s.summary = 'Pages extension for Refinery CMS'
|
|
12
|
+
s.description = 'The default content extension of Refinery CMS. This extension handles the administration and display of user-editable pages.'
|
|
13
|
+
s.email = 'gems@p.arndt.io'
|
|
14
|
+
s.homepage = 'https://www.refinerycms.com'
|
|
15
|
+
s.authors = ['Philip Arndt', 'David Jones', 'Uģis Ozols', 'Brice Sanchez']
|
|
16
|
+
s.license = 'MIT'
|
|
17
|
+
s.require_paths = %w[lib]
|
|
18
18
|
|
|
19
19
|
s.files = `git ls-files`.split("\n")
|
|
20
20
|
s.test_files = `git ls-files -- spec/*`.split("\n")
|
|
21
21
|
|
|
22
|
-
s.add_dependency 'friendly_id', ['>= 5.1.0', '< 5.3']
|
|
23
|
-
s.add_dependency 'globalize', ['>= 5.1.0.beta1', '< 5.2']
|
|
24
|
-
s.add_dependency 'activemodel-serializers-xml', '~> 1.0', '>= 1.0.1'
|
|
25
22
|
s.add_dependency 'awesome_nested_set', '~> 3.1', '>= 3.1.0'
|
|
26
|
-
s.add_dependency '
|
|
23
|
+
s.add_dependency 'babosa', '~> 1.0'
|
|
24
|
+
s.add_dependency 'diffy', '~> 3.1', '>= 3.1.0'
|
|
25
|
+
s.add_dependency 'friendly_id', '>= 5.4.0'
|
|
26
|
+
s.add_dependency 'friendly_id-mobility', '~> 1.0.4'
|
|
27
27
|
s.add_dependency 'refinerycms-core', version
|
|
28
|
-
s.add_dependency '
|
|
28
|
+
s.add_dependency 'seo_meta', '~> 3.0', '>= 3.0.0'
|
|
29
29
|
s.add_dependency 'speakingurl-rails', '~> 8.0', '>= 8.0.0'
|
|
30
|
-
s.add_dependency 'diffy', '~> 3.1', '>= 3.1.0'
|
|
31
30
|
|
|
32
31
|
s.required_ruby_version = Refinery::Version.required_ruby_version
|
|
33
|
-
|
|
34
|
-
s.cert_chain = [File.expand_path("../../certs/parndt.pem", __FILE__)]
|
|
35
|
-
if $0 =~ /gem\z/ && ARGV.include?("build") && ARGV.include?(__FILE__)
|
|
36
|
-
s.signing_key = File.expand_path("~/.ssh/gem-private_key.pem")
|
|
37
|
-
end
|
|
38
32
|
end
|