effective_pages 3.2.0 → 3.3.0

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: '06898ad2ffae38015ec40dbeeefb1a46e468a7df73e933c69c194d06415123cc'
4
- data.tar.gz: 74916bd3ca8fe11dbac3b6ac6b6085cc73cc9fd381fdf96aacd46fed82a3ba72
3
+ metadata.gz: 2620fbfec6b912fd31b7d9821fe5ef73eecbfb4c509063883f8c144a2aa66d30
4
+ data.tar.gz: d75935c05702f1328e32058f45874999a3b3b3f7f7becab1202c4d18b9dee743
5
5
  SHA512:
6
- metadata.gz: 27fc19935dabbad5e6710ad06a9ea883d04a983541ae5308d706c62bc5546c295a922a6143fb9778980fd80ec26817c1d68ea7025b32d6950558da8af09290de
7
- data.tar.gz: 1789579e269f287c2b4db33748d3039f6bc0b152506a0c597ebcbbbd58c8064f38cb240c2de4f76740bd01b620ffcb64c2dbbbda8eee822a513de5d9ea46c322
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
@@ -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
@@ -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,7 @@
1
+ = tabs do
2
+ = tab 'Page Section' do
3
+ = render '/admin/page_sections/form_page_section', page_section: page_section
4
+
5
+ - if page_section.persisted?
6
+ = tab 'Logs' do
7
+ = render_datatable(page_section.log_changes_datatable, inline: true, namespace: :admin)
@@ -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)
@@ -1,5 +1,6 @@
1
1
  EffectivePages.setup do |config|
2
2
  config.pages_table_name = :pages
3
+ config.page_sections_table_name = :page_sections
3
4
 
4
5
  # The menu names a page can belong to
5
6
  config.menus = [:main, :footer]
data/config/routes.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  EffectivePages::Engine.routes.draw do
4
4
  namespace :admin do
5
5
  resources :pages, except: [:show]
6
+ resources :page_sections, only: [:index, :edit, :update]
6
7
  resources :menus, only: [:index]
7
8
  end
8
9
 
@@ -30,10 +30,31 @@ class CreateEffectivePages < ActiveRecord::Migration[4.2]
30
30
  end
31
31
 
32
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
33
53
  end
34
54
 
35
55
  def self.down
36
56
  drop_table <%= @pages_table_name %>
57
+ drop_table <%= @page_sections_table_name %>
37
58
  end
38
59
 
39
60
  end
@@ -7,6 +7,7 @@ module EffectivePages
7
7
  app.config.to_prepare do
8
8
  ActiveSupport.on_load :action_controller_base do
9
9
  helper EffectivePagesHelper
10
+ helper EffectivePageSectionsHelper
10
11
  helper EffectiveMenusHelper
11
12
  end
12
13
  end
@@ -1,3 +1,3 @@
1
1
  module EffectivePages
2
- VERSION = '3.2.0'.freeze
2
+ VERSION = '3.3.0'.freeze
3
3
  end
@@ -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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
@@ -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