effective_pages 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56bbdfa9406cb66a2fc4171e85e118038d339b056555a33fbc105880397772c7
4
- data.tar.gz: a5bf336957ac12e9cb39a4e20be9f649cf89fa5a2be0dabb17638db7fd4efde2
3
+ metadata.gz: ccfde3b643933010d2ed2b254f381eda959b5d057cf9e30ab1cb1e2ed57adfaf
4
+ data.tar.gz: 5021c6f8feb8dfddc5f32ae1e076c976f7fc15408d0c69db25ae37e8c40da834
5
5
  SHA512:
6
- metadata.gz: ceef3c2528eefddfbfdc15c03c36b4f9f1b77b4cd8c4ff8ed683f6bdd1c8fdbd034d3138b24de88840d2cc93d1a6302629884187ceb4ddacc1c8ce1e2e4834dc
7
- data.tar.gz: dc8d257ad150d15d2fd9d4784ed3a22dfc7b353544dd0f723f5d356bb463d92aa6cf29229be251bc576222c0eeed2e3dca5ac17c6a28cba3690735f78bf647d6
6
+ metadata.gz: 70284db9597483e1ff7117056a18c282c7c822c372a6f5d1826e1d01ad4fbdba6603385e584c64040b0e2a0702590f3427d258837a38829cdbf340e5650ee613
7
+ data.tar.gz: f0f64d3c8739c2aeefb511cbbd1b6fd505728e7608f06684c020c68781d0baf005b753919da9b0ed2cdaad0dcc637d5016d43ac3c7750e12344a7464a6b26678
@@ -14,5 +14,9 @@ module Admin
14
14
  submit :save, 'Save and View', redirect: -> { effective_pages.page_path(resource) }
15
15
  submit :save, 'Duplicate', only: :edit, redirect: -> { effective_posts.new_admin_page_path(duplicate_id: resource.id) }
16
16
 
17
+ def permitted_params
18
+ params.require(:effective_page).permit!
19
+ end
20
+
17
21
  end
18
22
  end
@@ -1,7 +1,5 @@
1
1
  module Effective
2
2
  class PagesController < ApplicationController
3
- before_action(:authenticate_user!) if defined?(Devise) && EffectiveResources.authenticate_user
4
-
5
3
  include Effective::CrudController
6
4
 
7
5
  def show
@@ -10,9 +8,11 @@ module Effective
10
8
 
11
9
  @page = @pages.find(params[:id])
12
10
 
13
- raise ActiveRecord::RecordNotFound unless @page.present? # Incase .find() isn't raising it
14
- raise Effective::AccessDenied.new('Access Denied', :show, @page) unless @page.roles_permit?(current_user)
11
+ if @page.authenticate_user? || @page.roles.present?
12
+ authenticate_user!
13
+ end
15
14
 
15
+ raise Effective::AccessDenied.new('Access Denied', :show, @page) unless @page.roles_permit?(current_user)
16
16
  EffectiveResources.authorize!(self, :show, @page)
17
17
 
18
18
  @page_title = @page.title
@@ -29,7 +29,7 @@ module Effective
29
29
  end
30
30
 
31
31
  template = File.join(EffectivePages.pages_path, @page.template)
32
- layout = (@page.layout.presence || resource_layout)
32
+ layout = File.join(EffectivePages.layouts_path, @page.layout)
33
33
 
34
34
  render(template, layout: layout, locals: { page: @page })
35
35
  end
@@ -2,13 +2,17 @@ module Effective
2
2
  class Page < ActiveRecord::Base
3
3
  attr_accessor :current_user
4
4
 
5
- acts_as_slugged
5
+ # These parent / children are for the menu as well
6
+ belongs_to :menu_parent, class_name: 'Effective::Page', optional: true
7
+
8
+ has_many :menu_children, -> { Effective::Page.menuable }, class_name: 'Effective::Page',
9
+ foreign_key: :menu_parent_id, inverse_of: :menu_parent
6
10
 
7
- log_changes if respond_to?(:log_changes)
8
11
  acts_as_role_restricted
12
+ acts_as_slugged
13
+ has_many_rich_texts
9
14
 
10
- has_rich_text :body
11
- has_many :menu_items, as: :menuable, dependent: :destroy
15
+ log_changes if respond_to?(:log_changes)
12
16
 
13
17
  self.table_name = EffectivePages.pages_table_name.to_s
14
18
 
@@ -22,7 +26,15 @@ module Effective
22
26
  template :string
23
27
 
24
28
  slug :string
29
+
25
30
  roles_mask :integer
31
+ authenticate_user :boolean
32
+
33
+ # Menu stuff
34
+ menu :boolean
35
+ menu_name :string
36
+ menu_url :string
37
+ menu_position :integer
26
38
 
27
39
  timestamps
28
40
  end
@@ -32,11 +44,20 @@ module Effective
32
44
 
33
45
  validates :template, presence: true
34
46
 
47
+ # validates :menu_name, if: -> { menu? },
48
+ # presence: true, inclusion: { in: EffectivePages.menus }
49
+
50
+ # validates :menu_position, if: -> { menu? },
51
+ # presence: true, uniqueness: { scope: [:menu_name, :menu_parent_id] }
52
+
35
53
  scope :drafts, -> { where(draft: true) }
36
54
  scope :published, -> { where(draft: false) }
37
55
  scope :sorted, -> { order(:title) }
38
56
  scope :except_home, -> { where.not(title: 'Home') }
39
57
 
58
+ scope :menuable, -> { where(menu: true).order(:menu_position) }
59
+ scope :for_menu, -> (name) { menuable.where(menu_name: name) }
60
+
40
61
  def to_s
41
62
  title
42
63
  end
@@ -18,12 +18,11 @@
18
18
  = f.text_field :meta_description, hint: "A one or two sentence summary of this page. Appears on Google search results underneath the page title.", input_html: { maxlength: 150 }
19
19
 
20
20
  = render partial: '/admin/pages/additional_fields', locals: { page: page, form: f, f: f }
21
-
22
- = f.rich_text_area :body, hint: 'The main body of your page'
21
+ = render partial: '/admin/pages/rich_texts', locals: { page: page, form: f, f: f }
23
22
 
24
23
  = f.check_box :draft, label: 'Save this page as a draft. It will not be accessible on the website.'
25
24
 
26
- - if defined?(EffectiveRoles) and f.object.respond_to?(:roles) && EffectivePages.use_effective_roles
25
+ - if EffectivePages.use_effective_roles
27
26
  = render partial: '/admin/pages/roles', locals: { page: page, form: f, f: f }
28
27
 
29
28
  = effective_submit(f)
@@ -0,0 +1,2 @@
1
+ = f.rich_text_area :rich_text_body, hint: 'The main body of your page'
2
+ = f.rich_text_area :rich_text_sidebar, hint: 'The sidebar content of your page'
@@ -3,8 +3,8 @@ EffectivePages.setup do |config|
3
3
  config.menus_table_name = :menus
4
4
  config.menu_items_table_name = :menu_items
5
5
 
6
- # Call devise authenticate_user! as a before_action on Effective::Pages#show
7
- config.authenticate_user = false
6
+ # The menu names a page can belong to
7
+ config.menus = [:main, :footer]
8
8
 
9
9
  # The directory where your page templates live
10
10
  # Any files in this directory will be automatically available when
data/config/routes.rb CHANGED
@@ -1,9 +1,3 @@
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]
@@ -11,7 +5,9 @@ EffectivePages::Engine.routes.draw do
11
5
  end
12
6
 
13
7
  scope module: 'effective' do
14
- get '*id', to: 'pages#show', constraints: EffectivePagesConstraint, as: :page
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
+ }
15
11
  end
16
12
  end
17
13
 
@@ -4,13 +4,21 @@ 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: true
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
@@ -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, :authenticate_user, :menu, :layout
15
+ :use_effective_roles, :menus, :menu, :layout
16
16
  ]
17
17
  end
18
18
 
@@ -39,10 +39,4 @@ module EffectivePages
39
39
  end.compact.sort
40
40
  end
41
41
 
42
- def self.permitted_params
43
- @permitted_params ||= [
44
- :title, :meta_description, :draft, :layout, :template, :slug, roles: []
45
- ]
46
- end
47
-
48
42
  end
@@ -1,3 +1,3 @@
1
1
  module EffectivePages
2
- VERSION = '3.0.0'.freeze
2
+ VERSION = '3.0.1'.freeze
3
3
  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.0
4
+ version: 3.0.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: 2021-02-23 00:00:00.000000000 Z
11
+ date: 2021-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -95,6 +95,7 @@ files:
95
95
  - app/views/admin/menus/show.html.haml
96
96
  - app/views/admin/pages/_additional_fields.html.haml
97
97
  - app/views/admin/pages/_form.html.haml
98
+ - app/views/admin/pages/_rich_texts.html.haml
98
99
  - app/views/admin/pages/_roles.html.haml
99
100
  - config/effective_pages.rb
100
101
  - config/routes.rb