effective_pages 2.0.8 → 3.0.2

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +11 -70
  4. data/app/controllers/admin/menus_controller.rb +6 -48
  5. data/app/controllers/admin/pages_controller.rb +11 -102
  6. data/app/controllers/effective/pages_controller.rb +14 -8
  7. data/app/datatables/effective_pages_datatable.rb +20 -2
  8. data/app/datatables/effective_pages_menu_datatable.rb +38 -0
  9. data/app/helpers/effective_menus_helper.rb +31 -136
  10. data/app/helpers/effective_pages_helper.rb +4 -2
  11. data/app/models/effective/page.rb +65 -22
  12. data/app/views/admin/menus/index.html.haml +10 -2
  13. data/app/views/admin/pages/_form.html.haml +20 -25
  14. data/app/views/admin/pages/_form_access.html.haml +10 -0
  15. data/app/views/admin/pages/_form_content.html.haml +3 -0
  16. data/app/views/admin/pages/_form_menu.html.haml +16 -0
  17. data/app/views/admin/pages/_form_page.html.haml +31 -0
  18. data/app/views/admin/pages/_rich_text_areas.html.haml +2 -0
  19. data/app/views/effective/pages/_menu.html.haml +20 -0
  20. data/config/effective_pages.rb +9 -38
  21. data/config/routes.rb +6 -9
  22. data/db/migrate/01_create_effective_pages.rb.erb +12 -30
  23. data/lib/effective_pages.rb +17 -61
  24. data/lib/effective_pages/version.rb +1 -1
  25. data/lib/generators/effective_pages/install_generator.rb +1 -1
  26. data/lib/generators/templates/example.html.haml +4 -5
  27. data/lib/tasks/effective_pages_tasks.rake +1 -1
  28. metadata +11 -38
  29. data/app/datatables/effective_menus_datatable.rb +0 -16
  30. data/app/helpers/effective_breadcrumbs_helper.rb +0 -41
  31. data/app/helpers/effective_menus_admin_helper.rb +0 -8
  32. data/app/models/effective/access_denied.rb +0 -17
  33. data/app/models/effective/menu.rb +0 -172
  34. data/app/models/effective/menu_item.rb +0 -78
  35. data/app/views/admin/menu_items/_actions.html.haml +0 -4
  36. data/app/views/admin/menu_items/_expand.html.haml +0 -2
  37. data/app/views/admin/menu_items/_item.html.haml +0 -13
  38. data/app/views/admin/menu_items/_new.html.haml +0 -3
  39. data/app/views/admin/menus/_actions.html.haml +0 -2
  40. data/app/views/admin/menus/_form.html.haml +0 -4
  41. data/app/views/admin/menus/edit.html.haml +0 -3
  42. data/app/views/admin/menus/new.html.haml +0 -3
  43. data/app/views/admin/menus/show.html.haml +0 -39
  44. data/app/views/admin/pages/_actions.html.haml +0 -7
  45. data/app/views/admin/pages/_roles.html.haml +0 -1
  46. data/app/views/admin/pages/edit.html.haml +0 -3
  47. data/app/views/admin/pages/index.html.haml +0 -6
  48. data/app/views/admin/pages/new.html.haml +0 -3
@@ -0,0 +1,2 @@
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'
@@ -0,0 +1,20 @@
1
+ - raise('expected a menu') unless menu.present?
2
+ - menu = menu.to_s
3
+
4
+ - Effective::Page.for_menu_root(menu).each do |page|
5
+ - next unless EffectiveResources.authorized?(self, :show, page)
6
+ - next if (page.authenticate_user || page.roles.present?) && current_user.blank?
7
+ - next if page.roles.present? && !current_user.roles.include?(page.roles)
8
+
9
+ - menu_children = page.menu_children.select { |page| page.menu_name == menu }
10
+
11
+ - if menu_children.blank?
12
+ = nav_link_to(page, page.menu_url.presence || effective_pages.page_path(page))
13
+ - else
14
+ = nav_dropdown(page.to_s) do
15
+ - ([page] + menu_children).each do |page|
16
+ - next unless EffectiveResources.authorized?(self, :show, page)
17
+ - next if (page.authenticate_user || page.roles.present?) && current_user.blank?
18
+ - next if page.roles.present? && !current_user.roles.include?(page.roles)
19
+
20
+ = nav_link_to(page, page.menu_url.presence || effective_pages.page_path(page))
@@ -1,13 +1,18 @@
1
1
  EffectivePages.setup do |config|
2
2
  config.pages_table_name = :pages
3
- config.menus_table_name = :menus
4
- config.menu_items_table_name = :menu_items
3
+
4
+ # The menu names a page can belong to
5
+ config.menus = [:main, :footer]
5
6
 
6
7
  # The directory where your page templates live
7
8
  # Any files in this directory will be automatically available when
8
9
  # creating/editting an Effective::Page from the Admin screens
9
10
  # Relative to app/views/
10
- config.pages_path = '/effective/pages/'
11
+ config.pages_path = 'effective/pages/'
12
+
13
+ # The directory where your layouts live
14
+ # Relative to app/views/
15
+ config.layouts_path = 'layouts/'
11
16
 
12
17
  # Excluded Pages
13
18
  # Any page templates from the above directory that should be excluded
@@ -39,44 +44,10 @@ EffectivePages.setup do |config|
39
44
  config.silence_missing_meta_description_warnings = false
40
45
  config.silence_missing_canonical_url_warnings = false
41
46
 
42
-
43
47
  # Display the effective roles 'choose roles' input when an admin creates a new post
44
48
  config.use_effective_roles = false
45
49
 
46
- # Authorization Method
47
- #
48
- # This method is called by all controller actions with the appropriate action and resource
49
- # If the method returns false, an Effective::AccessDenied Error will be raised (see README.md for complete info)
50
- #
51
- # Use via Proc (and with CanCan):
52
- # config.authorization_method = Proc.new { |controller, action, resource| can?(action, resource) }
53
- #
54
- # Use via custom method:
55
- # config.authorization_method = :my_authorization_method
56
- #
57
- # And then in your application_controller.rb:
58
- #
59
- # def my_authorization_method(action, resource)
60
- # current_user.is?(:admin)
61
- # end
62
- #
63
- # Or disable the check completely:
64
- # config.authorization_method = false
65
- config.authorization_method = Proc.new { |controller, action, resource| authorize!(action, resource) && resource.roles_permit?(current_user) } # CanCanCan
66
- # Use effective_roles: resource.roles_permit?(current_user)
67
-
68
50
  # Layout Settings
69
- # Configure the Layout per controller, or all at once
70
-
71
- # The layout for the EffectivePages admin screen
72
- config.layout = {
73
- :admin => 'application'
74
- }
75
-
76
- # All effective_page menu options
77
- config.menu = {
78
- :apply_active_class => true, # Add an .active class to the appropriate li item based on current page url
79
- :maxdepth => 2 # 2 by default, strict bootstrap3 doesnt support dropdowns in your dropdowns
80
- }
51
+ # config.layout = { admin: 'admin' }
81
52
 
82
53
  end
data/config/routes.rb CHANGED
@@ -1,23 +1,20 @@
1
- class EffectivePagesConstraint
2
- def self.matches?(request)
3
- Effective::Page.find(request.path_parameters[:id] || '/').present? rescue false
4
- end
5
- end
6
-
7
1
  EffectivePages::Engine.routes.draw do
8
2
  namespace :admin do
9
3
  resources :pages, except: [:show]
4
+ resources :menus, only: [:index]
10
5
  end
11
6
 
12
- scope :module => 'effective' do
13
- get '*id', to: 'pages#show', constraints: EffectivePagesConstraint, as: :page
7
+ scope module: 'effective' do
8
+ match '*id', to: 'pages#show', via: :get, as: :page, constraints: lambda { |req|
9
+ Effective::Page.find_by_slug_or_id(req.path_parameters[:id] || '/').present?
10
+ }
14
11
  end
15
12
  end
16
13
 
17
14
  # Automatically mount the engine as an append
18
15
  Rails.application.routes.append do
19
16
  unless Rails.application.routes.routes.find { |r| r.name == 'effective_pages' }
20
- mount EffectivePages::Engine => '/', :as => 'effective_pages'
17
+ mount EffectivePages::Engine => '/', as: 'effective_pages'
21
18
  end
22
19
  end
23
20
 
@@ -4,49 +4,31 @@ class CreateEffectivePages < ActiveRecord::Migration[4.2]
4
4
  t.string :title
5
5
  t.string :meta_description
6
6
 
7
- t.boolean :draft, :default => false
7
+ t.boolean :draft, default: false
8
8
 
9
- t.string :layout, :default => 'application'
9
+ t.string :layout, default: 'application'
10
10
  t.string :template
11
11
 
12
12
  t.string :slug
13
- t.integer :roles_mask, :default => 0
13
+
14
+ t.boolean :authenticate_user, default: false
15
+ t.integer :roles_mask, default: 0
16
+
17
+ t.integer :menu_parent_id
18
+ t.boolean :menu, default: false
19
+ t.string :menu_name
20
+ t.string :menu_url
21
+ t.integer :menu_position
14
22
 
15
23
  t.datetime :updated_at
16
24
  t.datetime :created_at
17
25
  end
18
- add_index <%= @pages_table_name %>, :slug, :unique => true
19
-
20
- create_table <%= @menus_table_name %> do |t|
21
- t.string :title
22
- t.timestamps
23
- end
24
-
25
- create_table <%= @menu_items_table_name %> do |t|
26
- t.integer :menu_id
27
26
 
28
- t.integer :menuable_id
29
- t.string :menuable_type
30
-
31
- t.string :title
32
-
33
- t.string :url
34
- t.string :special
35
-
36
- t.string :classes
37
- t.boolean :new_window, :default => false
38
- t.integer :roles_mask, :default => nil
39
-
40
- t.integer :lft
41
- t.integer :rgt
42
- end
43
- add_index <%= @menu_items_table_name %>, :lft
27
+ add_index <%= @pages_table_name %>, :slug, :unique => true
44
28
  end
45
29
 
46
30
  def self.down
47
31
  drop_table <%= @pages_table_name %>
48
- drop_table <%= @menus_table_name %>
49
- drop_table <%= @menu_items_table_name %>
50
32
  end
51
33
 
52
34
  end
@@ -1,86 +1,42 @@
1
1
  require 'effective_datatables'
2
- require 'effective_regions'
2
+ require 'effective_resources'
3
3
  require 'effective_roles'
4
4
  require 'effective_pages/engine'
5
5
  require 'effective_pages/version'
6
6
 
7
7
  module EffectivePages
8
- mattr_accessor :pages_table_name
9
- mattr_accessor :menus_table_name
10
- mattr_accessor :menu_items_table_name
11
-
12
- mattr_accessor :pages_path
13
- mattr_accessor :excluded_pages
14
- mattr_accessor :excluded_layouts
15
-
16
- mattr_accessor :site_og_image
17
- mattr_accessor :site_og_image_width
18
- mattr_accessor :site_og_image_height
19
-
20
- mattr_accessor :site_title
21
- mattr_accessor :site_title_suffix
22
- mattr_accessor :fallback_meta_description
23
-
24
- mattr_accessor :silence_missing_page_title_warnings
25
- mattr_accessor :silence_missing_meta_description_warnings
26
- mattr_accessor :silence_missing_canonical_url_warnings
27
-
28
- mattr_accessor :use_effective_roles
29
-
30
- mattr_accessor :menu
31
- mattr_accessor :authorization_method
32
- mattr_accessor :layout
33
-
34
- def self.setup
35
- yield self
8
+ def self.config_keys
9
+ [
10
+ :pages_table_name,
11
+ :pages_path, :excluded_pages, :layouts_path, :excluded_layouts,
12
+ :site_og_image, :site_og_image_width, :site_og_image_height,
13
+ :site_title, :site_title_suffix, :fallback_meta_description,
14
+ :silence_missing_page_title_warnings, :silence_missing_meta_description_warnings, :silence_missing_canonical_url_warnings,
15
+ :use_effective_roles, :menus, :layout
16
+ ]
36
17
  end
37
18
 
38
- def self.authorized?(controller, action, resource)
39
- @_exceptions ||= [Effective::AccessDenied, (CanCan::AccessDenied if defined?(CanCan)), (Pundit::NotAuthorizedError if defined?(Pundit))].compact
40
-
41
- return !!authorization_method unless authorization_method.respond_to?(:call)
42
- controller = controller.controller if controller.respond_to?(:controller)
43
-
44
- begin
45
- !!(controller || self).instance_exec((controller || self), action, resource, &authorization_method)
46
- rescue *@_exceptions
47
- false
48
- end
49
- end
50
-
51
- def self.authorize!(controller, action, resource)
52
- raise Effective::AccessDenied.new('Access Denied', action, resource) unless authorized?(controller, action, resource)
53
- end
54
-
55
- # Remove leading and trailing '/' characters
56
- # Will return: "effective/pages"
57
- def self.pages_path=(filepath)
58
- filepath = filepath.to_s
59
- filepath = filepath[1..-1] if filepath.starts_with?('/')
60
- @@pages_path = filepath.chomp('/')
61
- end
19
+ include EffectiveGem
62
20
 
63
21
  def self.templates
64
- ApplicationController.view_paths.map { |path| Dir["#{path}/#{pages_path}/**"] }.flatten.reverse.map do |file|
22
+ ApplicationController.view_paths.map { |path| Dir[File.join(path, pages_path, '**')] }.flatten.map do |file|
65
23
  name = File.basename(file).split('.').first
66
24
  next if name.starts_with?('_')
67
25
  next if Array(EffectivePages.excluded_pages).map { |str| str.to_s }.include?(name)
68
26
  name
69
- end.compact
27
+ end.compact.sort
70
28
  end
71
29
 
72
30
  def self.layouts
73
- ApplicationController.view_paths.map { |path| Dir["#{path}/layouts/**"] }.flatten.reverse.map do |file|
31
+ return [] if layouts_path.blank?
32
+
33
+ ApplicationController.view_paths.map { |path| Dir[File.join(path, layouts_path, '**')] }.flatten.map do |file|
74
34
  name = File.basename(file).split('.').first
75
35
  next if name.starts_with?('_')
76
36
  next if name.include?('mailer')
77
37
  next if Array(EffectivePages.excluded_layouts).map { |str| str.to_s }.include?(name)
78
38
  name
79
- end.compact
80
- end
81
-
82
- def self.permitted_params
83
- @@permitted_params ||= [:title, :meta_description, :draft, :layout, :template, :slug, roles: []]
39
+ end.compact.sort
84
40
  end
85
41
 
86
42
  end
@@ -1,3 +1,3 @@
1
1
  module EffectivePages
2
- VERSION = '2.0.8'.freeze
2
+ VERSION = '3.0.2'.freeze
3
3
  end
@@ -32,7 +32,7 @@ module EffectivePages
32
32
  end
33
33
 
34
34
  def setup_routes
35
- inject_into_file 'config/routes.rb', "\n # if you want EffectivePages to render the home / root page\n # uncomment the following line and create an Effective::Page with slug == 'home' \n # root :to => 'Effective::Pages#show', :id => 'home'\n", :before => /root (:?)to.*/
35
+ inject_into_file 'config/routes.rb', "\n # if you want EffectivePages to render the home / root page\n # uncomment the following line and create an Effective::Page with slug == 'home' \n # root to: 'Effective::Pages#show', id: 'home'\n", :before => /root (:?)to.*/
36
36
  end
37
37
 
38
38
  end
@@ -1,6 +1,5 @@
1
- %h1
2
- = simple_effective_region page, :title do
3
- = page.title
1
+ %h1= page.title
4
2
 
5
- = effective_region page, :content do
6
- %p this is default content for the page titled #{page.title}
3
+ .row
4
+ .col-9= page.rich_text_body
5
+ .col-3= page.rich_text_sidebar
@@ -1,6 +1,6 @@
1
1
  # bundle exec rake effective_pages:seed
2
2
  namespace :effective_pages do
3
- task :seed => :environment do
3
+ task seed: :environment do
4
4
  include EffectiveMenusHelper
5
5
 
6
6
  return true if Effective::Menu.find_by_title('main menu').present?
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: 2.0.8
4
+ version: 3.0.2
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: 2020-07-30 00:00:00.000000000 Z
11
+ date: 2021-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.2.0
19
+ version: '6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 3.2.0
26
+ version: '6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: effective_datatables
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 4.0.0
41
- - !ruby/object:Gem::Dependency
42
- name: effective_regions
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: effective_resources
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -92,33 +78,20 @@ files:
92
78
  - app/controllers/admin/menus_controller.rb
93
79
  - app/controllers/admin/pages_controller.rb
94
80
  - app/controllers/effective/pages_controller.rb
95
- - app/datatables/effective_menus_datatable.rb
96
81
  - app/datatables/effective_pages_datatable.rb
97
- - app/helpers/effective_breadcrumbs_helper.rb
98
- - app/helpers/effective_menus_admin_helper.rb
82
+ - app/datatables/effective_pages_menu_datatable.rb
99
83
  - app/helpers/effective_menus_helper.rb
100
84
  - app/helpers/effective_pages_helper.rb
101
- - app/models/effective/access_denied.rb
102
- - app/models/effective/menu.rb
103
- - app/models/effective/menu_item.rb
104
85
  - app/models/effective/page.rb
105
- - app/views/admin/menu_items/_actions.html.haml
106
- - app/views/admin/menu_items/_expand.html.haml
107
- - app/views/admin/menu_items/_item.html.haml
108
- - app/views/admin/menu_items/_new.html.haml
109
- - app/views/admin/menus/_actions.html.haml
110
- - app/views/admin/menus/_form.html.haml
111
- - app/views/admin/menus/edit.html.haml
112
86
  - app/views/admin/menus/index.html.haml
113
- - app/views/admin/menus/new.html.haml
114
- - app/views/admin/menus/show.html.haml
115
- - app/views/admin/pages/_actions.html.haml
116
87
  - app/views/admin/pages/_additional_fields.html.haml
117
88
  - app/views/admin/pages/_form.html.haml
118
- - app/views/admin/pages/_roles.html.haml
119
- - app/views/admin/pages/edit.html.haml
120
- - app/views/admin/pages/index.html.haml
121
- - app/views/admin/pages/new.html.haml
89
+ - app/views/admin/pages/_form_access.html.haml
90
+ - app/views/admin/pages/_form_content.html.haml
91
+ - app/views/admin/pages/_form_menu.html.haml
92
+ - app/views/admin/pages/_form_page.html.haml
93
+ - app/views/admin/pages/_rich_text_areas.html.haml
94
+ - app/views/effective/pages/_menu.html.haml
122
95
  - config/effective_pages.rb
123
96
  - config/routes.rb
124
97
  - db/migrate/01_create_effective_pages.rb.erb
@@ -1,16 +0,0 @@
1
- class EffectiveMenusDatatable < Effective::Datatable
2
-
3
- datatable do
4
- col :id, visible: false
5
- col :updated_at, visible: false
6
-
7
- col :title
8
-
9
- actions_col partial: 'admin/menus/actions', partial_as: :menu
10
- end
11
-
12
- collection do
13
- Effective::Menu.all
14
- end
15
-
16
- end
@@ -1,41 +0,0 @@
1
- module EffectiveBreadcrumbsHelper
2
- def render_breadcrumbs(menu, page)
3
- menu = Effective::Menu.find_by_title(menu.to_s) if menu.kind_of?(String) || menu.kind_of?(Symbol)
4
- return "Menu '#{menu}' does not exist".html_safe unless menu.present?
5
-
6
- return breadcrumbs_fallback(page) if !page.present?
7
-
8
- menu_item = if page.kind_of?(Effective::Page)
9
- url = effective_pages.page_path(page)
10
- menu.menu_items.find { |item| item.menuable == page || item.title == page.title || item.url == url }
11
- elsif page.kind_of?(String)
12
- downcased = page.downcase
13
- menu.menu_items.find { |item| item.title.downcase == downcased || item.url == downcased }
14
- else
15
- menu.menu_items.find { |item| item.menuable == page || item.title == page || item.url == page }
16
- end
17
-
18
- return breadcrumbs_fallback(page) unless menu_item.present?
19
-
20
- parents = menu.menu_items.select { |item| item.lft < menu_item.lft && item.rgt > menu_item.rgt }
21
-
22
- content_tag(:ol, class: 'breadcrumb') do
23
- (
24
- parents.map { |parent| content_tag(:li, link_to(parent.title, parent.url.presence || '#', title: parent.title)) } +
25
- [content_tag(:li, page.try(:title) || page, class: 'active')]
26
- ).join().html_safe
27
- end
28
- end
29
-
30
- alias_method :render_breadcrumb, :render_breadcrumbs
31
-
32
- def breadcrumbs_fallback(page = nil, root: 'Home')
33
- content_tag(:ol, class: 'breadcrumb') do
34
- [
35
- content_tag(:li, link_to(root, root_path, title: root)),
36
- content_tag(:li, ((page.title if page.respond_to?(:title)) || page || @page_title || 'Here'), class: 'active')
37
- ].join().html_safe
38
- end
39
- end
40
-
41
- end