effective_pages 3.0.10 → 3.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce5bc87bbf145bfcf88dfcf9b5efb9ab778876b4d103cc0a2b2cabfbae9f0f05
4
- data.tar.gz: 613c1b974148fd8f0b31bcd204ce5cbd979545baf09d08468f9bb44f21ee4ab5
3
+ metadata.gz: 0f090f6237de5e5aabd329729b2c1d9b2098307bfd46510d4663b95783d5a233
4
+ data.tar.gz: c8516b8b3e013e8b41660e03cc14a519eee7f0897a80ab0e1cdc6356fd7ec977
5
5
  SHA512:
6
- metadata.gz: 51e0ba41ee3f97be0fe574b4cd017ba47fe3421e0d7827c0d1fad8522f4d1194ff8dc4e7c721c06d4d0b84b8414ba31a201ccea0ced2ae5dbc43148f1512b216
7
- data.tar.gz: 7ff18a08e8d591bc473609244604b73bd8f24a42cccf579492db53d24fb536b7e6c460f36718ea35fa59693ba9aa437fab6806c02e6729565a4330d1cbaf4e42
6
+ metadata.gz: fb40c0b8c3f7c86ae0374d183bd3217d737594637f469bffb8b93a91bd506a9b20101eb4439698939e835df00b33a38b6c16faf952aa728db9efbda35289c4aa
7
+ data.tar.gz: e9dd9e7c455f3f38be630aac0a2cea2d9fee080bb319dda6337bc8a5f4c90c62b8fd8021bb70795283c53a150c31ec22beae83a8946e6adaa7b3494150baa815
@@ -8,6 +8,8 @@ module Effective
8
8
 
9
9
  @page = @pages.find(params[:id])
10
10
 
11
+ raise ActionController::RoutingError.new('Not Found') if @page.menu_root_with_children?
12
+
11
13
  if @page.authenticate_user? || @page.roles.present?
12
14
  authenticate_user!
13
15
  end
@@ -22,9 +24,8 @@ module Effective
22
24
  if EffectiveResources.authorized?(self, :admin, :effective_pages)
23
25
  flash.now[:warning] = [
24
26
  'Hi Admin!',
25
- ('You are viewing a hidden page.' unless @page.published?),
26
- 'Click here to',
27
- ("<a href='#{effective_pages.edit_admin_page_path(@page)}' class='alert-link'>edit page settings</a>.")
27
+ ('You are viewing a draft page.' unless @page.published?),
28
+ ("<a href='#{effective_pages.edit_admin_page_path(@page)}' class='alert-link'>Click here to edit this page</a>.")
28
29
  ].compact.join(' ')
29
30
  end
30
31
 
@@ -1,10 +1,10 @@
1
1
  class EffectivePagesDatatable < Effective::Datatable
2
2
 
3
3
  filters do
4
+ scope :all
4
5
  scope :published
5
6
  scope :draft
6
7
  scope :on_menu
7
- scope :all
8
8
  end
9
9
 
10
10
  datatable do
@@ -15,6 +15,8 @@ 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
18
20
 
19
21
  col :slug do |page|
20
22
  link_to(page.slug, effective_pages.page_path(page), target: '_blank')
@@ -25,10 +27,8 @@ class EffectivePagesDatatable < Effective::Datatable
25
27
  col :layout, visible: false
26
28
  col :tempate, visible: false
27
29
 
28
- col :menu
29
- col :menu_name, visible: false
30
30
  col :menu_url, visible: false
31
- col :menu_parent, visible: false
31
+ col :menu_parent, search: { collection: admin_menu_parent_collection(), grouped: true }
32
32
  col :menu_position, visible: false
33
33
 
34
34
  col :authenticate_user, visible: false
@@ -13,18 +13,34 @@ class EffectivePagesMenuDatatable < Effective::Datatable
13
13
 
14
14
  col :menu_url, label: 'Redirect Url'
15
15
  col :menu_position, label: 'Position', visible: false
16
- col :menu_children, label: 'Children'
16
+
17
+ # We only support depth 2 and 3.
18
+ col :menu_children, label: 'Children' do |page|
19
+ page.menu_children.map do |child|
20
+ content_tag(:div, class: 'col-resource_item') do
21
+ link = link_to(child, effective_pages.edit_admin_page_path(child))
22
+
23
+ list = child.menu_children.map do |child|
24
+ content_tag(:li, link_to(child, effective_pages.edit_admin_page_path(child)))
25
+ end
26
+
27
+ link + (content_tag(:ul, list.join.html_safe) if list.present?).to_s
28
+ end
29
+ end.join.html_safe
30
+ end
17
31
 
18
32
  actions_col(new: false, destroy: false)
19
33
  end
20
34
 
21
35
  collection(apply_belongs_to: false) do
22
- scope = Effective::Page.deep.for_menu(menu)
36
+ scope = Effective::Page.deep.menuable
37
+
38
+ if attributes[:menu].present?
39
+ scope = scope.root_level.for_menu(menu)
40
+ end
23
41
 
24
- scope = if attributes[:menu_parent_id].present?
25
- scope.where(menu_parent_id: attributes[:menu_parent_id])
26
- else
27
- scope.where(menu_parent_id: nil)
42
+ if attributes[:page_id].present?
43
+ scope = scope.where(menu_parent_id: attributes[:page_id])
28
44
  end
29
45
 
30
46
  scope
@@ -12,18 +12,24 @@ module EffectiveMenusHelper
12
12
  content_tag(:ul, options) { render('effective/pages/menu', menu: menu) }
13
13
  end
14
14
 
15
+ def render_page_menu(page, options = {}, &block)
16
+ raise('expected a page with menu true') unless page.kind_of?(Effective::Page) && page.menu?
17
+
18
+ content_tag(:ul, options) { render('effective/pages/page_menu', page: page) }
19
+ end
20
+
15
21
  def render_breadcrumbs(menu, page = @page, root: 'Home')
16
22
  return breadcrumbs_root_url(page, root: root) if request.path == '/'
17
23
  return breadcrumbs_fallback(page, root: root) unless page.kind_of?(Effective::Page)
18
24
 
19
- parents = [page.menu_parent].compact
25
+ parents = [page.menu_parent&.menu_parent, page.menu_parent].compact
20
26
 
21
27
  content_tag(:ol, class: 'breadcrumb') do
22
28
  (
23
29
  [content_tag(:li, link_to(root, root_path, title: root), class: 'breadcrumb-item')] +
24
30
  parents.map do |page|
25
31
  url = (page.menu_url.presence || effective_pages.page_path(page))
26
- content_tag(:li, link_to(page, url, title: page.title), class: 'breadcrumb-item')
32
+ content_tag(:li, link_to(page, (page.menu_root_with_children? ? '#' : url), title: page.title), class: 'breadcrumb-item')
27
33
  end +
28
34
  [content_tag(:li, page, class: 'breadcrumb-item active', 'aria-current': 'page')]
29
35
  ).join.html_safe
@@ -49,4 +55,22 @@ module EffectiveMenusHelper
49
55
  end
50
56
  end
51
57
 
58
+ def admin_menu_parent_collection(page = nil)
59
+ raise('expected a page') if page.present? && !page.kind_of?(Effective::Page)
60
+
61
+ pages = Effective::Page.menuable.root_level.where.not(id: page)
62
+
63
+ if EffectivePages.max_menu_depth == 2
64
+ # You can only select root level pages
65
+ pages.group_by(&:menu_name)
66
+ elsif EffectivePages.max_menu_depth == 3
67
+ # You can only select root level pages and immediate children
68
+ pages.map do |page|
69
+ [[page.to_s, page.id, page.menu_name]] + page.menu_children.map do |child|
70
+ [' -- ' + child.to_s, child.id, child.menu_name]
71
+ end
72
+ end.flatten(1).group_by(&:last)
73
+ end
74
+ end
75
+
52
76
  end
@@ -59,7 +59,7 @@ module Effective
59
59
  validates :layout, presence: true
60
60
  validates :template, presence: true
61
61
 
62
- validates :menu_name, if: -> { menu? && EffectivePages.menus.present? }, presence: true
62
+ validates :menu_name, if: -> { menu_root? && EffectivePages.menus.present? }, presence: true
63
63
 
64
64
  # validates :menu_position, if: -> { menu? },
65
65
  # presence: true, uniqueness: { scope: [:menu_name, :menu_parent_id] }
@@ -72,7 +72,7 @@ module Effective
72
72
  scope :on_menu, -> { where(menu: true) }
73
73
  scope :except_home, -> { where.not(title: 'Home') }
74
74
 
75
- scope :menuable, -> { where(menu: true).order(:menu_position) }
75
+ scope :menuable, -> { published.where(menu: true).order(:menu_position) }
76
76
  scope :menu_deep, -> { includes(:menu_parent, :menu_children) }
77
77
 
78
78
  scope :for_menu, -> (name) { menuable.where(menu_name: name) }
@@ -114,8 +114,26 @@ module Effective
114
114
  duplicate.tap { |page| page.save! }
115
115
  end
116
116
 
117
+ # When true, this should not appear in sitemap.xml and should return 404 if visited
118
+ def menu_root_with_children?
119
+ menu_root? && menu_parent?
120
+ end
121
+
122
+ # This is for the form
117
123
  def menu_root_level
118
- menu? && menu_parent.blank?
124
+ menu_root?
125
+ end
126
+
127
+ def menu_root?
128
+ menu? && menu_parent_id.blank?
129
+ end
130
+
131
+ def menu_parent?
132
+ menu? && menu_children.to_a.present?
133
+ end
134
+
135
+ def menu_child?
136
+ menu? && menu_parent_id.present?
119
137
  end
120
138
 
121
139
  end
@@ -1,11 +1,11 @@
1
1
  %h1= @page_title
2
2
 
3
3
  %p
4
- Click Reorder to drag & drop reorder the menu.
4
+ Click Reorder to drag & drop reorder menu items.
5
5
  Edit an item to reorder its children items.
6
6
 
7
7
  - EffectivePages.menus.each do |menu|
8
- %h2 #{menu.to_s.titleize} Menu
8
+ %h3 #{menu.to_s.titleize} Menu
9
9
  - datatable = EffectivePagesMenuDatatable.new(menu: menu)
10
10
  = render_datatable(datatable, simple: true, inline: true)
11
- %hr
11
+ %hr.my-5
@@ -1,13 +1,6 @@
1
- - if inline_datatable? && inline_datatable.attributes[:menu]
2
- - menu = inline_datatable.attributes[:menu]
3
- - datatable = EffectivePagesMenuDatatable.new(menu: menu, menu_parent_id: page.id)
4
-
1
+ - if inline_datatable?
5
2
  = render '/admin/pages/form_menu', page: page
6
3
 
7
- - if datatable.present?(self)
8
- %h3 Children
9
- = render_datatable(datatable, simple: true, inline: true)
10
-
11
4
  - else
12
5
  = tabs do
13
6
  = tab 'Page' do
@@ -18,10 +11,6 @@
18
11
  = tab 'Menu' do
19
12
  = render '/admin/pages/form_menu', page: page
20
13
 
21
- - unless page.menu_root_level
22
- = tab 'Content' do
23
- = render '/admin/pages/form_content', page: page
24
-
25
14
  = tab 'Access' do
26
15
  = render '/admin/pages/form_access', page: page
27
16
 
@@ -1,10 +1,7 @@
1
1
  = effective_form_with(model: page, url: page.persisted? ? effective_pages.admin_page_path(page.id) : effective_pages.admin_pages_path) do |f|
2
- = f.check_box :authenticate_user, label: 'Yes, the user must be be signed in to view this page'
2
+ = f.check_box :authenticate_user, label: 'Restrict the page to any signed in user'
3
3
 
4
4
  - if EffectivePages.use_effective_roles
5
- = f.checks :roles, EffectiveRoles.roles_collection(f.object)
6
-
7
- %p.text-hint
8
- * leave blank for a regular public page that anyone can view
5
+ = f.checks :roles, EffectiveRoles.roles_collection(f.object), label: 'Restrict the page to any signed in user that has the role:'
9
6
 
10
7
  = f.submit
@@ -1,20 +1,20 @@
1
1
  = effective_form_with(model: page, url: page.persisted? ? effective_pages.admin_page_path(page.id) : effective_pages.admin_pages_path) do |f|
2
- = f.check_box :menu, label: 'Yes, display this page on the menu'
2
+ = f.check_box :menu, label: 'Yes, display this page in a menu'
3
3
 
4
4
  = f.show_if :menu, true do
5
5
 
6
- - if (menus = EffectivePages.menus).length > 1
7
- = f.select :menu_name, menus
8
- - else
9
- = f.hidden_field :menu_name, value: menus.first
10
-
11
- = f.check_box :menu_root_level, label: "This is a top level menu item. Do not show page content."
6
+ = f.check_box :menu_root_level, label: "This is a top level menu item. It has no content and cannot be viewed, but can have children pages"
12
7
 
13
8
  = f.show_if :menu_root_level, true do
14
9
  = f.hidden_field :menu_parent_id, value: nil
15
10
 
11
+ - if (menus = EffectivePages.menus).length > 1
12
+ = f.select :menu_name, menus, label: 'Top level menu item in this menu'
13
+ - else
14
+ = f.hidden_field :menu_name, value: menus.first
15
+
16
16
  = f.show_if :menu_root_level, false do
17
- = f.select :menu_parent_id, Effective::Page.menuable.root_level.where.not(id: f.object), required: true
17
+ = f.select :menu_parent_id, admin_menu_parent_collection(f.object), required: true, grouped: true
18
18
 
19
19
  = f.text_field :menu_title, hint: "Display this title on menus instead of full page title"
20
20
 
@@ -22,3 +22,13 @@
22
22
  hint: "Must start with http(s):// or /"
23
23
 
24
24
  = f.submit
25
+
26
+ - if page.menu_parent.present?
27
+ .mb-4
28
+ %h3 Parent
29
+ = link_to(page.menu_parent, effective_pages.edit_admin_page_path(page.menu_parent))
30
+
31
+ - if page.menu_children.present?
32
+ %h3 Children
33
+ - datatable = EffectivePagesMenuDatatable.new(page: page)
34
+ = render_datatable(datatable, simple: true, inline: true)
@@ -1,11 +1,12 @@
1
1
  = effective_form_with(model: page, url: page.persisted? ? effective_pages.admin_page_path(page.id) : effective_pages.admin_pages_path) do |f|
2
- = f.text_field :title, hint: 'The title of your page.'
2
+
3
+ = f.text_field :title
3
4
 
4
5
  = f.check_box :draft,
5
- label: 'Save this page as a draft. It will not be accessible on the website.'
6
+ label: 'Save this page as a draft. It will not appear in a menu and can only be accessed by admin users.'
6
7
 
7
8
  = f.text_field :meta_description,
8
- hint: "A one or two sentence summary of this page. Appears on Google search results underneath the page title.",
9
+ hint: "150 character summary. Appears on Google search results underneath the page title. ",
9
10
  input_html: { maxlength: 150 }
10
11
 
11
12
  - if (layouts = EffectivePages.layouts).length > 1
@@ -24,6 +25,19 @@
24
25
 
25
26
  = render partial: '/admin/pages/additional_fields', locals: { page: page, form: f, f: f }
26
27
 
28
+ - if f.object.persisted?
29
+ - if page.menu_root? && page.menu_parent?
30
+ .alert.alert-info.my-3.pl-0
31
+ %ul.mb-0
32
+ %li This page is a top level menu item with at least one child page
33
+ %li It will render on the menu as a dropdown link
34
+ %li Users will not be able to click access page via the menu
35
+ %li Visiting the page URL directly will return a 404 error
36
+ %li If you want this page to be accessible while also being a top level menu item, it needs to have no child pages
37
+
38
+ - else
39
+ = render '/admin/pages/rich_text_areas', page: page, f: f
40
+
27
41
  -# This is for duplicate
28
42
  - if f.object.new_record? && f.object.rich_texts.present?
29
43
  = render partial: '/admin/pages/rich_text_areas', locals: { page: page, form: f, f: f }
@@ -1,2 +1,6 @@
1
- = f.rich_text_area :rich_text_body, label: 'Body', hint: 'The main body of your page'
2
- = f.rich_text_area :rich_text_sidebar, label: 'Sidebar', hint: 'The sidebar content of your page'
1
+ - if defined?(EffectiveArticleEditor)
2
+ = f.article_editor :rich_text_body, label: 'Body', hint: 'The main body of your page'
3
+ = f.article_editor :rich_text_sidebar, label: 'Sidebar', hint: 'The sidebar content of your page'
4
+ - else
5
+ = f.rich_text_area :rich_text_body, label: 'Body', hint: 'The main body of your page'
6
+ = f.rich_text_area :rich_text_sidebar, label: 'Sidebar', hint: 'The sidebar content of your page'
@@ -1,15 +1,17 @@
1
1
  - raise('expected a menu') unless menu.present?
2
2
  - menu = menu.to_s
3
3
 
4
+ - # Renders menu_root? level pages and their immediate children
4
5
  - Effective::Page.for_menu_root(menu).each do |page|
5
6
  - next unless EffectiveResources.authorized?(self, :show, page)
6
7
  - next if (page.authenticate_user || page.roles.present?) && current_user.blank?
7
8
  - next if page.roles.present? && (current_user.roles & page.roles).blank?
8
9
 
9
- - menu_children = page.menu_children.select { |page| page.menu_name == menu }
10
+ - menu_children = page.menu_children
10
11
 
11
12
  - if menu_children.blank?
12
13
  = nav_link_to((page.menu_title.presence || page.title), (page.menu_url.presence || effective_pages.page_path(page)))
14
+
13
15
  - else
14
16
  = nav_dropdown(page.to_s) do
15
17
  - menu_children.each do |page|
@@ -0,0 +1,13 @@
1
+ - raise('expected a page') unless page.present?
2
+
3
+ - menu_children = page.menu_children
4
+
5
+ - if menu_children.blank? && page.menu_parent&.menu_children.present?
6
+ - menu_children = page.menu_parent&.menu_children
7
+
8
+ - menu_children.each do |page|
9
+ - next unless EffectiveResources.authorized?(self, :show, page)
10
+ - next if (page.authenticate_user || page.roles.present?) && current_user.blank?
11
+ - next if page.roles.present? && (current_user.roles & page.roles).blank?
12
+
13
+ = nav_link_to((page.menu_title.presence || page.title), (page.menu_url.presence || effective_pages.page_path(page)))
@@ -50,4 +50,10 @@ EffectivePages.setup do |config|
50
50
  # Layout Settings
51
51
  # config.layout = { admin: 'admin' }
52
52
 
53
+ # Menus
54
+ # Strict bootstrap only supports depth 2. A root level and one dropdown.
55
+ # Other sites can be configured such that the depth 3 menus are displayed on a sidebar.
56
+ # Only 2 or 3 are supported right now
57
+ config.max_menu_depth = 2
58
+
53
59
  end
@@ -1,3 +1,3 @@
1
1
  module EffectivePages
2
- VERSION = '3.0.10'.freeze
2
+ VERSION = '3.1.1'.freeze
3
3
  end
@@ -12,7 +12,7 @@ module EffectivePages
12
12
  :site_og_image, :site_og_image_width, :site_og_image_height,
13
13
  :site_title, :site_title_suffix, :fallback_meta_description,
14
14
  :silence_missing_page_title_warnings, :silence_missing_meta_description_warnings, :silence_missing_canonical_url_warnings,
15
- :use_effective_roles, :menus, :layout
15
+ :use_effective_roles, :menus, :layout, :max_menu_depth
16
16
  ]
17
17
  end
18
18
 
@@ -43,4 +43,10 @@ module EffectivePages
43
43
  end.compact.sort
44
44
  end
45
45
 
46
+ def self.max_menu_depth
47
+ depth = config[:max_menu_depth] || 2
48
+ raise('only depths 2 and 3 are supported') unless [2, 3].include?(depth)
49
+ depth
50
+ end
51
+
46
52
  end
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.0.10
4
+ version: 3.1.1
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-08-23 00:00:00.000000000 Z
11
+ date: 2022-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -87,11 +87,11 @@ files:
87
87
  - app/views/admin/pages/_additional_fields.html.haml
88
88
  - app/views/admin/pages/_form.html.haml
89
89
  - app/views/admin/pages/_form_access.html.haml
90
- - app/views/admin/pages/_form_content.html.haml
91
90
  - app/views/admin/pages/_form_menu.html.haml
92
91
  - app/views/admin/pages/_form_page.html.haml
93
92
  - app/views/admin/pages/_rich_text_areas.html.haml
94
93
  - app/views/effective/pages/_menu.html.haml
94
+ - app/views/effective/pages/_page_menu.html.haml
95
95
  - config/effective_pages.rb
96
96
  - config/routes.rb
97
97
  - db/migrate/01_create_effective_pages.rb.erb
@@ -1,3 +0,0 @@
1
- = effective_form_with(model: page, url: page.persisted? ? effective_pages.admin_page_path(page.id) : effective_pages.admin_pages_path) do |f|
2
- = render '/admin/pages/rich_text_areas', page: page, f: f
3
- = effective_submit(f)