effective_pages 3.1.1 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/admin/page_sections_controller.rb +13 -0
- data/app/datatables/effective_page_sections_datatable.rb +29 -0
- data/app/datatables/effective_pages_datatable.rb +4 -2
- data/app/datatables/effective_pages_menu_datatable.rb +4 -4
- data/app/helpers/effective_menus_helper.rb +9 -1
- data/app/helpers/effective_page_sections_helper.rb +24 -0
- data/app/models/effective/page.rb +24 -6
- data/app/models/effective/page_section.rb +49 -0
- data/app/views/admin/page_sections/_form.html.haml +7 -0
- data/app/views/admin/page_sections/_form_page_section.html.haml +25 -0
- data/app/views/admin/pages/_form_menu.html.haml +3 -2
- data/app/views/admin/pages/_form_page.html.haml +12 -13
- data/app/views/effective/pages/_menu.html.haml +10 -8
- data/app/views/effective/pages/_page_menu.html.haml +9 -5
- data/config/effective_pages.rb +1 -0
- data/config/routes.rb +1 -0
- data/db/migrate/01_create_effective_pages.rb.erb +25 -0
- data/lib/effective_pages/engine.rb +1 -0
- data/lib/effective_pages/version.rb +1 -1
- data/lib/effective_pages.rb +1 -1
- data/lib/generators/effective_pages/install_generator.rb +1 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2620fbfec6b912fd31b7d9821fe5ef73eecbfb4c509063883f8c144a2aa66d30
|
4
|
+
data.tar.gz: d75935c05702f1328e32058f45874999a3b3b3f7f7becab1202c4d18b9dee743
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dd4484e144bbbb2287dc399eb93bbae86b423c05fea8ca0bd0f7d5f716e384ebc1d935eef964166517b6358d1565f539c32894d6a2992e851a3e2d9104a6192
|
7
|
+
data.tar.gz: f1fa33f1bd839164cb281f23a3439f4d624458120061d7aeb7a0c2e16703d7b46d7043ae4abaf4878cea8bbf65e5a8a0710a02c00fbe0c8185f9df28e1e3e46c
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Admin
|
2
|
+
class PageSectionsController < ApplicationController
|
3
|
+
before_action(:authenticate_user!) if defined?(Devise)
|
4
|
+
before_action { EffectiveResources.authorize!(self, :admin, :effective_pages) }
|
5
|
+
|
6
|
+
include Effective::CrudController
|
7
|
+
|
8
|
+
def permitted_params
|
9
|
+
params.require(:effective_page_section).permit!
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class EffectivePageSectionsDatatable < Effective::Datatable
|
2
|
+
|
3
|
+
datatable do
|
4
|
+
order :name, :asc
|
5
|
+
length :all
|
6
|
+
|
7
|
+
col :id, visible: false
|
8
|
+
col :updated_at, visible: false
|
9
|
+
|
10
|
+
col :name
|
11
|
+
col :hint
|
12
|
+
|
13
|
+
col :title
|
14
|
+
col :rich_text_body
|
15
|
+
|
16
|
+
col :files
|
17
|
+
|
18
|
+
col :link_label, visible: false
|
19
|
+
col :link_url, visible: false
|
20
|
+
col :caption, visible: false
|
21
|
+
|
22
|
+
actions_col
|
23
|
+
end
|
24
|
+
|
25
|
+
collection do
|
26
|
+
Effective::PageSection.deep.all
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -15,8 +15,6 @@ class EffectivePagesDatatable < Effective::Datatable
|
|
15
15
|
col :updated_at, visible: false
|
16
16
|
|
17
17
|
col :title
|
18
|
-
col :menu_title
|
19
|
-
col :menu_name
|
20
18
|
|
21
19
|
col :slug do |page|
|
22
20
|
link_to(page.slug, effective_pages.page_path(page), target: '_blank')
|
@@ -27,6 +25,10 @@ class EffectivePagesDatatable < Effective::Datatable
|
|
27
25
|
col :layout, visible: false
|
28
26
|
col :tempate, visible: false
|
29
27
|
|
28
|
+
col :menu_name
|
29
|
+
col :menu_title
|
30
|
+
col :menu_group
|
31
|
+
|
30
32
|
col :menu_url, visible: false
|
31
33
|
col :menu_parent, search: { collection: admin_menu_parent_collection(), grouped: true }
|
32
34
|
col :menu_position, visible: false
|
@@ -16,12 +16,12 @@ class EffectivePagesMenuDatatable < Effective::Datatable
|
|
16
16
|
|
17
17
|
# We only support depth 2 and 3.
|
18
18
|
col :menu_children, label: 'Children' do |page|
|
19
|
-
page.menu_children.map do |child|
|
19
|
+
page.menu_children.group_by(&:menu_group).values.flatten.map do |child|
|
20
20
|
content_tag(:div, class: 'col-resource_item') do
|
21
|
-
link = link_to(child, effective_pages.edit_admin_page_path(child))
|
21
|
+
link = link_to(child.admin_menu_label, effective_pages.edit_admin_page_path(child))
|
22
22
|
|
23
|
-
list = child.menu_children.map do |child|
|
24
|
-
content_tag(:li, link_to(child, effective_pages.edit_admin_page_path(child)))
|
23
|
+
list = child.menu_children.group_by(&:menu_group).values.flatten.map do |child|
|
24
|
+
content_tag(:li, link_to(child.admin_menu_label, effective_pages.edit_admin_page_path(child)))
|
25
25
|
end
|
26
26
|
|
27
27
|
link + (content_tag(:ul, list.join.html_safe) if list.present?).to_s
|
@@ -67,7 +67,15 @@ module EffectiveMenusHelper
|
|
67
67
|
# You can only select root level pages and immediate children
|
68
68
|
pages.map do |page|
|
69
69
|
[[page.to_s, page.id, page.menu_name]] + page.menu_children.map do |child|
|
70
|
-
|
70
|
+
label = content_tag(:div) do
|
71
|
+
arrow = "→"
|
72
|
+
group = content_tag(:span, child.menu_group, class: 'badge badge-info') if child.menu_group.present?
|
73
|
+
title = child.menu_to_s
|
74
|
+
|
75
|
+
[arrow, group, title].compact.join(' ').html_safe
|
76
|
+
end
|
77
|
+
|
78
|
+
[child.to_s, child.to_param, { 'data-html': label }, child.menu_name]
|
71
79
|
end
|
72
80
|
end.flatten(1).group_by(&:last)
|
73
81
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EffectivePageSectionsHelper
|
4
|
+
|
5
|
+
def effective_page_sections
|
6
|
+
@_effective_page_sections ||= Effective::PageSection.all
|
7
|
+
end
|
8
|
+
|
9
|
+
def render_page_section(name, &block)
|
10
|
+
raise('expected a name') unless name.present?
|
11
|
+
|
12
|
+
name = name.to_s
|
13
|
+
|
14
|
+
page_section = effective_page_sections.find { |ps| ps.name == name }
|
15
|
+
raise("unable to find page section with name #{name}") unless page_section.present?
|
16
|
+
|
17
|
+
if block_given?
|
18
|
+
yield(page_section); nil
|
19
|
+
else
|
20
|
+
page_section.rich_text_body.to_s.html_safe
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -29,12 +29,13 @@ module Effective
|
|
29
29
|
slug :string
|
30
30
|
|
31
31
|
# Menu stuff
|
32
|
-
menu :boolean
|
33
|
-
menu_name :string
|
32
|
+
menu :boolean # Should this be displayed on the menu at all?
|
33
|
+
menu_name :string # When I'm a root level item, this is the menu I render underneath
|
34
|
+
menu_group :string # Used for design. Group by menu_group to display full dropdowns.
|
34
35
|
|
35
|
-
menu_title :string
|
36
|
-
menu_url :string
|
37
|
-
menu_position :integer
|
36
|
+
menu_title :string # Displayed on the menu instead of title
|
37
|
+
menu_url :string # Redirect to this url instead of the page url
|
38
|
+
menu_position :integer # Position in the menu
|
38
39
|
|
39
40
|
# Access
|
40
41
|
roles_mask :integer
|
@@ -59,7 +60,10 @@ module Effective
|
|
59
60
|
validates :layout, presence: true
|
60
61
|
validates :template, presence: true
|
61
62
|
|
62
|
-
validates :menu_name, if: -> { menu_root? && EffectivePages.menus.present? }
|
63
|
+
validates :menu_name, presence: true, if: -> { menu_root? && EffectivePages.menus.present? }
|
64
|
+
|
65
|
+
# Doesn't make sense for a top level item to have a menu group
|
66
|
+
validates :menu_group, absence: true, if: -> { menu_root? && EffectivePages.menus.present? }
|
63
67
|
|
64
68
|
# validates :menu_position, if: -> { menu? },
|
65
69
|
# presence: true, uniqueness: { scope: [:menu_name, :menu_parent_id] }
|
@@ -69,6 +73,7 @@ module Effective
|
|
69
73
|
scope :draft, -> { where(draft: true) }
|
70
74
|
scope :published, -> { where(draft: false) }
|
71
75
|
scope :sorted, -> { order(:title) }
|
76
|
+
|
72
77
|
scope :on_menu, -> { where(menu: true) }
|
73
78
|
scope :except_home, -> { where.not(title: 'Home') }
|
74
79
|
|
@@ -79,10 +84,23 @@ module Effective
|
|
79
84
|
scope :for_menu_root, -> (name) { for_menu(name).menu_deep.root_level }
|
80
85
|
scope :root_level, -> { where(menu_parent_id: nil) }
|
81
86
|
|
87
|
+
scope :menu_root_with_children, -> { menu_parents.where(menu_parent_id: nil) }
|
88
|
+
scope :menu_roots, -> { where(menu: true).where(menu_parent_id: nil) }
|
89
|
+
scope :menu_parents, -> { where(menu: true).where(id: Effective::Page.select('menu_parent_id')) }
|
90
|
+
scope :menu_children, -> { where(menu: true).where.not(menu_parent_id: nil) }
|
91
|
+
|
92
|
+
scope :for_sitemap, -> {
|
93
|
+
published.where(menu: false).or(published.where(menu: true).where.not(id: menu_root_with_children))
|
94
|
+
}
|
95
|
+
|
82
96
|
def to_s
|
83
97
|
title
|
84
98
|
end
|
85
99
|
|
100
|
+
def menu_to_s
|
101
|
+
(menu_title.presence || title)
|
102
|
+
end
|
103
|
+
|
86
104
|
# As per has_many_rich_texts
|
87
105
|
def body
|
88
106
|
rich_text_body
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Effective
|
2
|
+
class PageSection < ActiveRecord::Base
|
3
|
+
attr_accessor :current_user
|
4
|
+
|
5
|
+
# Not used
|
6
|
+
belongs_to :owner, polymorphic: true, optional: true
|
7
|
+
|
8
|
+
has_many_rich_texts
|
9
|
+
has_many_attached :files
|
10
|
+
|
11
|
+
log_changes if respond_to?(:log_changes)
|
12
|
+
|
13
|
+
self.table_name = EffectivePages.page_sections_table_name.to_s
|
14
|
+
|
15
|
+
effective_resource do
|
16
|
+
name :string # Unique name of this page section
|
17
|
+
|
18
|
+
title :string
|
19
|
+
caption :string
|
20
|
+
|
21
|
+
link_label :string
|
22
|
+
link_url :string
|
23
|
+
|
24
|
+
hint :text
|
25
|
+
|
26
|
+
timestamps
|
27
|
+
end
|
28
|
+
|
29
|
+
validates :name, presence: true, uniqueness: true
|
30
|
+
validates :title, presence: true, length: { maximum: 255 }
|
31
|
+
|
32
|
+
validates :link_url, presence: true, if: -> { link_label.present? }
|
33
|
+
validates :link_url, absence: true, if: -> { link_label.blank? }
|
34
|
+
|
35
|
+
scope :deep, -> { with_attached_files.includes(:rich_texts) }
|
36
|
+
scope :sorted, -> { order(:name) }
|
37
|
+
|
38
|
+
def to_s
|
39
|
+
name.presence || 'page section'
|
40
|
+
end
|
41
|
+
|
42
|
+
# As per has_many_rich_texts
|
43
|
+
def body
|
44
|
+
rich_text_body
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
= effective_form_with(model: [:admin, page_section], engine: true) do |f|
|
2
|
+
- if f.object.new_record?
|
3
|
+
= f.text_field :name, hint: 'The name of this region must be unique'
|
4
|
+
- else
|
5
|
+
= f.static_field :name
|
6
|
+
|
7
|
+
- if f.object.hint.present?
|
8
|
+
.mb-4= f.object.hint.html_safe
|
9
|
+
|
10
|
+
= f.text_field :title
|
11
|
+
|
12
|
+
- if defined?(EffectiveArticleEditor)
|
13
|
+
= f.article_editor :rich_text_body, label: 'Body', hint: 'The main content'
|
14
|
+
- else
|
15
|
+
= f.rich_text_area :rich_text_body, label: 'Body', hint: 'The main content'
|
16
|
+
|
17
|
+
.row
|
18
|
+
.col= f.text_field :link_label
|
19
|
+
.col= f.url_field :link_url
|
20
|
+
|
21
|
+
= f.file_field :files, label: 'Attachment'
|
22
|
+
|
23
|
+
= f.text_field :caption
|
24
|
+
|
25
|
+
= effective_submit(f)
|
@@ -14,14 +14,15 @@
|
|
14
14
|
= f.hidden_field :menu_name, value: menus.first
|
15
15
|
|
16
16
|
= f.show_if :menu_root_level, false do
|
17
|
-
= f.select :menu_parent_id, admin_menu_parent_collection(f.object), required: true, grouped: true
|
17
|
+
= f.select :menu_parent_id, admin_menu_parent_collection(f.object), required: true, grouped: true, hint: 'Displayed on the menu underneath this parent'
|
18
|
+
= f.text_field :menu_group, hint: 'Displayed on the menu in this group or column'
|
18
19
|
|
19
20
|
= f.text_field :menu_title, hint: "Display this title on menus instead of full page title"
|
20
21
|
|
21
22
|
= f.text_field :menu_url, label: "Redirect to path or url instead of displaying page",
|
22
23
|
hint: "Must start with http(s):// or /"
|
23
24
|
|
24
|
-
= f
|
25
|
+
= effective_submit(f)
|
25
26
|
|
26
27
|
- if page.menu_parent.present?
|
27
28
|
.mb-4
|
@@ -25,21 +25,20 @@
|
|
25
25
|
|
26
26
|
= render partial: '/admin/pages/additional_fields', locals: { page: page, form: f, f: f }
|
27
27
|
|
28
|
-
- if f.object.persisted?
|
29
|
-
-
|
30
|
-
.
|
31
|
-
%
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
= render '/admin/pages/rich_text_areas', page: page, f: f
|
28
|
+
- if f.object.persisted? && f.object.menu_root_with_children?
|
29
|
+
.alert.alert-info.my-3.pl-0
|
30
|
+
%ul.mb-0
|
31
|
+
%li This page is a top level menu item with at least one child page
|
32
|
+
%li It will render on the menu as a dropdown link
|
33
|
+
%li Users will not be able to click access page via the menu
|
34
|
+
%li Visiting the page URL directly will return a 404 error
|
35
|
+
%li If you want this page to be accessible while also being a top level menu item, it needs to have no child pages
|
36
|
+
|
37
|
+
- if f.object.persisted? && !f.object.menu_root_with_children?
|
38
|
+
= render '/admin/pages/rich_text_areas', page: page, f: f
|
40
39
|
|
41
40
|
-# This is for duplicate
|
42
41
|
- if f.object.new_record? && f.object.rich_texts.present?
|
43
|
-
= render
|
42
|
+
= render '/admin/pages/rich_text_areas', page: page, f: f
|
44
43
|
|
45
44
|
= effective_submit(f)
|
@@ -10,13 +10,15 @@
|
|
10
10
|
- menu_children = page.menu_children
|
11
11
|
|
12
12
|
- if menu_children.blank?
|
13
|
-
= nav_link_to(
|
13
|
+
= nav_link_to(page.menu_to_s, (page.menu_url.presence || effective_pages.page_path(page)))
|
14
14
|
|
15
|
-
-
|
16
|
-
= nav_dropdown(page.
|
17
|
-
- menu_children.each do |
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
- if menu_children.present?
|
16
|
+
= nav_dropdown(page.menu_to_s, groups: true) do
|
17
|
+
- menu_children.group_by(&:menu_group).each do |menu_group, pages|
|
18
|
+
= nav_dropdown_group(menu_group) do
|
19
|
+
- pages.each do |page|
|
20
|
+
- next unless EffectiveResources.authorized?(self, :show, page)
|
21
|
+
- next if (page.authenticate_user || page.roles.present?) && current_user.blank?
|
22
|
+
- next if page.roles.present? && (current_user.roles & page.roles).blank?
|
21
23
|
|
22
|
-
|
24
|
+
= nav_link_to(page.menu_to_s, (page.menu_url.presence || effective_pages.page_path(page)))
|
@@ -5,9 +5,13 @@
|
|
5
5
|
- if menu_children.blank? && page.menu_parent&.menu_children.present?
|
6
6
|
- menu_children = page.menu_parent&.menu_children
|
7
7
|
|
8
|
-
- menu_children.each do |
|
9
|
-
-
|
10
|
-
|
11
|
-
- next if page.roles.present? && (current_user.roles & page.roles).blank?
|
8
|
+
- menu_children.group_by(&:menu_group).each do |menu_group, pages|
|
9
|
+
- if menu_group.present?
|
10
|
+
%h6= menu_group
|
12
11
|
|
13
|
-
|
12
|
+
- pages.each do |page|
|
13
|
+
- next unless EffectiveResources.authorized?(self, :show, page)
|
14
|
+
- next if (page.authenticate_user || page.roles.present?) && current_user.blank?
|
15
|
+
- next if page.roles.present? && (current_user.roles & page.roles).blank?
|
16
|
+
|
17
|
+
= nav_link_to(page.menu_to_s, (page.menu_url.presence || effective_pages.page_path(page)))
|
data/config/effective_pages.rb
CHANGED
data/config/routes.rb
CHANGED
@@ -15,8 +15,12 @@ class CreateEffectivePages < ActiveRecord::Migration[4.2]
|
|
15
15
|
t.integer :roles_mask, default: 0
|
16
16
|
|
17
17
|
t.integer :menu_parent_id
|
18
|
+
|
18
19
|
t.boolean :menu, default: false
|
20
|
+
|
19
21
|
t.string :menu_name
|
22
|
+
t.string :menu_group
|
23
|
+
|
20
24
|
t.string :menu_title
|
21
25
|
t.string :menu_url
|
22
26
|
t.integer :menu_position
|
@@ -26,10 +30,31 @@ class CreateEffectivePages < ActiveRecord::Migration[4.2]
|
|
26
30
|
end
|
27
31
|
|
28
32
|
add_index <%= @pages_table_name %>, :slug, :unique => true
|
33
|
+
|
34
|
+
create_table <%= @page_sections_table_name %> do |t|
|
35
|
+
t.string :owner_type
|
36
|
+
t.integer :owner_id
|
37
|
+
|
38
|
+
t.string :name
|
39
|
+
|
40
|
+
t.string :title
|
41
|
+
t.string :caption
|
42
|
+
|
43
|
+
t.string :link_label
|
44
|
+
t.string :link_url
|
45
|
+
|
46
|
+
t.text :hint
|
47
|
+
|
48
|
+
t.datetime :updated_at
|
49
|
+
t.datetime :created_at
|
50
|
+
end
|
51
|
+
|
52
|
+
add_index <%= @page_sections_table_name %>, :name, :unique => true
|
29
53
|
end
|
30
54
|
|
31
55
|
def self.down
|
32
56
|
drop_table <%= @pages_table_name %>
|
57
|
+
drop_table <%= @page_sections_table_name %>
|
33
58
|
end
|
34
59
|
|
35
60
|
end
|
data/lib/effective_pages.rb
CHANGED
@@ -7,7 +7,7 @@ require 'effective_pages/version'
|
|
7
7
|
module EffectivePages
|
8
8
|
def self.config_keys
|
9
9
|
[
|
10
|
-
:pages_table_name,
|
10
|
+
:pages_table_name, :page_sections_table_name,
|
11
11
|
:pages_path, :excluded_pages, :layouts_path, :excluded_layouts,
|
12
12
|
:site_og_image, :site_og_image_width, :site_og_image_height,
|
13
13
|
:site_title, :site_title_suffix, :fallback_meta_description,
|
@@ -21,6 +21,7 @@ module EffectivePages
|
|
21
21
|
|
22
22
|
def create_migration_file
|
23
23
|
@pages_table_name = ':' + EffectivePages.pages_table_name.to_s
|
24
|
+
@page_sections_table_name = ':' + EffectivePages.page_sections_table_name.to_s
|
24
25
|
migration_template ('../' * 3) + 'db/migrate/01_create_effective_pages.rb.erb', 'db/migrate/create_effective_pages.rb'
|
25
26
|
end
|
26
27
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_pages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -76,14 +76,20 @@ files:
|
|
76
76
|
- MIT-LICENSE
|
77
77
|
- README.md
|
78
78
|
- app/controllers/admin/menus_controller.rb
|
79
|
+
- app/controllers/admin/page_sections_controller.rb
|
79
80
|
- app/controllers/admin/pages_controller.rb
|
80
81
|
- app/controllers/effective/pages_controller.rb
|
82
|
+
- app/datatables/effective_page_sections_datatable.rb
|
81
83
|
- app/datatables/effective_pages_datatable.rb
|
82
84
|
- app/datatables/effective_pages_menu_datatable.rb
|
83
85
|
- app/helpers/effective_menus_helper.rb
|
86
|
+
- app/helpers/effective_page_sections_helper.rb
|
84
87
|
- app/helpers/effective_pages_helper.rb
|
85
88
|
- app/models/effective/page.rb
|
89
|
+
- app/models/effective/page_section.rb
|
86
90
|
- app/views/admin/menus/index.html.haml
|
91
|
+
- app/views/admin/page_sections/_form.html.haml
|
92
|
+
- app/views/admin/page_sections/_form_page_section.html.haml
|
87
93
|
- app/views/admin/pages/_additional_fields.html.haml
|
88
94
|
- app/views/admin/pages/_form.html.haml
|
89
95
|
- app/views/admin/pages/_form_access.html.haml
|