hancock_cms_seo 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +4 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +86 -0
  9. data/Rakefile +1 -0
  10. data/app/assets/javascripts/hancock/rails_admin/plugins/seo.coffee +4 -0
  11. data/app/assets/javascripts/hancock/rails_admin/plugins/seo/custom/ui.coffee +0 -0
  12. data/app/assets/stylesheets/hancock/rails_admin/plugins/seo.sass +3 -0
  13. data/app/assets/stylesheets/hancock/rails_admin/plugins/seo/custom/theming.sass +0 -0
  14. data/app/assets/stylesheets/hancock/rails_admin/plugins/seo/footer_nav_links.sass +16 -0
  15. data/app/controllers/concerns/hancock/seo/x_frame_options.rb +42 -0
  16. data/app/helpers/hancock/seo/seo_helper.rb +60 -0
  17. data/app/models/concerns/hancock/seo/decorators/seo.rb +60 -0
  18. data/app/models/concerns/hancock/seo/decorators/sitemap_data.rb +35 -0
  19. data/app/models/concerns/hancock/seo/seoable.rb +71 -0
  20. data/app/models/concerns/hancock/seo/sitemap_data_field.rb +37 -0
  21. data/app/models/concerns/hancock/seo/sitemapable.rb +7 -0
  22. data/app/models/hancock/seo/seo.rb +16 -0
  23. data/app/models/hancock/seo/sitemap_data.rb +16 -0
  24. data/app/views/blocks/_seo_block.html.slim +25 -0
  25. data/app/views/blocks/_seo_block_with_obj.html.slim +18 -0
  26. data/app/views/hancock/seo/blocks/_ga.html.slim +8 -0
  27. data/app/views/hancock/seo/blocks/_ym.html.slim +31 -0
  28. data/app/views/shared/_meta.html.slim +28 -0
  29. data/app/views/shared/_obj_with_seo.html.slim +38 -0
  30. data/app/views/shared/_og.html.slim +4 -0
  31. data/bin/console +14 -0
  32. data/bin/setup +7 -0
  33. data/config/initializers/hancock_seo.rb +7 -0
  34. data/config/locales/ru.hancock.seo.yml +37 -0
  35. data/hancock_cms_seo.gemspec +40 -0
  36. data/lib/generators/hancock/seo/config/config_generator.rb +13 -0
  37. data/lib/generators/hancock/seo/config/templates/hancock_seo.erb +10 -0
  38. data/lib/generators/hancock/seo/migrations/migrations_generator.rb +18 -0
  39. data/lib/generators/hancock/seo/migrations/templates/migration_seos.rb +48 -0
  40. data/lib/generators/hancock/seo/models/decorators_generator.rb +24 -0
  41. data/lib/generators/hancock/seo/models/seo_generator.rb +39 -0
  42. data/lib/generators/hancock/seo/models/sitemap_data_generator.rb +39 -0
  43. data/lib/generators/hancock/seo/models/templates/seo.erb +57 -0
  44. data/lib/generators/hancock/seo/models/templates/sitemap_data.erb +31 -0
  45. data/lib/generators/hancock/seo/sitemap/sitemap_generator.rb +27 -0
  46. data/lib/generators/hancock/seo/sitemap/templates/sitemap.erb +31 -0
  47. data/lib/hancock/seo/admin.rb +24 -0
  48. data/lib/hancock/seo/admin/seo.rb +69 -0
  49. data/lib/hancock/seo/admin/sitemap_data.rb +47 -0
  50. data/lib/hancock/seo/configuration.rb +29 -0
  51. data/lib/hancock/seo/engine.rb +44 -0
  52. data/lib/hancock/seo/models/active_record/seo.rb +14 -0
  53. data/lib/hancock/seo/models/active_record/sitemap_data.rb +11 -0
  54. data/lib/hancock/seo/models/mongoid/seo.rb +25 -0
  55. data/lib/hancock/seo/models/mongoid/sitemap_data.rb +24 -0
  56. data/lib/hancock/seo/models/seo.rb +114 -0
  57. data/lib/hancock/seo/models/sitemap_data.rb +79 -0
  58. data/lib/hancock/seo/version.rb +5 -0
  59. data/lib/hancock_cms_seo.rb +43 -0
  60. data/release.sh +6 -0
  61. metadata +193 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 47fa9a50126db8a16d614a5fb6e72a3d68e98969
4
+ data.tar.gz: af8810345cbfa83152832e19901c021879e93371
5
+ SHA512:
6
+ metadata.gz: b6c127efdf5eefb6bf31a66b29ccc8c0dd2b8499d0a03e872ced719d3f7f318aa5816a0bfe4a5baffaecf22c497d02a731830410fbbbb83d9991090e87c41125
7
+ data.tar.gz: 3ccd0bd7b5d4533f31a940996daf7a3a43dafff892ba4df36862fc242780bb9d9e24061bc5eea875c2890334d34332fcd5d894a4d99df6407d6e0a265c50aa82
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ hancock_seo
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hancock_cms_seo.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Alexander Kiseliev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # HancockCmsSeo
2
+
3
+ ### Remaded from [EnjoyCMSSeo](https://github.com/enjoycreative/enjoy_cms_seo)
4
+
5
+ SEO and sitemap fields for [HancockCMS](https://github.com/red-rocks/hancock_cms).
6
+ Add Seo support to HancockCMS plugins by default and other objects in two lines.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'hancock_cms_seo'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install hancock_cms_seo
23
+
24
+ ## Usage
25
+
26
+ ### Mongoid
27
+
28
+ Add this in your model for attributes
29
+ ```ruby
30
+ include Hancock::Seo::Seoable
31
+ include Hancock::Seo::SitemapDataField
32
+ ```
33
+
34
+ and this for rails_admin config
35
+ ```ruby
36
+ group :seo do
37
+ active false
38
+ field :seo
39
+ end
40
+ group :sitemap_data do
41
+ active false
42
+ field :sitemap_data
43
+ end
44
+ ```
45
+
46
+ Also you can generate and then edit config/initializers/hancock_seo.rb
47
+
48
+ $ rails g hancock:seo:config
49
+
50
+ SEO fields (h1, title, keywords, description, og_title, og_image, robots) and sitemap_data fields(sitemap_show, sitemap_lastmod, sitemap_changefreq, sitemap_priority) are delegated to your model.
51
+
52
+ #### Sitemap
53
+
54
+ Also you can use [SitemapGenerator](https://github.com/kjvarga/sitemap_generator) for sitemap.
55
+
56
+ #### Google Analitics and Yandex Metrika
57
+
58
+ We have helper methods for this. Usage
59
+ ```ruby
60
+ hancock_ym_counter_tag('counter_id')
61
+ ```
62
+ or
63
+ ```ruby
64
+ hancock_ga_counter_tag('counter_id')
65
+ ```
66
+ or
67
+ ```ruby
68
+ render_hancock_counters(ym_counter_id: 'counter_id1', ga_counter_id: 'counter_id2')
69
+ ```
70
+ [More](https://github.com/red-rocks/hancock_cms_seo/blob/master/app/helpers/hancock/seo/seo_helper.rb)
71
+
72
+
73
+ ## Development
74
+
75
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
76
+
77
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
78
+
79
+ ## Contributing
80
+
81
+ Bug reports and pull requests are welcome on GitHub at https://github.com/red-rocks/hancock_cms_seo.
82
+
83
+
84
+ ## License
85
+
86
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,4 @@
1
+ #= require_self
2
+ #= require "hancock/rails_admin/plugins/seo/custom/ui"
3
+
4
+ window.hancock.plugins.seo ||= {}
@@ -0,0 +1,3 @@
1
+ @import "hancock/rails_admin/plugins/seo/footer_nav_links"
2
+
3
+ @import "hancock/rails_admin/plugins/seo/custom/theming"
@@ -0,0 +1,16 @@
1
+ .footer-nav-link.sitemap, .footer-nav-link.robots_txt
2
+ a
3
+ font-size: 0
4
+ &:before
5
+ display: inline-block
6
+ font-family: FontAwesome
7
+ font-size: 18px
8
+ text-rendering: auto
9
+ -webkit-font-smoothing: antialiased
10
+ -moz-osx-font-smoothing: grayscale
11
+ content: "\f0e8"
12
+ box-sizing: border-box
13
+
14
+ .footer-nav-link.robots_txt a:before
15
+ content: "\f0f6"
16
+ font-size: 18px
@@ -0,0 +1,42 @@
1
+ module Hancock::Seo::XFrameOptions
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ def clear_x_frame_options
6
+ begin
7
+ if x_frame_options_referer_regexp and request.referer =~ x_frame_options_referer_regexp
8
+ response.headers.delete('X-Frame-Options')
9
+ else
10
+ if defined?(Addressable)
11
+ _domain = Addressable::URI.parse(request.referer).domain
12
+ else
13
+ _domain = URI.parse(request.referer).host
14
+ end
15
+
16
+ if base_site_host.is_a?(Regexp)
17
+ response.headers.delete('X-Frame-Options') if _domain =~ base_site_host
18
+ else
19
+ response.headers.delete('X-Frame-Options') if _domain == base_site_host
20
+ end
21
+ end
22
+ rescue
23
+ end
24
+ end
25
+ end
26
+
27
+ class_methods do
28
+ def clear_x_frame_options
29
+ after_action :clear_x_frame_options
30
+ end
31
+ end
32
+
33
+ protected
34
+ def x_frame_options_referer_regexp
35
+ # /^https?:\/\/([^\/]+metrika.*yandex.(ru|ua|com|com.tr|by|kz)|([^\/]+.)?webvisor.com)\//
36
+ /^https?\:\/\/([^\/]*metrika.*yandex\.(ru|ua|com|com\.tr|by|kz)|([^\/]+\.)?webvisor\.com)\//i
37
+ end
38
+ def base_site_host
39
+ request.domain
40
+ end
41
+
42
+ end
@@ -0,0 +1,60 @@
1
+ module Hancock::Seo::SeoHelper
2
+
3
+ def hancock_ym_counter_tag(counter_id)
4
+ return nil if counter_id.blank?
5
+ render partial: "hancock/seo/blocks/ym", locals: {counter_id: counter_id}
6
+ end
7
+ def hancock_ga_counter_tag(counter_id)
8
+ return nil if counter_id.blank?
9
+ render partial: "hancock/seo/blocks/ga", locals: {counter_id: counter_id}
10
+ end
11
+ def render_hancock_counters(opts = {})
12
+ ret = []
13
+
14
+ _cache_key = "ym_counter".freeze
15
+ ym_counter = Rails.cache.fetch(_cache_key) do
16
+ if Hancock::Seo.config.cache_support
17
+ Hancock::Cache::Fragment.create_unless_exists(name: _cache_key, parents: hancock_cache_views_keys)
18
+ _cache_key = [_cache_key]
19
+ _cache_key += hancock_cache_views_keys
20
+ else
21
+ _cache_key = [_cache_key]
22
+ end
23
+ _add_cache_key = opts.delete(:cache_key)
24
+ _cache_key = [_cache_key, _add_cache_key].flatten if _add_cache_key
25
+
26
+ _html = Settings.ym_counter_html(default: '', kind: :code, label: 'Yandex Метрика HTML-код'.freeze, cache_keys: _cache_key).strip
27
+ unless _html.blank?
28
+ _html
29
+ else
30
+ ym_counter_id = opts[:ym_counter_id] || Settings.ym_counter_id(default: '', kind: :string, label: 'Yandex Метрика ID'.freeze, cache_keys: _cache_key).strip
31
+ ym_counter_id.blank? ? nil : hancock_ym_counter_tag(ym_counter_id)
32
+ end
33
+ end
34
+ ret << ym_counter unless ym_counter.blank?
35
+
36
+ _cache_key = "ga_counter".freeze
37
+ ga_counter = Rails.cache.fetch(_cache_key) do
38
+ if Hancock::Seo.config.cache_support
39
+ Hancock::Cache::Fragment.create_unless_exists(name: _cache_key, parents: hancock_cache_views_keys)
40
+ _cache_key = [_cache_key]
41
+ _cache_key += hancock_cache_views_keys
42
+ else
43
+ _cache_key = [_cache_key]
44
+ end
45
+ _add_cache_key = opts.delete(:cache_key)
46
+ _cache_key = [_cache_key, _add_cache_key].flatten if _add_cache_key
47
+
48
+ _html = Settings.ga_counter_html(default: '', kind: :code, label: 'Google Analitics HTML-код'.freeze, cache_keys: _cache_key).strip
49
+ unless _html.blank?
50
+ _html
51
+ else
52
+ ga_counter_id = opts[:ga_counter_id] || Settings.ga_counter_id(default: '', kind: :string, label: 'Google Analitics ID'.freeze, cache_keys: _cache_key).strip
53
+ ga_counter_id.blank? ? nil : hancock_ga_counter_tag(ga_counter_id)
54
+ end
55
+ end
56
+ ret << ga_counter unless ga_counter.blank?
57
+
58
+ ret.join.html_safe
59
+ end
60
+ end
@@ -0,0 +1,60 @@
1
+ module Hancock::Seo::Decorators
2
+ module Seo
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ # # after_save :og_image_auto_rails_admin_jcrop
7
+ # def og_image_auto_rails_admin_jcrop
8
+ # auto_rails_admin_jcrop(:og_image) # or nil for cancel autocrop
9
+ # end
10
+
11
+ # hancock_cms_attached_file(:og_image)
12
+ # def og_image_styles
13
+ # {thumb: "800x600>"}
14
+ # end
15
+ #
16
+ # def og_image_jcrop_options
17
+ # {}
18
+ # end
19
+ #
20
+ #
21
+ # def set_default_seo
22
+ # _obj = self.seoable
23
+ # if _obj and _obj.set_default_seo?
24
+ # self.h1 = _obj.default_seo_h1 if self.h1.blank?
25
+ # self.title = _obj.default_seo_title if self.title.blank?
26
+ # self.keywords = _obj.default_seo_keywords if self.keywords.blank?
27
+ # self.description = _obj.default_seo_description if self.description.blank?
28
+ # self.title = _obj.default_seo_og_title if self.title.blank?
29
+ # end
30
+ # end
31
+ #
32
+ # ############ rails_admin ##############
33
+ # def self.rails_admin_add_fields
34
+ # [] #super
35
+ # end
36
+ #
37
+ # def self.rails_admin_add_config(config)
38
+ # #super(config)
39
+ # end
40
+ #
41
+ # def self.admin_can_user_defined_actions
42
+ # [].freeze
43
+ # end
44
+ # def self.admin_cannot_user_defined_actions
45
+ # [].freeze
46
+ # end
47
+ # def self.manager_can_user_defined_actions
48
+ # [].freeze
49
+ # end
50
+ # def self.manager_cannot_user_defined_actions
51
+ # [].freeze
52
+ # end
53
+ # def self.rails_admin_user_defined_visible_actions
54
+ # [].freeze
55
+ # end
56
+
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,35 @@
1
+ module Hancock::Seo::Decorators
2
+ module SitemapData
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+
7
+ ############# rails_admin ##############
8
+ # def self.rails_admin_add_fields
9
+ # [] #super
10
+ # end
11
+ #
12
+ # def self.rails_admin_add_config(config)
13
+ # #super(config)
14
+ # end
15
+ #
16
+ # def self.admin_can_user_defined_actions
17
+ # [].freeze
18
+ # end
19
+ # def self.admin_cannot_user_defined_actions
20
+ # [].freeze
21
+ # end
22
+ # def self.manager_can_user_defined_actions
23
+ # [].freeze
24
+ # end
25
+ # def self.manager_cannot_user_defined_actions
26
+ # [].freeze
27
+ # end
28
+ # def self.rails_admin_user_defined_visible_actions
29
+ # [].freeze
30
+ # end
31
+
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,71 @@
1
+ module Hancock::Seo::Seoable
2
+ extend ActiveSupport::Concern
3
+ LOCALIZED_FIELDS = [:h1, :title, :keywords, :description, :og_title, :author]
4
+ FIELDS = LOCALIZED_FIELDS + [:og_image, :robots]
5
+
6
+ included do
7
+ has_one :seo, as: :seoable, autosave: true, class_name: "Hancock::Seo::Seo"
8
+ accepts_nested_attributes_for :seo
9
+
10
+ delegate(*FIELDS, to: :seo)
11
+ delegate(*(FIELDS.map {|f| "#{f}=".to_sym }), to: :seo)
12
+
13
+ if Hancock::Seo.config.localize
14
+ delegate(*(LOCALIZED_FIELDS.map {|f| "#{f}_translations".to_sym }), to: :seo)
15
+ delegate(*(LOCALIZED_FIELDS.map {|f| "#{f}_translations=".to_sym }), to: :seo)
16
+ end
17
+
18
+ alias seo_without_build seo
19
+ def seo
20
+ seo_without_build || build_seo
21
+ end
22
+
23
+
24
+ def default_seo_h1
25
+ if self.respond_to?(:name)
26
+ self.name
27
+ elsif self.respond_to?(:title)
28
+ self.title
29
+ end
30
+ end
31
+ def default_seo_title
32
+ if self.respond_to?(:name)
33
+ self.name
34
+ elsif self.respond_to?(:title)
35
+ self.title
36
+ end
37
+ end
38
+ def default_seo_keywords
39
+ ""
40
+ end
41
+ def default_seo_description
42
+ ""
43
+ end
44
+ def default_seo_og_title
45
+ if self.respond_to?(:name)
46
+ self.name
47
+ elsif self.respond_to?(:title)
48
+ self.title
49
+ end
50
+ end
51
+
52
+ def set_default_seo?
53
+ true
54
+ end
55
+ end
56
+
57
+ def page_title
58
+ return self.title unless self.title.blank?
59
+ self.name if self.respond_to?(:name)
60
+ end
61
+
62
+ def get_og_title
63
+ return self.og_title unless self.og_title.blank?
64
+ self.name if self.respond_to?(:name)
65
+ end
66
+
67
+ def og_image_jcrop_options
68
+ {aspectRation: 800.0/600.0}
69
+ end
70
+
71
+ end