effective_pages 3.4.13 → 3.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/app/controllers/admin/alerts_controller.rb +15 -0
- data/app/controllers/admin/permalinks_controller.rb +15 -0
- data/app/controllers/effective/permalinks_controller.rb +21 -0
- data/app/datatables/effective_alerts_datatable.rb +18 -0
- data/app/datatables/effective_permalinks_datatable.rb +18 -0
- data/app/helpers/effective_alerts_helper.rb +16 -0
- data/app/helpers/effective_permalinks_helper.rb +20 -0
- data/app/models/effective/alert.rb +25 -0
- data/app/models/effective/page.rb +41 -0
- data/app/models/effective/permalink.rb +53 -0
- data/app/views/admin/alerts/_form.html.haml +7 -0
- data/app/views/admin/alerts/_form_alert.html.haml +9 -0
- data/app/views/admin/permalinks/_form.html.haml +7 -0
- data/app/views/admin/permalinks/_form_permalink.html.haml +8 -0
- data/app/views/effective/alerts/_alert.html.haml +4 -0
- data/config/effective_pages.rb +2 -0
- data/config/routes.rb +9 -5
- data/db/migrate/01_create_effective_pages.rb.erb +17 -0
- data/lib/effective_pages/engine.rb +2 -0
- data/lib/effective_pages/version.rb +1 -1
- data/lib/effective_pages.rb +1 -1
- data/lib/generators/effective_pages/install_generator.rb +2 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a4bbe810bd4f30ca02c101c48465763f4c6f246bb2e89afa70ddb79e117df8b
|
4
|
+
data.tar.gz: a8780dabcf25e0403836da65af42af2497c120cbd6fa9b67388d2f66c24b2e74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 612e18117979fdc36a5eaf6db3db0041ec2192006a7965d23357efd56fd18f6976cfefb95eeb4159ad16db765e9a275d06abd235abd0d062aab2bd34288123ae
|
7
|
+
data.tar.gz: 301c723e79df66b45159ac505badabea9eac1ea68bd56eda0c57ef57ae4f9d1f6a47418c18bd985c9a75fada67ec20df6317f17a8483d1a0ce8fe96049a7b588
|
data/README.md
CHANGED
@@ -211,6 +211,10 @@ if user.is?(:admin)
|
|
211
211
|
end
|
212
212
|
```
|
213
213
|
|
214
|
+
## Search
|
215
|
+
|
216
|
+
If you use `pg_search` then `Effective::Pages` will be also included on its `multisearch` by default, allowing you to search across all pages.
|
217
|
+
|
214
218
|
## License
|
215
219
|
|
216
220
|
MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Admin
|
2
|
+
class AlertsController < 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
|
+
page_title 'Alerts'
|
9
|
+
|
10
|
+
def permitted_params
|
11
|
+
params.require(:effective_alert).permit!
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Admin
|
2
|
+
class PermalinksController < 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
|
+
page_title 'Permalinks'
|
9
|
+
|
10
|
+
def permitted_params
|
11
|
+
params.require(:effective_permalink).permit!
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Effective
|
2
|
+
class PermalinksController < ApplicationController
|
3
|
+
def redirect
|
4
|
+
@permalink = Effective::Permalink.find_by! slug: params[:slug]
|
5
|
+
|
6
|
+
authorize! :redirect, @permalink
|
7
|
+
|
8
|
+
redirect_to redirect_path_for(@permalink), allow_other_host: (@permalink.target == :url)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def redirect_path_for(permalink)
|
14
|
+
permalink.target == :attachment ? attachment_url(permalink.attachment) : permalink.url
|
15
|
+
end
|
16
|
+
|
17
|
+
def attachment_url(permalink)
|
18
|
+
Rails.application.routes.url_helpers.rails_blob_path(permalink, only_path: true)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class EffectiveAlertsDatatable < Effective::Datatable
|
2
|
+
|
3
|
+
datatable do
|
4
|
+
col :id, visible: false
|
5
|
+
col :updated_at, visible: false
|
6
|
+
|
7
|
+
col :enabled
|
8
|
+
|
9
|
+
col :rich_text_body, label: 'Content'
|
10
|
+
|
11
|
+
actions_col
|
12
|
+
end
|
13
|
+
|
14
|
+
collection do
|
15
|
+
Effective::Alert.deep.all
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class EffectivePermalinksDatatable < Effective::Datatable
|
2
|
+
|
3
|
+
datatable do
|
4
|
+
col :id, visible: false
|
5
|
+
col :updated_at, visible: false
|
6
|
+
|
7
|
+
col :title
|
8
|
+
col :slug
|
9
|
+
col :summary
|
10
|
+
|
11
|
+
actions_col
|
12
|
+
end
|
13
|
+
|
14
|
+
collection do
|
15
|
+
Effective::Permalink.deep.all
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EffectiveAlertsHelper
|
4
|
+
|
5
|
+
def effective_alerts
|
6
|
+
@_effective_alerts ||= Effective::Alert.all.enabled
|
7
|
+
end
|
8
|
+
|
9
|
+
def render_effective_alerts
|
10
|
+
effective_alerts
|
11
|
+
.map { |alert| render 'effective/alerts/alert', alert: alert }
|
12
|
+
.join
|
13
|
+
.html_safe
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EffectivePermalinksHelper
|
4
|
+
|
5
|
+
def permalinks
|
6
|
+
@_effective_permalinks ||= Effective::Permalink.deep.order(:id)
|
7
|
+
end
|
8
|
+
|
9
|
+
def permalink_to(permalink_or_slug, options = {})
|
10
|
+
permalink =
|
11
|
+
if permalink_or_slug.kind_of?(String)
|
12
|
+
Effective::Permalink.find_by(slug: slug)
|
13
|
+
else
|
14
|
+
permalink_or_slug
|
15
|
+
end
|
16
|
+
|
17
|
+
link_to permalink, permalink.redirect_path, options
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Effective
|
2
|
+
class Alert < ApplicationRecord
|
3
|
+
self.table_name = (EffectivePages.alerts_table_name || :alerts).to_s
|
4
|
+
|
5
|
+
log_changes if respond_to?(:log_changes)
|
6
|
+
|
7
|
+
has_rich_text :body
|
8
|
+
|
9
|
+
effective_resource do
|
10
|
+
enabled :boolean
|
11
|
+
|
12
|
+
timestamps
|
13
|
+
end
|
14
|
+
|
15
|
+
scope :deep, -> { with_rich_text_body }
|
16
|
+
scope :enabled, -> { where(enabled: true) }
|
17
|
+
|
18
|
+
validates :body, presence: true
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
'alert'
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -1,5 +1,38 @@
|
|
1
1
|
module Effective
|
2
2
|
class Page < ActiveRecord::Base
|
3
|
+
if defined?(PgSearch)
|
4
|
+
include PgSearch::Model
|
5
|
+
|
6
|
+
pg_search_scope :search,
|
7
|
+
against: [
|
8
|
+
:title,
|
9
|
+
:menu_title,
|
10
|
+
:meta_description,
|
11
|
+
:slug,
|
12
|
+
],
|
13
|
+
associated_against: {
|
14
|
+
rich_texts: [:body],
|
15
|
+
},
|
16
|
+
using: { tsearch: { highlight: true }, trigram: { word_similarity: true } }
|
17
|
+
|
18
|
+
multisearchable against: [
|
19
|
+
:title,
|
20
|
+
:menu_title,
|
21
|
+
:meta_description,
|
22
|
+
:slug,
|
23
|
+
],
|
24
|
+
associated_against: {
|
25
|
+
rich_texts: [:body],
|
26
|
+
},
|
27
|
+
using: {
|
28
|
+
trigram: {},
|
29
|
+
tsearch: {
|
30
|
+
highlight: true,
|
31
|
+
}
|
32
|
+
},
|
33
|
+
ranked_by: ":trigram" # Could rank by any column/expression, e.g.: (books.num_pages * :trigram) + (:tsearch / 2.0)
|
34
|
+
end
|
35
|
+
|
3
36
|
attr_accessor :current_user
|
4
37
|
attr_accessor :menu_root_level
|
5
38
|
|
@@ -76,6 +109,14 @@ module Effective
|
|
76
109
|
published.where(menu: false).or(published.where(menu: true).where.not(id: menu_root_with_children))
|
77
110
|
}
|
78
111
|
|
112
|
+
# Maybe change paginate to be an isolated function instead of a scope, so we can use it with PgSearch::Document when doing a whole app search?
|
113
|
+
scope :paginate, -> (page: nil, per_page: nil) {
|
114
|
+
page = (page || 1).to_i
|
115
|
+
offset = [(page - 1), 0].max * per_page
|
116
|
+
|
117
|
+
limit(per_page).offset(offset)
|
118
|
+
}
|
119
|
+
|
79
120
|
before_validation(if: -> { menu? && menu_position.blank? }) do
|
80
121
|
self.menu_position = (self.class.where(menu_parent: menu_parent).maximum(:menu_position) || -1) + 1
|
81
122
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Effective
|
2
|
+
class Permalink < ApplicationRecord
|
3
|
+
self.table_name = (EffectivePages.permalinks_table_name || :permalinks).to_s
|
4
|
+
|
5
|
+
has_one_attached :attachment
|
6
|
+
has_one_purgable :attachment
|
7
|
+
|
8
|
+
acts_as_slugged
|
9
|
+
|
10
|
+
log_changes if respond_to?(:log_changes)
|
11
|
+
|
12
|
+
scope :deep, -> { with_attached_attachment }
|
13
|
+
|
14
|
+
effective_resource do
|
15
|
+
title :string
|
16
|
+
slug :string
|
17
|
+
|
18
|
+
url :string
|
19
|
+
|
20
|
+
summary :text
|
21
|
+
|
22
|
+
timestamps
|
23
|
+
end
|
24
|
+
|
25
|
+
validate :attachment_and_url_cannot_both_be_present
|
26
|
+
|
27
|
+
validates :title, presence: true
|
28
|
+
validates :attachment, presence: true, if: -> { url.blank? }
|
29
|
+
validates :url, presence: true, if: -> { attachment.blank? }, url: true
|
30
|
+
|
31
|
+
public
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
title.presence || model_name.human
|
35
|
+
end
|
36
|
+
|
37
|
+
def redirect_path
|
38
|
+
"/permalinks/#{slug}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def target
|
42
|
+
url.present? ? :url : :attachment
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def attachment_and_url_cannot_both_be_present
|
48
|
+
if url.present? && (attachment.attached? && !attachment.marked_for_destruction?)
|
49
|
+
self.errors.add(:base, 'Attachment and URL cannot both be present')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
= effective_form_with(model: [:admin, alert], engine: true) do |f|
|
2
|
+
= f.check_box :enabled, hint: 'Toggle activation of this alert'
|
3
|
+
|
4
|
+
- if defined?(EffectiveArticleEditor)
|
5
|
+
= f.article_editor :body, label: 'Content', hint: 'Content to be displayed'
|
6
|
+
- else
|
7
|
+
= f.rich_text_area :body, label: 'Content', hint: 'Content to be displayed'
|
8
|
+
|
9
|
+
= effective_submit(f)
|
@@ -0,0 +1,8 @@
|
|
1
|
+
= effective_form_with(model: [:admin, permalink], engine: true) do |f|
|
2
|
+
= f.text_field :title, required: true, hint: 'Title of the permalink to be displayed'
|
3
|
+
= f.text_field :slug, required: true, hint: 'Slug for link of the permalink'
|
4
|
+
= f.text_field :summary, required: true, hint: 'Summary explanation of the permalink not displayed'
|
5
|
+
= f.url_field :url, required: false, hint: 'The link if redirecting to a website or specific page'
|
6
|
+
= f.file_field :attachment, required: false, hint: 'The attachment of the permalink if redirecting to a document, image or other file'
|
7
|
+
|
8
|
+
= effective_submit(f)
|
data/config/effective_pages.rb
CHANGED
@@ -3,6 +3,8 @@ EffectivePages.setup do |config|
|
|
3
3
|
config.page_sections_table_name = :page_sections
|
4
4
|
config.page_banners_table_name = :page_banners
|
5
5
|
config.carousel_items_table_name = :carousel_items
|
6
|
+
config.alerts_table_name = :alerts
|
7
|
+
config.permalinks_table_name = :permalinks
|
6
8
|
|
7
9
|
# The menu names a page can belong to
|
8
10
|
config.menus = [:main, :footer]
|
data/config/routes.rb
CHANGED
@@ -2,14 +2,18 @@
|
|
2
2
|
|
3
3
|
EffectivePages::Engine.routes.draw do
|
4
4
|
namespace :admin do
|
5
|
-
resources :pages,
|
6
|
-
resources :page_sections,
|
7
|
-
resources :page_banners,
|
8
|
-
resources :menus,
|
9
|
-
resources :carousel_items,
|
5
|
+
resources :pages, except: [:show]
|
6
|
+
resources :page_sections, only: [:index, :edit, :update]
|
7
|
+
resources :page_banners, except: [:show]
|
8
|
+
resources :menus, only: [:index]
|
9
|
+
resources :carousel_items, except: [:show]
|
10
|
+
resources :alerts, except: [:show]
|
11
|
+
resources :permalinks, except: [:show]
|
10
12
|
end
|
11
13
|
|
12
14
|
scope module: 'effective' do
|
15
|
+
get '/permalinks/:slug', to: 'permalinks#redirect', as: :permalink_redirect
|
16
|
+
|
13
17
|
match '*id', to: 'pages#show', via: :get, as: :page, constraints: lambda { |req|
|
14
18
|
Effective::Page.find_by_slug_or_id(req.path_parameters[:id] || '/').present?
|
15
19
|
}
|
@@ -75,6 +75,21 @@ class CreateEffectivePages < ActiveRecord::Migration[4.2]
|
|
75
75
|
t.timestamps
|
76
76
|
end
|
77
77
|
|
78
|
+
create_table <%= @alerts_table_name %>, if_not_exists: true do |t|
|
79
|
+
t.boolean :enabled
|
80
|
+
|
81
|
+
t.timestamps
|
82
|
+
end
|
83
|
+
|
84
|
+
create_table <%= @permalinks_table_name %>, if_not_exists: true do |t|
|
85
|
+
t.string :title
|
86
|
+
t.string :slug
|
87
|
+
t.string :url
|
88
|
+
t.text :summary
|
89
|
+
|
90
|
+
t.timestamps
|
91
|
+
end
|
92
|
+
|
78
93
|
end
|
79
94
|
|
80
95
|
def self.down
|
@@ -82,6 +97,8 @@ class CreateEffectivePages < ActiveRecord::Migration[4.2]
|
|
82
97
|
drop_table <%= @page_banners_table_name %>
|
83
98
|
drop_table <%= @page_sections_table_name %>
|
84
99
|
drop_table <%= @carousel_items_table_name %>
|
100
|
+
drop_table <%= @alerts_table_name %>
|
101
|
+
drop_table <%= @permalinks_table_name %>
|
85
102
|
end
|
86
103
|
|
87
104
|
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, :page_sections_table_name, :page_banners_table_name, :carousel_items_table_name,
|
10
|
+
:pages_table_name, :page_sections_table_name, :page_banners_table_name, :carousel_items_table_name, :alerts_table_name, :permalinks_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, :google_analytics_code,
|
@@ -24,6 +24,8 @@ module EffectivePages
|
|
24
24
|
@page_sections_table_name = ':' + EffectivePages.page_sections_table_name.to_s
|
25
25
|
@page_banners_table_name = ':' + EffectivePages.page_banners_table_name.to_s
|
26
26
|
@carousel_items_table_name = ':' + EffectivePages.carousel_items_table_name.to_s
|
27
|
+
@alerts_table_name = ':' + EffectivePages.alerts_table_name.to_s
|
28
|
+
@permalinks_table_name = ':' + EffectivePages.permalinks_table_name.to_s
|
27
29
|
|
28
30
|
migration_template ('../' * 3) + 'db/migrate/01_create_effective_pages.rb.erb', 'db/migrate/create_effective_pages.rb'
|
29
31
|
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.
|
4
|
+
version: 3.6.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: 2023-
|
11
|
+
date: 2023-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -78,26 +78,37 @@ files:
|
|
78
78
|
- app/assets/config/effective_pages_manifest.js
|
79
79
|
- app/assets/javascripts/effective_pages.js
|
80
80
|
- app/assets/javascripts/effective_pages/google_analytics.js
|
81
|
+
- app/controllers/admin/alerts_controller.rb
|
81
82
|
- app/controllers/admin/carousel_items_controller.rb
|
82
83
|
- app/controllers/admin/menus_controller.rb
|
83
84
|
- app/controllers/admin/page_banners_controller.rb
|
84
85
|
- app/controllers/admin/page_sections_controller.rb
|
85
86
|
- app/controllers/admin/pages_controller.rb
|
87
|
+
- app/controllers/admin/permalinks_controller.rb
|
86
88
|
- app/controllers/effective/pages_controller.rb
|
89
|
+
- app/controllers/effective/permalinks_controller.rb
|
90
|
+
- app/datatables/effective_alerts_datatable.rb
|
87
91
|
- app/datatables/effective_carousel_items_datatable.rb
|
88
92
|
- app/datatables/effective_page_banners_datatable.rb
|
89
93
|
- app/datatables/effective_page_sections_datatable.rb
|
90
94
|
- app/datatables/effective_pages_datatable.rb
|
91
95
|
- app/datatables/effective_pages_menu_datatable.rb
|
96
|
+
- app/datatables/effective_permalinks_datatable.rb
|
97
|
+
- app/helpers/effective_alerts_helper.rb
|
92
98
|
- app/helpers/effective_carousels_helper.rb
|
93
99
|
- app/helpers/effective_menus_helper.rb
|
94
100
|
- app/helpers/effective_page_banners_helper.rb
|
95
101
|
- app/helpers/effective_page_sections_helper.rb
|
96
102
|
- app/helpers/effective_pages_helper.rb
|
103
|
+
- app/helpers/effective_permalinks_helper.rb
|
104
|
+
- app/models/effective/alert.rb
|
97
105
|
- app/models/effective/carousel_item.rb
|
98
106
|
- app/models/effective/page.rb
|
99
107
|
- app/models/effective/page_banner.rb
|
100
108
|
- app/models/effective/page_section.rb
|
109
|
+
- app/models/effective/permalink.rb
|
110
|
+
- app/views/admin/alerts/_form.html.haml
|
111
|
+
- app/views/admin/alerts/_form_alert.html.haml
|
101
112
|
- app/views/admin/carousel_items/_form.html.haml
|
102
113
|
- app/views/admin/carousel_items/_form_carousel_item.html.haml
|
103
114
|
- app/views/admin/carousel_items/index.html.haml
|
@@ -112,6 +123,9 @@ files:
|
|
112
123
|
- app/views/admin/pages/_form_menu.html.haml
|
113
124
|
- app/views/admin/pages/_form_page.html.haml
|
114
125
|
- app/views/admin/pages/_rich_text_areas.html.haml
|
126
|
+
- app/views/admin/permalinks/_form.html.haml
|
127
|
+
- app/views/admin/permalinks/_form_permalink.html.haml
|
128
|
+
- app/views/effective/alerts/_alert.html.haml
|
115
129
|
- app/views/effective/carousels/_carousel.html.haml
|
116
130
|
- app/views/effective/pages/_menu.html.haml
|
117
131
|
- app/views/effective/pages/_page_menu.html.haml
|