fi_seo 0.1.0

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 (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +3 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +6 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +10 -0
  8. data/Gemfile.lock +93 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +309 -0
  11. data/Rakefile +6 -0
  12. data/app/controller/sitemap_controller.rb +58 -0
  13. data/app/views/acts_as_seoable/_view_helper.html.arb +31 -0
  14. data/app/views/google_analytics/_acts_as_seoable.html.erb +9 -0
  15. data/app/views/sitemap/sitemap.xml.erb +1 -0
  16. data/bin/console +14 -0
  17. data/bin/setup +8 -0
  18. data/config/routes.rb +7 -0
  19. data/fi_seo.gemspec +29 -0
  20. data/lib/acts_as_seoable/dynamic_seo.rb +6 -0
  21. data/lib/acts_as_seoable/engine.rb +6 -0
  22. data/lib/acts_as_seoable/google_analytic_seo.rb +5 -0
  23. data/lib/acts_as_seoable/helpers/sitemap_helper.rb +32 -0
  24. data/lib/acts_as_seoable/helpers/static_helper.rb +94 -0
  25. data/lib/acts_as_seoable/sitemap_seo.rb +10 -0
  26. data/lib/acts_as_seoable/static_seo.rb +5 -0
  27. data/lib/acts_as_seoable/version.rb +3 -0
  28. data/lib/fi_seo.rb +205 -0
  29. data/lib/generators/acts_as_seoable/admin/admin_generator.rb +17 -0
  30. data/lib/generators/acts_as_seoable/admin/templates/admin.rb +250 -0
  31. data/lib/generators/acts_as_seoable/admin_view_helper/admin_view_helper_generator.rb +17 -0
  32. data/lib/generators/acts_as_seoable/admin_view_helper/templates/_view_helper.html.arb +31 -0
  33. data/lib/generators/acts_as_seoable/install/install_generator.rb +13 -0
  34. data/lib/generators/acts_as_seoable/install/templates/initializer.rb +20 -0
  35. data/lib/generators/acts_as_seoable/migrate/migrate_generator.rb +22 -0
  36. data/lib/generators/acts_as_seoable/migrate/templates/migration.rb +65 -0
  37. data/screenshots/dynamic-pages-seoable.png +0 -0
  38. data/screenshots/static-pages-seoable-details.png +0 -0
  39. data/screenshots/static-pages-seoable-frontend.png +0 -0
  40. data/screenshots/static-pages-seoable.png +0 -0
  41. metadata +140 -0
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ Rails.application.routes.draw do
2
+ sitemap_enable = false
3
+ sitemap_enable = true if FiSeo.initialized_config.sitemap_enable == true
4
+ if sitemap_enable
5
+ get 'sitemap' => 'sitemap#sitemap', format: true
6
+ end
7
+ end
data/fi_seo.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/acts_as_seoable/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'fi_seo'
5
+ spec.version = FiSeo::VERSION
6
+ spec.authors = ['Banura Randika']
7
+ spec.email = ['info@fidenz.com', 'tech@fidenz.com', 'banura.r@fidenz.com']
8
+
9
+ spec.summary = 'Flexible SEO solution for rails projects'
10
+ spec.description = 'This gem provides a easier solution to search engine optimization(SEO) in a ruby project. This will give you the seo capabilities to your static pages anddynamic pages alike with few lines of code.
11
+ Also site maps are essential to the SEO of your web application. So this gem gives that capabilities with a feature to integrate google analytics.'
12
+ spec.homepage = 'https://github.com/fidenz-developer/fi-seo.git'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_runtime_dependency 'activerecord', '~> 5.0', '>= 5.0.0.1'
27
+ spec.add_runtime_dependency('meta-tags', '~> 2.13')
28
+ spec.add_runtime_dependency 'xml-sitemap', '~> 1.3', '>= 1.3.3'
29
+ end
@@ -0,0 +1,6 @@
1
+ class DynamicSeo < ActiveRecord::Base
2
+
3
+ belongs_to :seoable, polymorphic: true
4
+ validates_presence_of :seoable_type, :seoable_id
5
+ validates_uniqueness_of :seoable_id, scope: :seoable_type
6
+ end
@@ -0,0 +1,6 @@
1
+ module ActsAsSeoable
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace ActsAsSeoable
4
+ end
5
+ end
6
+
@@ -0,0 +1,5 @@
1
+ class GoogleAnalyticSeo < ActiveRecord::Base
2
+
3
+ validates_presence_of :title
4
+ validates_presence_of :content, allow_blank: true
5
+ end
@@ -0,0 +1,32 @@
1
+ require 'acts_as_seoable/sitemap_seo'
2
+
3
+ module SitemapClassMethods
4
+
5
+ def create_sitemap_seo_records
6
+ Rails.application.reload_routes!
7
+ routes = Rails.application.routes.routes.select { |r| r.defaults.include? :sitemap}
8
+ row_routes = Array.new
9
+
10
+ routes.each do |route|
11
+ next if route.defaults[:sitemap] != true || route.verb != 'GET'
12
+
13
+ static = route.defaults[:static] == true
14
+ row = SitemapSeo.find_by_sitemap_controller_and_sitemap_action(route.defaults[:controller], route.defaults[:action])
15
+ if row.nil?
16
+ new_row = SitemapSeo.create(sitemap_controller: route.defaults[:controller], sitemap_action: route.defaults[:action],
17
+ status: false, static: static)
18
+ row_routes << new_row
19
+ else
20
+ row.update(static: static)
21
+ row.save
22
+ row_routes << row
23
+ end
24
+ end
25
+
26
+ SitemapSeo.all.each do |sitemap_seo|
27
+ next if row_routes.include? sitemap_seo
28
+
29
+ sitemap_seo.delete
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,94 @@
1
+ require 'acts_as_seoable/static_seo'
2
+ require 'meta-tags'
3
+
4
+ module ActsAsSeoableStaticClassMethods
5
+
6
+ def create_static_seo_records
7
+ Rails.application.reload_routes!
8
+ routes = Rails.application.routes.routes.select { |r| r.defaults.include? :acts_as_seoable }
9
+ row_routes = Array.new
10
+
11
+ routes.each do |route|
12
+ row = StaticSeo.find_by_seoable_controller_and_seoable_action(route.defaults[:controller], route.defaults[:action])
13
+ status = route.defaults[:acts_as_seoable] == true
14
+ if row.nil?
15
+ new_row = StaticSeo.create(seoable_controller: route.defaults[:controller], seoable_action: route.defaults[:action],
16
+ title: '', description: '', keywords: '', status: status)
17
+ row_routes << new_row
18
+ else
19
+ row_routes << row
20
+ row.update(status: status)
21
+ end
22
+ end
23
+
24
+ StaticSeo.all.each do |static_seo|
25
+ next if row_routes.include? static_seo
26
+
27
+ static_seo.delete
28
+ end
29
+ end
30
+
31
+ def create_static_meta_tags(controller_name, action_name, _options = {})
32
+ FiSeo::create_static_seo_records
33
+
34
+ configuration = { reverse: false,
35
+ lowercase: false,
36
+ index: false,
37
+ noindex: false,
38
+ nofollow: false,
39
+ follow: false,
40
+ noarchive: false,
41
+ separator: '&#124;',
42
+ canonical: false,
43
+ canonical_url: '',
44
+ social: false }
45
+ configuration.update(_options) if _options.present?
46
+ row = StaticSeo.find_by_seoable_controller_and_seoable_action(controller_name, action_name)
47
+ hash = if row.nil? || (row && row.status == false)
48
+ {
49
+ title: '',
50
+ description: '',
51
+ keywords: ''
52
+ }
53
+ else
54
+ static_hash = {
55
+ title: row.title,
56
+ description: row.description,
57
+ keywords: row.keywords,
58
+ lowercase: configuration[:lowercase],
59
+ reverse: configuration[:reverse],
60
+ index: configuration[:index],
61
+ noindex: configuration[:noindex],
62
+ follow: configuration[:follow],
63
+ nofollow: configuration[:nofollow],
64
+ noarchive: configuration[:noarchive],
65
+ separator: configuration[:separator].html_safe
66
+ }
67
+ if configuration[:canonical].present?
68
+ static_hash.merge!(canonical: configuration[:canonical_url])
69
+ end
70
+ if configuration[:social].present?
71
+ if configuration[:social].include? :facebook
72
+ static_hash.merge!(og: {
73
+ title: row.facebook_title.blank? ? '' : row.facebook_title,
74
+ type: row.facebook_type.blank? ? '' : row.facebook_type,
75
+ url: row.facebook_url.blank? ? '' : row.facebook_url,
76
+ image: row.facebook_image.blank? ? '' : row.facebook_image,
77
+ description: row.facebook_description.blank? ? '' : row.facebook_description
78
+ })
79
+ end
80
+ if configuration[:social].include? :twitter
81
+ static_hash.merge!(twitter: {
82
+ title: row.twitter_title.blank? ? '' : row.twitter_title,
83
+ card: row.twitter_card.blank? ? '' : row.twitter_card,
84
+ site: row.twitter_site.blank? ? '' : row.twitter_site,
85
+ image: row.twitter_image.blank? ? '' : row.twitter_image,
86
+ description: row.twitter_description.blank? ? '' : row.twitter_description
87
+ })
88
+ end
89
+ end
90
+ static_hash
91
+ end
92
+ hash
93
+ end
94
+ end
@@ -0,0 +1,10 @@
1
+
2
+ class SitemapSeo < ActiveRecord::Base
3
+
4
+ validates_presence_of :sitemap_action, :sitemap_controller
5
+ validates_uniqueness_of :sitemap_action, scope: :sitemap_controller
6
+ validates_numericality_of :priority, greater_than_or_equal_to: 0, less_than_or_equal_to: 1
7
+
8
+
9
+ enum period: { not_available: 0, always: 1, hourly: 2, daily: 3, weekly: 4, monthly: 5,yearly: 6, never: 7 }
10
+ end
@@ -0,0 +1,5 @@
1
+ class StaticSeo < ActiveRecord::Base
2
+
3
+ validates_presence_of :seoable_controller, :seoable_action
4
+ validates_uniqueness_of :seoable_action, scope: :seoable_controller
5
+ end
@@ -0,0 +1,3 @@
1
+ module FiSeo
2
+ VERSION = "0.1.0"
3
+ end
data/lib/fi_seo.rb ADDED
@@ -0,0 +1,205 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'meta-tags'
4
+ require 'xml-sitemap'
5
+
6
+ require 'acts_as_seoable/version'
7
+ require 'active_record'
8
+ require 'active_record/version'
9
+ require 'active_support/core_ext/module'
10
+ require 'active_support/core_ext/hash'
11
+ require 'generators/acts_as_seoable/migrate/migrate_generator'
12
+ require 'acts_as_seoable/dynamic_seo'
13
+ require 'acts_as_seoable/static_seo'
14
+ require 'acts_as_seoable/google_analytic_seo'
15
+ require 'acts_as_seoable/sitemap_seo'
16
+ require 'acts_as_seoable/engine'
17
+ require 'acts_as_seoable/helpers/static_helper'
18
+ require 'acts_as_seoable/helpers/sitemap_helper'
19
+
20
+ module FiSeo
21
+ extend ActiveSupport::Concern
22
+ extend SitemapClassMethods
23
+ extend ActsAsSeoableStaticClassMethods
24
+
25
+ class << self
26
+ attr_accessor :initialized_config
27
+ end
28
+
29
+ def self.initialized_config
30
+ @initialized_config ||= Configuration.new
31
+ end
32
+
33
+ def self.configure
34
+ yield(initialized_config)
35
+ end
36
+
37
+ class Configuration
38
+ attr_accessor :default_facebook_title
39
+ attr_accessor :default_facebook_url
40
+ attr_accessor :default_facebook_type
41
+ attr_accessor :default_facebook_image
42
+ attr_accessor :default_facebook_description
43
+ attr_accessor :default_twitter_title
44
+ attr_accessor :default_twitter_card
45
+ attr_accessor :default_twitter_site
46
+ attr_accessor :default_twitter_image
47
+ attr_accessor :default_twitter_description
48
+ attr_accessor :default_canonical_url
49
+ attr_accessor :sitemap_host_url
50
+ attr_accessor :sitemap_enable
51
+
52
+ def initialize
53
+ @default_facebook_title = ''
54
+ @default_facebook_url = ''
55
+ @default_facebook_type = ''
56
+ @default_facebook_image = ''
57
+ @default_facebook_description = ''
58
+ @default_twitter_title = ''
59
+ @default_twitter_card = ''
60
+ @default_twitter_site = ''
61
+ @default_twitter_image = ''
62
+ @default_twitter_description = ''
63
+ @default_canonical_url = ''
64
+ @sitemap_host_url = 'www.domain.com'
65
+ @sitemap_enable = true
66
+
67
+ end
68
+ end
69
+
70
+ module ClassMethods
71
+
72
+ def acts_as_seoable(title, description, keywords, _options = {})
73
+ extend ActsAsSeoableClassMethods
74
+ include ActsAsSeoableInstanceMethods
75
+
76
+ attr_names = [title, description, keywords]
77
+ configuration = { check_for_changes: true,
78
+ reverse: false,
79
+ lowercase: false,
80
+ index: false,
81
+ noindex: false,
82
+ nofollow: false,
83
+ follow: false,
84
+ noarchive: false,
85
+ social: false,
86
+ separator: '&#124;',
87
+ canonical: false }
88
+ configuration.update(_options) if _options.present?
89
+ configuration[:fields] = attr_names.flatten.uniq.compact
90
+
91
+ class_attribute :seoable_options
92
+ self.seoable_options = configuration
93
+
94
+ self.send('after_create', :create_dynamic_seo_record)
95
+ self.send('after_update', :update_dynamic_seo_record)
96
+ self.send('has_one', :dynamic_seo, as: :seoable, dependent: :delete)
97
+ self.send('accepts_nested_attributes_for', :dynamic_seo)
98
+ end
99
+ end
100
+
101
+ def self.included(receiver)
102
+ receiver.extend(ClassMethods)
103
+ end
104
+
105
+ module ActsAsSeoableClassMethods
106
+
107
+ def seoable_fields
108
+ self.seoable_options[:fields]
109
+ end
110
+ end
111
+
112
+ module ActsAsSeoableInstanceMethods
113
+
114
+ def to_meta_tags
115
+ row = DynamicSeo.find_by_seoable_type_and_seoable_id(self.class.to_s, self.id)
116
+ if row.nil?
117
+ {}
118
+ else
119
+ hash = {
120
+ title: row.title,
121
+ description: row.description,
122
+ keywords: row.keywords,
123
+ lowercase: self.class.seoable_options[:lowercase],
124
+ reverse: self.class.seoable_options[:reverse],
125
+ index: self.class.seoable_options[:index],
126
+ noindex: self.class.seoable_options[:noindex],
127
+ follow: self.class.seoable_options[:follow],
128
+ nofollow: self.class.seoable_options[:nofollow],
129
+ noarchive: self.class.seoable_options[:noarchive],
130
+ separator: self.class.seoable_options[:separator].html_safe
131
+ }
132
+
133
+ if self.class.seoable_options[:social].present?
134
+ if self.class.seoable_options[:social].include? :facebook
135
+ hash.merge!(og: facebook_tags)
136
+ end
137
+ if self.class.seoable_options[:social].include? :twitter
138
+ hash.merge!(twitter: twitter_tags)
139
+ end
140
+ end
141
+ if self.class.seoable_options[:canonical].present?
142
+ hash.merge!(canonical: canonical_url)
143
+ end
144
+ hash
145
+ end
146
+ end
147
+
148
+
149
+
150
+ def create_dynamic_seo_record
151
+ DynamicSeo.create(seoable_type: self.class.to_s, seoable_id: id, title: self.title_value,
152
+ description: self.description_value, keywords: self.keywords_value)
153
+ end
154
+
155
+ def update_dynamic_seo_record
156
+ if self.class.seoable_options[:check_for_changes]
157
+ row = DynamicSeo.find_by_seoable_type_and_seoable_id(self.class.to_s, self.id)
158
+ if row.nil?
159
+ self.create_dynamic_seo_record
160
+ else
161
+ DynamicSeo.where(seoable_type: self.class.to_s).where(seoable_id: self.id)
162
+ .update_all(title: self.title_value, description: self.description_value, keywords: self.keywords_value)
163
+ end
164
+ end
165
+ end
166
+
167
+ def facebook_tags
168
+ {
169
+ title: FiSeo.initialized_config.default_facebook_title,
170
+ type: FiSeo.initialized_config.default_facebook_type,
171
+ url: FiSeo.initialized_config.default_facebook_url,
172
+ image: FiSeo.initialized_config.default_facebook_image,
173
+ description: FiSeo.initialized_config.default_facebook_description
174
+ }
175
+ end
176
+
177
+ def twitter_tags
178
+ {
179
+ title: FiSeo.initialized_config.default_twitter_title,
180
+ card: FiSeo.initialized_config.default_twitter_card,
181
+ site: FiSeo.initialized_config.default_twitter_site,
182
+ image: FiSeo.initialized_config.default_twitter_image,
183
+ description: FiSeo.initialized_config.default_twitter_description
184
+ }
185
+ end
186
+
187
+ def canonical_url
188
+ FiSeo.initialized_config.default_canonical_url
189
+ end
190
+
191
+ def title_value
192
+ self.send(self.class.seoable_fields.first)
193
+ end
194
+
195
+ def description_value
196
+ self.send(self.class.seoable_fields.second)
197
+ end
198
+
199
+ def keywords_value
200
+ self.send(self.class.seoable_fields.third)
201
+ end
202
+ end
203
+ end
204
+
205
+ ActiveRecord::Base.send(:include, FiSeo)
@@ -0,0 +1,17 @@
1
+ require 'rails/generators'
2
+
3
+ module ActsAsSeoable
4
+ module Generators
5
+ class AdminGenerator < Rails::Generators::Base
6
+ source_root File.expand_path('templates', __dir__)
7
+
8
+ def generate_config_file
9
+ if Gem.loaded_specs.has_key?('activeadmin')
10
+ template 'admin.rb', 'app/admin/acts_as_seoable.rb'
11
+ else
12
+ raise StandardError, 'Could not generate activeadmin page without activeadmin installed.'
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,250 @@
1
+
2
+ ActiveAdmin.register_page 'SEOData' do
3
+ menu label: 'SEO Data', url: '#'
4
+ end
5
+
6
+ ActiveAdmin.register StaticSeo do
7
+ menu label: 'Static Pages', priority: 1, parent: 'SEOData'
8
+ config.filters = false
9
+ actions :all, except: %i[destroy new]
10
+
11
+ show title: proc { |static_seo| "#{static_seo.seoable_controller.titleize} - #{static_seo.seoable_action.titleize}" } do
12
+ attributes_table do
13
+ row('Controller', &:seoable_controller)
14
+ row('Action', &:seoable_action)
15
+ row :title
16
+ row :description
17
+ row :keywords
18
+ row :status
19
+ row :facebook_title
20
+ row :facebook_url
21
+ row :facebook_type
22
+ row :facebook_image
23
+ row :facebook_description
24
+ row :twitter_title
25
+ row :twitter_card
26
+ row :twitter_site
27
+ row :twitter_image
28
+ row :twitter_description
29
+ row :created_at
30
+ row :updated_at
31
+ end
32
+ end
33
+
34
+ index title: 'Static SEO' do
35
+ column 'Controller' do |static_seo|
36
+ static_seo.seoable_controller.titleize
37
+ end
38
+ column 'Action' do |static_seo|
39
+ static_seo.seoable_action.titleize
40
+ end
41
+ column :title
42
+ column :created_at
43
+ column :updated_at
44
+ actions
45
+ end
46
+
47
+ form do |f|
48
+ f.inputs do
49
+ f.input :seoable_controller, input_html: { readonly: true }
50
+ f.input :seoable_action, input_html: { readonly: true }
51
+ f.input :title
52
+ f.input :description
53
+ f.input :keywords
54
+ f.input :status
55
+ f.input :facebook_title
56
+ f.input :facebook_url
57
+ f.input :facebook_type
58
+ f.input :facebook_image
59
+ f.input :facebook_description
60
+ f.input :twitter_title
61
+ f.input :twitter_card
62
+ f.input :twitter_site
63
+ f.input :twitter_image
64
+ f.input :twitter_description
65
+ end
66
+ f.actions
67
+ end
68
+
69
+ controller do
70
+ def permitted_params
71
+ params.permit!
72
+ end
73
+ end
74
+ end
75
+
76
+ ActiveAdmin.register DynamicSeo do
77
+ menu label: 'Dynamic Pages', priority: 2, parent: 'SEOData'
78
+ config.filters = false
79
+ actions :all, except: %i[destroy new edit show]
80
+
81
+ index title: 'Dynamic SEO' do
82
+ column 'Type' do |dynamic_seo|
83
+ dynamic_seo.seoable_type.titleize
84
+ end
85
+ column 'Item Count' do |dynamic_seo|
86
+ DynamicSeo.where(seoable_type: dynamic_seo.seoable_type).count
87
+ end
88
+ actions defaults: true do |dynamic_seo|
89
+ link_to('View All', "/admin/dynamic_seo_by_types?type=#{dynamic_seo.seoable_type}")
90
+ end
91
+ end
92
+
93
+ controller do
94
+ def permitted_params
95
+ params.permit!
96
+ end
97
+
98
+ def scoped_collection
99
+ arr_of_distinct_types = DynamicSeo.all.group_by(&:seoable_type).collect{|k,v| v.first}
100
+ DynamicSeo.where(id: arr_of_distinct_types.map(&:id))
101
+ end
102
+ end
103
+ end
104
+
105
+ ActiveAdmin.register DynamicSeo, as: 'DynamicSEO By Type' do
106
+ menu false
107
+ config.filters = false
108
+ actions :all, except: %i[destroy new edit]
109
+ config.breadcrumb = false
110
+
111
+ show do
112
+ attributes_table do
113
+ row 'Type' do |dyanamic_seo|
114
+ dyanamic_seo.seoable_type.titleize
115
+ end
116
+ row 'Id' do |dynamic_seo|
117
+ dynamic_seo.seoable_id
118
+ end
119
+ row 'Title' do |dynamic_seo|
120
+ dynamic_seo.title.titleize
121
+ end
122
+ row :description
123
+ row :keywords
124
+ row :created_at
125
+ row :updated_at
126
+ end
127
+ end
128
+
129
+ index title: proc { |dynamic_seo| "Dynamic SEO - #{params[:type]}" } do
130
+ column 'Type' do |dynamic_seo|
131
+ dynamic_seo.seoable_type.titleize
132
+ end
133
+ column 'Id' do |dynamic_seo|
134
+ dynamic_seo.seoable_id
135
+ end
136
+ column 'Title' do |dynamic_seo|
137
+ dynamic_seo.title.titleize
138
+ end
139
+ column :created_at
140
+ column :updated_at
141
+ actions defaults: false do |dynamic_seo|
142
+ link_to('View', "/admin/dynamic_seo_by_types/#{dynamic_seo.id}?type=#{dynamic_seo.seoable_type}")
143
+ end
144
+ end
145
+
146
+ controller do
147
+ def permitted_params
148
+ params.permit!
149
+ end
150
+
151
+ def scoped_collection
152
+ DynamicSeo.where(seoable_type: params[:type])
153
+ end
154
+ end
155
+ end
156
+
157
+ ActiveAdmin.register SitemapSeo do
158
+ menu label: 'Sitemap Seo', priority: 3, parent: 'SEOData'
159
+ config.filters = false
160
+ actions :all, except: %i[destroy new]
161
+
162
+ show title: proc { |sitemap_seo| "#{sitemap_seo.sitemap_controller.titleize} - #{sitemap_seo.sitemap_action.titleize}" } do
163
+ attributes_table do
164
+ row('Controller', &:sitemap_controller)
165
+ row('Action', &:sitemap_action)
166
+ row :priority
167
+ row 'Period' do |sitemap_seo|
168
+ sitemap_seo.period.titleize
169
+ end
170
+ row :status
171
+ row :created_at
172
+ row :updated_at
173
+ end
174
+ end
175
+
176
+ index title: 'Sitemap Seo' do
177
+ column 'Controller' do |sitemap_seo|
178
+ sitemap_seo.sitemap_controller.titleize
179
+ end
180
+ column 'Action' do |sitemap_seo|
181
+ sitemap_seo.sitemap_action.titleize
182
+ end
183
+ column :priority
184
+ column 'Period' do |sitemap_seo|
185
+ sitemap_seo.period.titleize
186
+ end
187
+ column :status
188
+ column :created_at
189
+ column :updated_at
190
+ actions
191
+ end
192
+
193
+ form do |f|
194
+ f.inputs do
195
+ f.input :sitemap_controller, input_html: { readonly: true }
196
+ f.input :sitemap_action, input_html: { readonly: true }
197
+ f.input :priority
198
+ f.input :period, as: :select, collection: SitemapSeo.periods.keys.map {|e|[e.titleize, e]}
199
+ f.input :status
200
+ end
201
+ f.actions
202
+ end
203
+
204
+ controller do
205
+ def permitted_params
206
+ params.permit!
207
+ end
208
+ end
209
+ end
210
+
211
+ ActiveAdmin.register GoogleAnalyticSeo do
212
+ menu label: 'Google Analytics', priority: 4, parent: 'SEOData'
213
+ config.filters = false
214
+ actions :all, except: %i[destroy new]
215
+
216
+ show title: proc { |google_analytic| "#{google_analytic.title.titleize}" } do
217
+ attributes_table do
218
+ row 'Title' do |google_analytic|
219
+ google_analytic.title.titleize
220
+ end
221
+ row :content
222
+ row :created_at
223
+ row :updated_at
224
+ end
225
+ end
226
+
227
+ index title: 'Google Analytics' do
228
+ column 'Title' do |google_analytic|
229
+ google_analytic.title.titleize
230
+ end
231
+ column :content
232
+ column :created_at
233
+ column :updated_at
234
+ actions
235
+ end
236
+
237
+ form do |f|
238
+ f.inputs do
239
+ f.input :title, input_html: { readonly: true }
240
+ f.input :content
241
+ end
242
+ f.actions
243
+ end
244
+
245
+ controller do
246
+ def permitted_params
247
+ params.permit!
248
+ end
249
+ end
250
+ end