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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ae17335fe58d0639787e9ce4b9a3b35087d9e0fb6e8022d1177ab875334d8af6
|
|
4
|
+
data.tar.gz: b2ea953d3fdbd2d81aacb589628ad17d65e72b7193808cee8eeaf256fcaa69b4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ddaea6f897999904cb366edf108b92ff87a37842dda38815388d7a040c9ec9f954c6ff29bfa218f237097707d0f50b5253e6cd580416b5cb7ff23f1112daf7b6
|
|
7
|
+
data.tar.gz: d5faab462239c5f137770f046e29062b246b4c646d6b3fe126ddc8b891c57ee8f23444edf098f5a19a6789995755e9bc3f6be08b5e49906725053295eaca29fa
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
module Refinery
|
|
2
2
|
module Admin
|
|
3
3
|
class PagePartsController < ::Refinery::AdminController
|
|
4
|
+
skip_after_action :store_location?, raise: false
|
|
4
5
|
|
|
5
6
|
def new
|
|
6
7
|
render :partial => '/refinery/admin/pages/page_part_field', :locals => {
|
|
@@ -28,7 +29,7 @@ module Refinery
|
|
|
28
29
|
|
|
29
30
|
private
|
|
30
31
|
def permitted_new_page_part_params
|
|
31
|
-
[:title, :slug, :body
|
|
32
|
+
[:title, :slug, :body]
|
|
32
33
|
end
|
|
33
34
|
end
|
|
34
35
|
end
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
module Refinery
|
|
2
2
|
module Admin
|
|
3
3
|
class PagesController < Refinery::AdminController
|
|
4
|
-
prepend Pages::InstanceMethods
|
|
4
|
+
prepend Refinery::Pages::InstanceMethods
|
|
5
5
|
|
|
6
6
|
crudify :'refinery/page',
|
|
7
|
-
:
|
|
8
|
-
:
|
|
7
|
+
include: [:translations, :children],
|
|
8
|
+
paging: false,
|
|
9
|
+
exclude_from_find: [:show]
|
|
9
10
|
|
|
10
11
|
helper_method :valid_layout_templates, :valid_view_templates
|
|
11
12
|
|
|
12
13
|
def new
|
|
13
14
|
@page = Page.new(new_page_params)
|
|
14
|
-
Pages.default_parts_for(@page).each_with_index do |page_part, index|
|
|
15
|
+
Refinery::Pages.default_parts_for(@page).each_with_index do |page_part, index|
|
|
15
16
|
@page.parts << PagePart.new(:title => page_part[:title], :slug => page_part[:slug], :position => index)
|
|
16
17
|
end
|
|
17
18
|
end
|
|
@@ -22,7 +23,7 @@ module Refinery
|
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
def update
|
|
25
|
-
if @page.
|
|
26
|
+
if @page.update(page_params)
|
|
26
27
|
flash.notice = t('refinery.crudify.updated', what: "'#{@page.title}'")
|
|
27
28
|
|
|
28
29
|
if from_dialog?
|
|
@@ -35,7 +36,7 @@ module Refinery
|
|
|
35
36
|
render partial: 'save_and_continue_callback',
|
|
36
37
|
locals: save_and_continue_locals(@page)
|
|
37
38
|
else
|
|
38
|
-
|
|
39
|
+
redirect_back(fallback_location: { action: 'edit' })
|
|
39
40
|
end
|
|
40
41
|
else
|
|
41
42
|
redirect_back_or_default(refinery.admin_pages_path)
|
|
@@ -67,23 +68,23 @@ module Refinery
|
|
|
67
68
|
|
|
68
69
|
# We can safely assume ::Refinery::I18n is defined because this method only gets
|
|
69
70
|
# Invoked when the before_action from the plugin is run.
|
|
70
|
-
def
|
|
71
|
+
def mobility!
|
|
71
72
|
return super unless action_name.to_s == 'index'
|
|
72
73
|
|
|
73
74
|
# Always display the tree of pages from the default frontend locale.
|
|
74
75
|
if Refinery::I18n.built_in_locales.keys.map(&:to_s).include?(params[:switch_locale])
|
|
75
|
-
|
|
76
|
+
Mobility.locale = params[:switch_locale].try(:to_sym)
|
|
76
77
|
else
|
|
77
|
-
|
|
78
|
+
Mobility.locale = Refinery::I18n.default_frontend_locale
|
|
78
79
|
end
|
|
79
80
|
end
|
|
80
81
|
|
|
81
82
|
def valid_layout_templates
|
|
82
|
-
Pages.layout_template_whitelist & Pages.valid_templates(*Pages.layout_templates_pattern)
|
|
83
|
+
Refinery::Pages.layout_template_whitelist & Refinery::Pages.valid_templates(*Refinery::Pages.layout_templates_pattern)
|
|
83
84
|
end
|
|
84
85
|
|
|
85
86
|
def valid_view_templates
|
|
86
|
-
Pages.valid_templates(*Pages.view_templates_pattern)
|
|
87
|
+
Refinery::Pages.valid_templates(*Refinery::Pages.view_templates_pattern)
|
|
87
88
|
end
|
|
88
89
|
|
|
89
90
|
def page_params
|
|
@@ -6,16 +6,16 @@ module Refinery
|
|
|
6
6
|
|
|
7
7
|
def link_to
|
|
8
8
|
# Get the switch_local variable to determine the locale we're currently editing
|
|
9
|
-
# Set up
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
# Set up Mobility with our current locale
|
|
10
|
+
Mobility.locale = if params[:switch_locale].present? && Refinery::I18n.built_in_locales.keys.map(&:to_s).include?(params[:switch_locale])
|
|
11
|
+
Mobility.locale = params[:switch_locale]
|
|
12
12
|
else
|
|
13
13
|
Refinery::I18n.default_locale
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
@pages = ::Refinery::Page.roots.paginate(:page => params[:page], :per_page => ::Refinery::Page.per_page(true))
|
|
17
17
|
|
|
18
|
-
@pages = @pages.
|
|
18
|
+
@pages = @pages.with_mobility
|
|
19
19
|
|
|
20
20
|
if ::Refinery::Plugins.registered.names.include?('refinery_files')
|
|
21
21
|
@resources = Resource.paginate(:page => params[:resource_page], :per_page => Resource.per_page(true)).
|
|
@@ -28,8 +28,8 @@ module Refinery
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
# web address link
|
|
31
|
-
@web_address_text = "
|
|
32
|
-
@web_address_text = params[:current_link] if params[:current_link].to_s =~ /^
|
|
31
|
+
@web_address_text = "https://"
|
|
32
|
+
@web_address_text = params[:current_link] if params[:current_link].to_s =~ /^https?:\/\//
|
|
33
33
|
@web_address_target_blank = (params[:target_blank] == "true")
|
|
34
34
|
|
|
35
35
|
# mailto link
|
|
@@ -45,8 +45,8 @@ module Refinery
|
|
|
45
45
|
@page_area_selected = (params[:paginating] == "your_page")
|
|
46
46
|
@resource_area_selected = (params[:paginating] == "resource_file")
|
|
47
47
|
else
|
|
48
|
-
@page_area_selected = (!is_resource_link and @web_address_text == "
|
|
49
|
-
@web_address_area_selected = (@web_address_text != "
|
|
48
|
+
@page_area_selected = (!is_resource_link and @web_address_text == "https://" and @email_address_text.blank?)
|
|
49
|
+
@web_address_area_selected = (@web_address_text != "https://")
|
|
50
50
|
@email_address_area_selected = @email_address_text.present?
|
|
51
51
|
@resource_area_selected = is_resource_link
|
|
52
52
|
end
|
|
@@ -9,6 +9,9 @@ module Refinery
|
|
|
9
9
|
include Pages::RenderOptions
|
|
10
10
|
|
|
11
11
|
skip_before_action :error_404, :set_canonical
|
|
12
|
+
skip_after_action :store_location?, raise: false
|
|
13
|
+
|
|
14
|
+
layout :layout
|
|
12
15
|
|
|
13
16
|
def show
|
|
14
17
|
render_with_templates?
|
|
@@ -44,6 +47,10 @@ module Refinery
|
|
|
44
47
|
:layout_template, :custom_slug, parts_attributes: [:id, :title, :slug, :body, :position]
|
|
45
48
|
]
|
|
46
49
|
end
|
|
50
|
+
|
|
51
|
+
def layout
|
|
52
|
+
'application'
|
|
53
|
+
end
|
|
47
54
|
end
|
|
48
55
|
end
|
|
49
56
|
end
|
|
@@ -10,6 +10,9 @@ module Refinery
|
|
|
10
10
|
|
|
11
11
|
# This action is usually accessed with the root path, normally '/'
|
|
12
12
|
def home
|
|
13
|
+
if page.link_url.present? && page.link_url != "/"
|
|
14
|
+
redirect_to page.link_url, status: 301 and return
|
|
15
|
+
end
|
|
13
16
|
render_with_templates?
|
|
14
17
|
end
|
|
15
18
|
|
|
@@ -101,7 +104,7 @@ module Refinery
|
|
|
101
104
|
module Finders
|
|
102
105
|
class Home
|
|
103
106
|
def self.call(_params)
|
|
104
|
-
Refinery::Page.find_by link_url:
|
|
107
|
+
Refinery::Page.find_by link_url: Refinery::Pages.home_page_path
|
|
105
108
|
end
|
|
106
109
|
end
|
|
107
110
|
|
|
@@ -3,22 +3,26 @@ module Refinery
|
|
|
3
3
|
module PagesHelper
|
|
4
4
|
def parent_id_nested_set_options(current_page)
|
|
5
5
|
pages = []
|
|
6
|
-
nested_set_options(::Refinery::Page, current_page) { |page| pages << page}
|
|
6
|
+
nested_set_options(::Refinery::Page, current_page) { |page| pages << page }
|
|
7
7
|
# page.title needs the :translations association, doing something like
|
|
8
8
|
# nested_set_options(::Refinery::Page.includes(:translations), page) doesn't work, yet.
|
|
9
9
|
# See https://github.com/collectiveidea/awesome_nested_set/pull/123
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
if Rails::VERSION::MAJOR >= 7
|
|
11
|
+
ActiveRecord::Associations::Preloader.new(records: pages, associations: :translations).call
|
|
12
|
+
else
|
|
13
|
+
ActiveRecord::Associations::Preloader.new.preload(pages, :translations)
|
|
14
|
+
end
|
|
15
|
+
pages.map { |page| ["#{'-' * page.level} #{page.title}", page.id] }
|
|
12
16
|
end
|
|
13
17
|
|
|
14
18
|
def template_options(template_type, current_page)
|
|
15
|
-
html_options = { :
|
|
19
|
+
html_options = { selected: send("default_#{template_type}", current_page) }
|
|
16
20
|
|
|
17
21
|
if (template = current_page.send(template_type).presence)
|
|
18
|
-
html_options.update :
|
|
22
|
+
html_options.update selected: template
|
|
19
23
|
elsif current_page.parent_id? && !current_page.send(template_type).presence
|
|
20
24
|
template = current_page.parent.send(template_type).presence
|
|
21
|
-
html_options.update :
|
|
25
|
+
html_options.update selected: template if template
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
html_options
|
|
@@ -52,7 +56,25 @@ module Refinery
|
|
|
52
56
|
::I18n.t('draft', :scope => 'refinery.admin.pages.page')
|
|
53
57
|
end if page.draft?
|
|
54
58
|
|
|
55
|
-
meta_information
|
|
59
|
+
tag.span meta_information, class: :meta
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def page_icon(number_of_children)
|
|
63
|
+
# 1. has_children 'folder|folderopen', 'toggle'
|
|
64
|
+
# 2. no_children 'page'
|
|
65
|
+
|
|
66
|
+
# .toggle scss handles adding icons to pages with children
|
|
67
|
+
classes = ['icon']
|
|
68
|
+
if number_of_children.zero?
|
|
69
|
+
classes.push icon_class('page')
|
|
70
|
+
title = ::I18n.t('edit', scope: 'refinery.admin.pages.page')
|
|
71
|
+
else
|
|
72
|
+
expanded_class = Refinery::Pages.auto_expand_admin_tree ? 'expanded' : ''
|
|
73
|
+
classes.push 'toggle', expanded_class
|
|
74
|
+
title = ::I18n.t('expand_collapse', scope: 'refinery.admin.pages')
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
tag.span(class: classes.join(' '), title: title)
|
|
56
78
|
end
|
|
57
79
|
end
|
|
58
80
|
end
|
data/app/models/refinery/page.rb
CHANGED
|
@@ -1,74 +1,62 @@
|
|
|
1
1
|
# Encoding: utf-8
|
|
2
2
|
require 'friendly_id'
|
|
3
|
+
require 'friendly_id/mobility'
|
|
3
4
|
require 'refinery/core/base_model'
|
|
4
5
|
require 'refinery/pages/url'
|
|
5
6
|
require 'refinery/pages/finder'
|
|
6
7
|
|
|
7
8
|
module Refinery
|
|
8
9
|
class Page < Core::BaseModel
|
|
9
|
-
extend
|
|
10
|
-
|
|
11
|
-
translates :title, :menu_title, :custom_slug, :slug, :include => :seo_meta
|
|
12
|
-
|
|
13
|
-
attribute :title
|
|
14
|
-
attribute :menu_title
|
|
15
|
-
attribute :custom_slug
|
|
16
|
-
attribute :slug
|
|
10
|
+
extend Mobility
|
|
11
|
+
translates :title, :menu_title, :custom_slug, :slug, :browser_title, :meta_description
|
|
17
12
|
|
|
18
|
-
after_save { translations.
|
|
13
|
+
after_save { translations.in_locale(Mobility.locale).seo_meta.save! }
|
|
19
14
|
|
|
20
15
|
class Translation
|
|
21
16
|
is_seo_meta
|
|
22
|
-
|
|
23
|
-
def self.seo_fields
|
|
24
|
-
::SeoMeta.attributes.keys.map{ |a| [a, :"#{a}="]}.flatten
|
|
25
|
-
end
|
|
26
17
|
end
|
|
27
18
|
|
|
19
|
+
has_many :parts, -> {
|
|
20
|
+
scope = ::Refinery::PagePart.respond_to?(:mobility) ? i18n.includes(:translations) : all
|
|
21
|
+
scope = scope.order('position ASC')
|
|
22
|
+
scope
|
|
23
|
+
}, :foreign_key => :refinery_page_id,
|
|
24
|
+
:class_name => '::Refinery::PagePart',
|
|
25
|
+
:inverse_of => :page,
|
|
26
|
+
:dependent => :destroy
|
|
27
|
+
|
|
28
|
+
accepts_nested_attributes_for :parts, :allow_destroy => true
|
|
29
|
+
|
|
30
|
+
# Docs for acts_as_nested_set https://github.com/collectiveidea/awesome_nested_set
|
|
31
|
+
# rather than :delete_all we want :destroy
|
|
32
|
+
acts_as_nested_set :dependent => :destroy
|
|
33
|
+
|
|
28
34
|
class FriendlyIdOptions
|
|
29
35
|
def self.options
|
|
30
36
|
# Docs for friendly_id https://github.com/norman/friendly_id
|
|
31
37
|
friendly_id_options = {
|
|
32
|
-
use: [:reserved],
|
|
38
|
+
use: [:mobility, :reserved],
|
|
33
39
|
reserved_words: Refinery::Pages.friendly_id_reserved_words
|
|
34
40
|
}
|
|
35
41
|
if ::Refinery::Pages.scope_slug_by_parent
|
|
36
42
|
friendly_id_options[:use] << :scoped
|
|
37
43
|
friendly_id_options.merge!(scope: :parent)
|
|
38
44
|
end
|
|
39
|
-
|
|
45
|
+
|
|
40
46
|
friendly_id_options
|
|
41
47
|
end
|
|
42
48
|
end
|
|
43
49
|
|
|
50
|
+
extend FriendlyId
|
|
51
|
+
friendly_id :custom_slug_or_title, FriendlyIdOptions.options
|
|
52
|
+
|
|
44
53
|
# If title changes tell friendly_id to regenerate slug when saving record
|
|
45
54
|
def should_generate_new_friendly_id?
|
|
46
|
-
|
|
55
|
+
title_changed? || custom_slug_changed?
|
|
47
56
|
end
|
|
48
57
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
validates :title, :presence => true
|
|
53
|
-
|
|
54
|
-
validates :custom_slug, :uniqueness => true, :allow_blank => true
|
|
55
|
-
|
|
56
|
-
# Docs for acts_as_nested_set https://github.com/collectiveidea/awesome_nested_set
|
|
57
|
-
# rather than :delete_all we want :destroy
|
|
58
|
-
acts_as_nested_set counter_cache: :children_count, dependent: :destroy, touch: true
|
|
59
|
-
|
|
60
|
-
friendly_id :custom_slug_or_title, FriendlyIdOptions.options
|
|
61
|
-
|
|
62
|
-
has_many :parts, -> {
|
|
63
|
-
scope = order('position ASC')
|
|
64
|
-
scope = scope.includes(:translations) if ::Refinery::PagePart.respond_to?(:translation_class)
|
|
65
|
-
scope
|
|
66
|
-
}, :foreign_key => :refinery_page_id,
|
|
67
|
-
:class_name => '::Refinery::PagePart',
|
|
68
|
-
:inverse_of => :page,
|
|
69
|
-
:dependent => :destroy
|
|
70
|
-
|
|
71
|
-
accepts_nested_attributes_for :parts, :allow_destroy => true
|
|
58
|
+
validates :title, presence: true
|
|
59
|
+
validates :custom_slug, uniqueness: true, allow_blank: true
|
|
72
60
|
|
|
73
61
|
before_destroy :deletable?
|
|
74
62
|
after_save :reposition_parts!
|
|
@@ -103,7 +91,7 @@ module Refinery
|
|
|
103
91
|
def find_by_path_or_id!(path, id)
|
|
104
92
|
page = find_by_path_or_id(path, id)
|
|
105
93
|
|
|
106
|
-
raise ActiveRecord::RecordNotFound unless page
|
|
94
|
+
raise ::ActiveRecord::RecordNotFound unless page
|
|
107
95
|
|
|
108
96
|
page
|
|
109
97
|
end
|
|
@@ -129,7 +117,7 @@ module Refinery
|
|
|
129
117
|
# This works using a query against the translated content first and then
|
|
130
118
|
# using all of the page_ids we further filter against this model's table.
|
|
131
119
|
def in_menu
|
|
132
|
-
where(:
|
|
120
|
+
where(show_in_menu: true).with_mobility
|
|
133
121
|
end
|
|
134
122
|
|
|
135
123
|
# An optimised scope containing only live pages ordered for display in a menu.
|
|
@@ -138,8 +126,8 @@ module Refinery
|
|
|
138
126
|
end
|
|
139
127
|
|
|
140
128
|
# Wrap up the logic of finding the pages based on the translations table.
|
|
141
|
-
def
|
|
142
|
-
Pages::Finder.
|
|
129
|
+
def with_mobility(conditions = {})
|
|
130
|
+
Pages::Finder.with_mobility(conditions)
|
|
143
131
|
end
|
|
144
132
|
|
|
145
133
|
# Returns how many pages per page should there be when paginating pages
|
|
@@ -155,7 +143,7 @@ module Refinery
|
|
|
155
143
|
protected
|
|
156
144
|
|
|
157
145
|
def nullify_duplicate_slugs_under_the_same_parent!
|
|
158
|
-
t_slug =
|
|
146
|
+
t_slug = Translation.arel_table[:slug]
|
|
159
147
|
joins(:translations).group(:locale, :parent_id, t_slug).having(t_slug.count.gt(1)).count.
|
|
160
148
|
each do |(locale, parent_id, slug), count|
|
|
161
149
|
by_slug(slug, :locale => locale).where(:parent_id => parent_id).drop(1).each do |page|
|
|
@@ -167,20 +155,20 @@ module Refinery
|
|
|
167
155
|
end
|
|
168
156
|
|
|
169
157
|
def translated_to_default_locale?
|
|
170
|
-
persisted? && translations.any?{ |t| t.locale == Refinery::I18n.default_frontend_locale}
|
|
158
|
+
persisted? && translations.any?{ |t| t.locale.to_sym == Refinery::I18n.default_frontend_locale}
|
|
171
159
|
end
|
|
172
160
|
|
|
173
161
|
# The canonical page for this particular page.
|
|
174
162
|
# Consists of:
|
|
175
163
|
# * The current locale's translated slug
|
|
176
164
|
def canonical
|
|
177
|
-
|
|
165
|
+
Mobility.with_locale(::Refinery::I18n.current_frontend_locale) { url }
|
|
178
166
|
end
|
|
179
167
|
|
|
180
168
|
# The canonical slug for this particular page.
|
|
181
169
|
# This is the slug for the current frontend locale.
|
|
182
170
|
def canonical_slug
|
|
183
|
-
|
|
171
|
+
Mobility.with_locale(::Refinery::I18n.current_frontend_locale) { slug }
|
|
184
172
|
end
|
|
185
173
|
|
|
186
174
|
# Returns in cascading order: custom_slug or menu_title or title depending on
|
|
@@ -217,7 +205,7 @@ module Refinery
|
|
|
217
205
|
|
|
218
206
|
# If you want to destroy a page that is set to be not deletable this is the way to do it.
|
|
219
207
|
def destroy!
|
|
220
|
-
self.
|
|
208
|
+
self.update(:menu_match => nil, :link_url => nil, :deletable => true)
|
|
221
209
|
|
|
222
210
|
self.destroy
|
|
223
211
|
end
|
|
@@ -237,7 +225,7 @@ module Refinery
|
|
|
237
225
|
end
|
|
238
226
|
|
|
239
227
|
def nested_url
|
|
240
|
-
|
|
228
|
+
Mobility.with_locale(slug_locale) do
|
|
241
229
|
if ::Refinery::Pages.scope_slug_by_parent && !root?
|
|
242
230
|
self_and_ancestors.includes(:translations).map(&:to_param)
|
|
243
231
|
else
|
|
@@ -379,9 +367,9 @@ module Refinery
|
|
|
379
367
|
end
|
|
380
368
|
|
|
381
369
|
def slug_locale
|
|
382
|
-
return
|
|
370
|
+
return Mobility.locale if slug
|
|
383
371
|
|
|
384
|
-
if translations.empty? ||
|
|
372
|
+
if translations.empty? || slug(locale: Refinery::I18n.default_frontend_locale)
|
|
385
373
|
Refinery::I18n.default_frontend_locale
|
|
386
374
|
else
|
|
387
375
|
translations.first.locale
|
|
@@ -6,19 +6,25 @@ module Refinery
|
|
|
6
6
|
before_validation :set_default_slug
|
|
7
7
|
|
|
8
8
|
validates :title, :presence => true
|
|
9
|
-
validates :slug, :presence => true, :uniqueness => {:scope => :refinery_page_id}
|
|
10
|
-
alias_attribute :content, :body
|
|
9
|
+
validates :slug, :presence => true, :uniqueness => {:scope => :refinery_page_id, :case_sensitive => true}
|
|
11
10
|
|
|
11
|
+
extend Mobility
|
|
12
12
|
translates :body
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
def content
|
|
15
|
+
body
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def content=(value)
|
|
19
|
+
self.body = value
|
|
20
|
+
end
|
|
15
21
|
|
|
16
22
|
def to_param
|
|
17
23
|
"page_part_#{slug.downcase.gsub(/\W/, '_')}"
|
|
18
24
|
end
|
|
19
25
|
|
|
20
26
|
def body=(value)
|
|
21
|
-
|
|
27
|
+
super
|
|
22
28
|
|
|
23
29
|
normalise_text_fields
|
|
24
30
|
end
|
|
@@ -33,8 +39,8 @@ module Refinery
|
|
|
33
39
|
protected
|
|
34
40
|
|
|
35
41
|
def normalise_text_fields
|
|
36
|
-
if
|
|
37
|
-
|
|
42
|
+
if body? && body !~ %r{^<}
|
|
43
|
+
self.body = "<p>#{body.gsub("\r\n\r\n", "</p><p>").gsub("\r\n", "<br/>")}</p>"
|
|
38
44
|
end
|
|
39
45
|
end
|
|
40
46
|
|
|
@@ -89,7 +89,7 @@ module Refinery
|
|
|
89
89
|
url = find_url_for(item)
|
|
90
90
|
|
|
91
91
|
# Now use all possible vectors to try to find a valid match
|
|
92
|
-
[path,
|
|
92
|
+
[path, CGI.unescape(path)].include?(url) || path == "/#{item.original_id}"
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
def menu_item_css(menu_item, index)
|
|
@@ -136,4 +136,4 @@ module Refinery
|
|
|
136
136
|
end
|
|
137
137
|
end
|
|
138
138
|
end
|
|
139
|
-
end
|
|
139
|
+
end
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
<%= form_for [refinery, :admin, @page],
|
|
2
|
-
:
|
|
2
|
+
url: (refinery.admin_update_page_path(@page.nested_url) if @page.persisted?) do |f| %>
|
|
3
3
|
|
|
4
|
-
<%= render '/refinery/admin/error_messages', :
|
|
4
|
+
<%= render '/refinery/admin/error_messages', object: @page, include_object_name: true %>
|
|
5
5
|
|
|
6
|
-
<%= render '/refinery/admin/locale_picker', :
|
|
6
|
+
<%= render '/refinery/admin/locale_picker', current_locale: Mobility.locale %>
|
|
7
7
|
|
|
8
8
|
<div class="field">
|
|
9
9
|
<%= f.label :title %>
|
|
10
|
-
<%= f.text_field :title, :
|
|
10
|
+
<%= f.text_field :title, class: %w(larger widest) %>
|
|
11
11
|
</div>
|
|
12
12
|
|
|
13
|
-
<%= render 'form_fields_after_title', :
|
|
13
|
+
<%= render 'form_fields_after_title', f: f %>
|
|
14
14
|
|
|
15
|
-
<div class=
|
|
16
|
-
<%= render 'form_page_parts', :
|
|
15
|
+
<div class="field">
|
|
16
|
+
<%= render 'form_page_parts', f: f %>
|
|
17
17
|
</div>
|
|
18
18
|
|
|
19
|
-
<%= render 'form_advanced_options', :
|
|
19
|
+
<%= render 'form_advanced_options', f: f %>
|
|
20
20
|
|
|
21
21
|
<%= render '/refinery/admin/form_actions', f: f,
|
|
22
22
|
continue_editing: true,
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
),
|
|
34
34
|
cancel_url: refinery.admin_pages_path %>
|
|
35
35
|
|
|
36
|
-
<%= render 'form_new_page_parts', :
|
|
36
|
+
<%= render 'form_new_page_parts', f: f if Refinery::Pages.new_page_parts %>
|
|
37
37
|
<% end %>
|
|
38
38
|
|
|
39
39
|
<% content_for :javascripts do %>
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
action: prev_url,
|
|
65
65
|
target: prev_target
|
|
66
66
|
});
|
|
67
|
-
},
|
|
67
|
+
}, 500);
|
|
68
68
|
});
|
|
69
69
|
});
|
|
70
70
|
</script>
|
|
@@ -1,53 +1,25 @@
|
|
|
1
|
-
<%
|
|
2
|
-
add_url = refinery.new_admin_page_path(parent_id: page.id)
|
|
3
|
-
edit_url = refinery.admin_edit_page_path(page.nested_url, switch_locale: (page.translations.first.locale unless page.translated_to_default_locale?))
|
|
4
|
-
delete_url = refinery.admin_delete_page_path(page.nested_url)
|
|
5
|
-
delete_options = {
|
|
6
|
-
class: "cancel confirm-delete",
|
|
7
|
-
data: {confirm: t('message', scope: 'refinery.admin.delete', title: translated_field(page, :title))}
|
|
8
|
-
}
|
|
9
|
-
%>
|
|
1
|
+
<% edit_url = refinery.admin_edit_page_path(page.nested_url) %>
|
|
10
2
|
|
|
11
|
-
|
|
12
|
-
<div class=
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
<% else %>
|
|
18
|
-
<span class="item"></span>
|
|
19
|
-
<% end %>
|
|
3
|
+
<li class="record page <%= cycle('on', 'on-hover') %>" id="<%= dom_id(page) %>">
|
|
4
|
+
<div class="item">
|
|
5
|
+
<%= page_icon(page.children.size) %>
|
|
6
|
+
<%= link_to translated_field(page, :title), edit_url, class: [:title, :edit], title: t('.edit') %>
|
|
7
|
+
<%= page_meta_information(page) %>
|
|
8
|
+
<%= edit_in_locales(edit_url, locales_with_translated_field(page, 'title', include_current: false)) %>
|
|
20
9
|
|
|
21
|
-
<span class=
|
|
22
|
-
<%=
|
|
23
|
-
<%=
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
<%= link_to refinery.admin_edit_page_path(page.nested_url, switch_locale: translation.locale),
|
|
31
|
-
class: 'locale', title: translation.locale.upcase do %>
|
|
32
|
-
|
|
33
|
-
<div class="<%=translation.locale %> locale_marker">
|
|
34
|
-
<%= locale_text_icon(translation.locale.upcase) %>
|
|
35
|
-
</div>
|
|
36
|
-
<% end %>
|
|
37
|
-
<% end %>
|
|
38
|
-
<% end %>
|
|
39
|
-
</span>
|
|
40
|
-
<% end %>
|
|
41
|
-
|
|
42
|
-
<span class='actions'>
|
|
43
|
-
<%= action_icon(:preview, page.url, t('.view_live_html')) %>
|
|
44
|
-
<%= action_icon(:add, add_url, t('new', scope: 'refinery.admin.pages' ) ) %>
|
|
45
|
-
<%= action_icon(:edit, edit_url , t('edit', scope: 'refinery.admin.pages' ) ) %>
|
|
46
|
-
<%= action_icon(:delete, delete_url, t('delete', scope: 'refinery.admin.pages' ), delete_options ) if page.deletable? %>
|
|
10
|
+
<span class="actions">
|
|
11
|
+
<%= action_icon(:preview, page.url, t('.view_live_html')) %>
|
|
12
|
+
<%= action_icon(:add, refinery.new_admin_page_path(parent_id: page.id), t('.new')) %>
|
|
13
|
+
<%= action_icon(:edit, edit_url, t('.edit')) %>
|
|
14
|
+
<%= action_icon(:delete, refinery.admin_delete_page_path(page.nested_url),
|
|
15
|
+
t('.delete'),
|
|
16
|
+
class: "cancel confirm-delete",
|
|
17
|
+
data: { confirm: t('message', scope: 'refinery.admin.delete', title: translated_field(page, :title)) }
|
|
18
|
+
) if page.deletable? %>
|
|
47
19
|
</span>
|
|
48
20
|
</div>
|
|
49
21
|
|
|
50
22
|
<%= content_tag :ul, class: 'nested', data: { 'ajax-content': refinery.admin_children_pages_path(page.nested_url) } do %>
|
|
51
|
-
<%= render(partial: 'page', collection: page.children, cached:
|
|
23
|
+
<%= render(partial: 'page', collection: page.children, cached: ->(child_page) { child_page.self_and_descendants.to_a }) if Refinery::Pages.auto_expand_admin_tree %>
|
|
52
24
|
<% end %>
|
|
53
25
|
</li>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<%= content_tag :ul, id: 'sortable_list' do %>
|
|
2
|
-
<%= render partial: 'page', collection: @pages.roots, cached:
|
|
2
|
+
<%= render partial: 'page', collection: @pages.roots, cached: ->(child_page) { child_page.self_and_descendants } %>
|
|
3
3
|
<% end %>
|
|
4
4
|
|
|
5
5
|
<%= render '/refinery/admin/sortable_list', continue_reordering: !!local_assigns[:continue_reordering] %>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<%= render partial: 'page', collection: @page.children, cached:
|
|
1
|
+
<%= render partial: 'page', collection: @page.children, cached: ->(child_page) { child_page.self_and_descendants } %>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<%
|
|
2
2
|
link_args = defined?(link_to_arguments) ? link_to_arguments : {}
|
|
3
|
-
page_link_url =
|
|
3
|
+
page_link_url = Mobility.with_locale(params[:switch_locale]) { refinery.url_for(page_link.url) }
|
|
4
4
|
# current_link is relative so check against the relative url portion before conditionally making it absolute
|
|
5
5
|
linked = params[:current_link].present? && page_link_url == params[:current_link]
|
|
6
6
|
page_link_url = "#{[request.protocol, request.host_with_port].join}#{page_link_url}" if Refinery::Pages.absolute_page_links
|