effective_pages 3.6.0 → 3.7.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: 1a4bbe810bd4f30ca02c101c48465763f4c6f246bb2e89afa70ddb79e117df8b
4
- data.tar.gz: a8780dabcf25e0403836da65af42af2497c120cbd6fa9b67388d2f66c24b2e74
3
+ metadata.gz: 955cae35489cf5133d4e988126070fb86de48849bb75d832b2acc43fc709d1b8
4
+ data.tar.gz: dc820dc28af2c81dbfaa4158ce1196209ec173dab3f16255121dab37e87586eb
5
5
  SHA512:
6
- metadata.gz: 612e18117979fdc36a5eaf6db3db0041ec2192006a7965d23357efd56fd18f6976cfefb95eeb4159ad16db765e9a275d06abd235abd0d062aab2bd34288123ae
7
- data.tar.gz: 301c723e79df66b45159ac505badabea9eac1ea68bd56eda0c57ef57ae4f9d1f6a47418c18bd985c9a75fada67ec20df6317f17a8483d1a0ce8fe96049a7b588
6
+ metadata.gz: 1a5e86f7a5c65d13432dd2701b7366f5d1a0ab4a7032bc9cc81ba278fc57e5d2777e8b4f339d28a1a61a48ca996adb0473ccf6c54487c80e363600fd4fd4a4a7
7
+ data.tar.gz: e967b492ab869e6bd1f02f523317e30899dcffe14a1a767162af5d1d7bd8df195e306da9cabbc2cbfedb01b509b588c5e6bf16aad402d1aaa82b86fc2c82c8ee
@@ -0,0 +1,8 @@
1
+ module Admin
2
+ class TaggingsController < ApplicationController
3
+ before_action(:authenticate_user!) if defined?(Devise)
4
+ before_action { EffectiveResources.authorize!(self, :admin, :effective_pages) }
5
+
6
+ include Effective::CrudController
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ module Admin
2
+ class TagsController < 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_tag).permit!
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ class Admin::EffectiveTaggingsDatatable < Effective::Datatable
2
+
3
+ datatable do
4
+ col :id, visible: false
5
+
6
+ col :tag
7
+ col :taggable
8
+
9
+ col :created_at
10
+
11
+ actions_col
12
+ end
13
+
14
+ collection do
15
+ Effective::Tagging.deep.all
16
+ end
17
+
18
+ end
@@ -0,0 +1,16 @@
1
+ class Admin::EffectiveTagsDatatable < Effective::Datatable
2
+
3
+ datatable do
4
+ col :id, visible: false
5
+ col :updated_at, visible: false
6
+
7
+ col :name
8
+
9
+ actions_col
10
+ end
11
+
12
+ collection do
13
+ Effective::Tag.deep.all
14
+ end
15
+
16
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EffectiveTagsHelper
4
+ end
@@ -0,0 +1,46 @@
1
+ module ActsAsTagged
2
+ extend ActiveSupport::Concern
3
+
4
+ module Base
5
+ def acts_as_tagged(*options)
6
+ @acts_as_tagged = options || []
7
+ include ::ActsAsTagged
8
+ end
9
+ end
10
+
11
+ included do
12
+ has_many :taggings, as: :taggable, class_name: 'Effective::Tagging', dependent: :delete_all
13
+
14
+ has_many :tags, through: :taggings, class_name: 'Effective::Tag'
15
+
16
+ accepts_nested_attributes_for :tags, reject_if: :all_blank, allow_destroy: true
17
+
18
+ #
19
+ # Create or assign tags based on the input
20
+ #
21
+ # @param [Array<String, Integer>] input An array of tag names and/or tag ids, with a possible blank string
22
+ #
23
+ # @return [void]
24
+ #
25
+ def tags=(input)
26
+ input = (input - ['']).group_by { |value| value.gsub(/\D/, '').to_i > 0 }
27
+
28
+ ids = (input[true] || []).map(&:to_i)
29
+ names = input[false] || []
30
+
31
+ # Delete any existing Tags that aren't in this array
32
+ tags.each { |tag| tag.mark_for_destruction unless ids.include?(tag.id) }
33
+
34
+ # Create any new Tags
35
+ ids.each do |tag_id|
36
+ taggings.find { |tagging| tagging.tag_id == tag_id } || self.tags << Effective::Tag.where(id: tag_id).first!
37
+ end
38
+
39
+ names.each { |name| self.tags.build(name: name) }
40
+ end
41
+ end
42
+
43
+ module ClassMethods
44
+ def acts_as_tagged?; true; end
45
+ end
46
+ end
@@ -46,6 +46,7 @@ module Effective
46
46
 
47
47
  acts_as_role_restricted
48
48
  acts_as_slugged
49
+ acts_as_tagged
49
50
  has_many_rich_texts
50
51
 
51
52
  log_changes if respond_to?(:log_changes)
@@ -0,0 +1,27 @@
1
+ module Effective
2
+ class Tag < ApplicationRecord
3
+ self.table_name = (EffectivePages.tags_table_name || :tags).to_s
4
+
5
+ log_changes if respond_to?(:log_changes)
6
+
7
+ has_many :taggings, class_name: 'Effective::Tagging', dependent: :delete_all
8
+
9
+ scope :deep, -> { all }
10
+ scope :sorted, -> { order(:name) }
11
+
12
+ effective_resource do
13
+ name :string
14
+
15
+ timestamps
16
+ end
17
+
18
+ validates :name, presence: true
19
+ validates :name, uniqueness: true
20
+
21
+ public
22
+
23
+ def to_s
24
+ name.presence || model_name.human
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ module Effective
2
+ class Tagging < ApplicationRecord
3
+ self.table_name = (EffectivePages.taggings_table_name || :taggings).to_s
4
+
5
+ belongs_to :tag, class_name: 'Effective::Tag'
6
+ belongs_to :taggable, polymorphic: true
7
+
8
+ scope :deep, -> { all }
9
+
10
+ effective_resource do
11
+ tag_id :integer
12
+ taggable_id :integer
13
+ taggable_type :string
14
+
15
+ timestamps
16
+ end
17
+
18
+ validates :tag_id, uniqueness: { scope: [:taggable_type, :taggable_id] }
19
+
20
+ public
21
+
22
+ def to_s
23
+ name
24
+ end
25
+ end
26
+ end
@@ -16,3 +16,6 @@
16
16
 
17
17
  = tab 'Logs' do
18
18
  = render_datatable(page.log_changes_datatable, inline: true, namespace: :admin)
19
+
20
+ = tab 'Tags' do
21
+ = render '/admin/pages/form_tags', page: page
@@ -0,0 +1,4 @@
1
+ = effective_form_with(model: [:admin, page], engine: true) do |f|
2
+ = render 'effective/tags/fields', f: f
3
+
4
+ = f.submit
@@ -0,0 +1,3 @@
1
+ = tabs do
2
+ = tab 'Tagged content' do
3
+ = render_datatable(EffectiveTaggingsDatatable.new, namespace: :admin)
@@ -0,0 +1,4 @@
1
+ = effective_form_with(model: [:admin, tagging], engine: true) do |f|
2
+ = f.text_field :name, hint: 'Tag ID'
3
+
4
+ = f.submit 'Save'
@@ -0,0 +1,7 @@
1
+ = tabs do
2
+ = tab 'Tag' do
3
+ = render '/admin/tags/form_tag', tag: tag
4
+
5
+ - if tag.persisted?
6
+ = tab 'Logs' do
7
+ = render_datatable(tag.log_changes_datatable, inline: true, namespace: :admin)
@@ -0,0 +1,4 @@
1
+ = effective_form_with(model: [:admin, tag], engine: true) do |f|
2
+ = f.text_field :name, hint: 'Tag name'
3
+
4
+ = f.submit 'Save'
@@ -0,0 +1 @@
1
+ = f.select :tag_ids, Effective::Tag.all, tags: true, hint: 'Select existing tags or type and hit Enter to create a new tag'
@@ -5,6 +5,8 @@ EffectivePages.setup do |config|
5
5
  config.carousel_items_table_name = :carousel_items
6
6
  config.alerts_table_name = :alerts
7
7
  config.permalinks_table_name = :permalinks
8
+ config.tags_table_name = :tags
9
+ config.taggings_table_name = :taggings
8
10
 
9
11
  # The menu names a page can belong to
10
12
  config.menus = [:main, :footer]
@@ -2,3 +2,7 @@ en:
2
2
  effective_pages:
3
3
  name: 'Effective Pages'
4
4
  acronym: 'Pages'
5
+
6
+ activerecord:
7
+ models:
8
+ effective/tagging: 'Tagged content'
data/config/routes.rb CHANGED
@@ -9,6 +9,8 @@ EffectivePages::Engine.routes.draw do
9
9
  resources :carousel_items, except: [:show]
10
10
  resources :alerts, except: [:show]
11
11
  resources :permalinks, except: [:show]
12
+ resources :tags, except: [:show]
13
+ resources :taggings, only: [:index]
12
14
  end
13
15
 
14
16
  scope module: 'effective' do
@@ -90,6 +90,20 @@ class CreateEffectivePages < ActiveRecord::Migration[4.2]
90
90
  t.timestamps
91
91
  end
92
92
 
93
+ create_table <%= @tags_table_name %>, if_not_exists: true do |t|
94
+ t.string :name
95
+
96
+ t.timestamps
97
+ end
98
+
99
+ create_table <%= @taggings_table_name %>, if_not_exists: true do |t|
100
+ t.integer :tag_id
101
+ t.integer :taggable_id
102
+ t.string :taggable_type
103
+
104
+ t.timestamps
105
+ end
106
+
93
107
  end
94
108
 
95
109
  def self.down
@@ -99,6 +113,8 @@ class CreateEffectivePages < ActiveRecord::Migration[4.2]
99
113
  drop_table <%= @carousel_items_table_name %>
100
114
  drop_table <%= @alerts_table_name %>
101
115
  drop_table <%= @permalinks_table_name %>
116
+ drop_table <%= @tags_table_name %>
117
+ drop_table <%= @taggings_table_name %>
102
118
  end
103
119
 
104
120
  end
@@ -2,6 +2,15 @@ module EffectivePages
2
2
  class Engine < ::Rails::Engine
3
3
  engine_name 'effective_pages'
4
4
 
5
+ # Include acts_as_tagged concern and allow any ActiveRecord object to call it
6
+ initializer 'effective_pages.active_record' do |app|
7
+ app.config.to_prepare do
8
+ ActiveSupport.on_load :active_record do
9
+ ActiveRecord::Base.extend(ActsAsTagged::Base)
10
+ end
11
+ end
12
+ end
13
+
5
14
  # Include Helpers to base application
6
15
  initializer 'effective_pages.action_controller' do |app|
7
16
  app.config.to_prepare do
@@ -13,6 +22,7 @@ module EffectivePages
13
22
  helper EffectiveMenusHelper
14
23
  helper EffectiveAlertsHelper
15
24
  helper EffectivePermalinksHelper
25
+ helper EffectiveTagsHelper
16
26
  end
17
27
  end
18
28
  end
@@ -1,3 +1,3 @@
1
1
  module EffectivePages
2
- VERSION = '3.6.0'.freeze
2
+ VERSION = '3.7.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, :page_sections_table_name, :page_banners_table_name, :carousel_items_table_name, :alerts_table_name, :permalinks_table_name,
10
+ :pages_table_name, :page_sections_table_name, :page_banners_table_name, :carousel_items_table_name, :alerts_table_name, :permalinks_table_name, :tags_table_name, :taggings_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,
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.6.0
4
+ version: 3.7.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-06-06 00:00:00.000000000 Z
11
+ date: 2023-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -85,8 +85,12 @@ files:
85
85
  - app/controllers/admin/page_sections_controller.rb
86
86
  - app/controllers/admin/pages_controller.rb
87
87
  - app/controllers/admin/permalinks_controller.rb
88
+ - app/controllers/admin/taggings_controller.rb
89
+ - app/controllers/admin/tags_controller.rb
88
90
  - app/controllers/effective/pages_controller.rb
89
91
  - app/controllers/effective/permalinks_controller.rb
92
+ - app/datatables/admin/effective_taggings_datatable.rb
93
+ - app/datatables/admin/effective_tags_datatable.rb
90
94
  - app/datatables/effective_alerts_datatable.rb
91
95
  - app/datatables/effective_carousel_items_datatable.rb
92
96
  - app/datatables/effective_page_banners_datatable.rb
@@ -101,12 +105,16 @@ files:
101
105
  - app/helpers/effective_page_sections_helper.rb
102
106
  - app/helpers/effective_pages_helper.rb
103
107
  - app/helpers/effective_permalinks_helper.rb
108
+ - app/helpers/effective_tags_helper.rb
109
+ - app/models/concerns/acts_as_tagged.rb
104
110
  - app/models/effective/alert.rb
105
111
  - app/models/effective/carousel_item.rb
106
112
  - app/models/effective/page.rb
107
113
  - app/models/effective/page_banner.rb
108
114
  - app/models/effective/page_section.rb
109
115
  - app/models/effective/permalink.rb
116
+ - app/models/effective/tag.rb
117
+ - app/models/effective/tagging.rb
110
118
  - app/views/admin/alerts/_form.html.haml
111
119
  - app/views/admin/alerts/_form_alert.html.haml
112
120
  - app/views/admin/carousel_items/_form.html.haml
@@ -122,13 +130,19 @@ files:
122
130
  - app/views/admin/pages/_form_access.html.haml
123
131
  - app/views/admin/pages/_form_menu.html.haml
124
132
  - app/views/admin/pages/_form_page.html.haml
133
+ - app/views/admin/pages/_form_tags.html.haml
125
134
  - app/views/admin/pages/_rich_text_areas.html.haml
126
135
  - app/views/admin/permalinks/_form.html.haml
127
136
  - app/views/admin/permalinks/_form_permalink.html.haml
137
+ - app/views/admin/taggings/_form.html.haml
138
+ - app/views/admin/taggings/_form_tagging.html.haml
139
+ - app/views/admin/tags/_form.html.haml
140
+ - app/views/admin/tags/_form_tag.html.haml
128
141
  - app/views/effective/alerts/_alert.html.haml
129
142
  - app/views/effective/carousels/_carousel.html.haml
130
143
  - app/views/effective/pages/_menu.html.haml
131
144
  - app/views/effective/pages/_page_menu.html.haml
145
+ - app/views/effective/tags/_fields.html.haml
132
146
  - app/views/layouts/_google_analytics.html.erb
133
147
  - config/effective_pages.rb
134
148
  - config/locales/effective_pages.en.yml