seo_sensei 0.0.0.1 → 0.0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/seo_sensei/generate_translations_generator.rb +13 -0
- data/lib/generators/seo_sensei/install_generator.rb +37 -0
- data/lib/generators/templates/migration.rb +14 -0
- data/lib/generators/templates/seo_sensei.rb +5 -0
- data/lib/seo_sensei/controllers/helpers.rb +5 -9
- data/lib/seo_sensei/lookup.rb +16 -0
- data/lib/seo_sensei/lookups/database.rb +12 -0
- data/lib/seo_sensei/lookups/default_translation.rb +16 -0
- data/lib/seo_sensei/lookups/translation.rb +24 -0
- data/lib/seo_sensei/lookups/translation_attributes.rb +15 -0
- data/lib/seo_sensei/models/seo_tag.rb +11 -0
- data/lib/seo_sensei/version.rb +1 -1
- data/lib/seo_sensei.rb +23 -0
- metadata +11 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acfe5bb9d4f7612b10374ad40fd84af8d332cbd52d576c75f58d899a8e88e21a
|
4
|
+
data.tar.gz: e4ec71cd3597227fa95ff8e8442be66b2f06ca15ec6de680b2d2e281b690c88f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88c8ebf9ab0b6ff93de5720d3d5725ed298d7854ca4a6d0b16187563d7c4cec23b14e512079b499b005b896f8880cfc2b24466773759f71042b6ed20e4a081e1
|
7
|
+
data.tar.gz: 488a4254c5999edee4e3584ac3d282c80b78089fc6bf515d595af9bc2c051685d861baeacdca242869adcdda082990a2b79f7f6a9d9f33322a1061ba5edf9e03
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators/base'
|
4
|
+
|
5
|
+
module SeoSensei
|
6
|
+
module Generators
|
7
|
+
class GenerateTranslationsGenerator < Rails::Generators::Base
|
8
|
+
source_root File.expand_path("../../templates", __FILE__)
|
9
|
+
|
10
|
+
desc ""
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators/base'
|
4
|
+
|
5
|
+
module SeoSensei
|
6
|
+
module Generators
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
8
|
+
source_root File.expand_path("../../templates", __FILE__)
|
9
|
+
|
10
|
+
desc "Creates a SeoSensei initializer and copy locale file to your application."
|
11
|
+
|
12
|
+
def copy_initializer
|
13
|
+
template "seo_sensei.rb", "config/initializers/seo_sensei.rb"
|
14
|
+
end
|
15
|
+
|
16
|
+
def copy_migration
|
17
|
+
template "migration.rb", "db/migrate/#{Time.now.strftime('%Y%m%d%H%M')}_create_seo_sensei.rb", migration_version: migration_version
|
18
|
+
end
|
19
|
+
|
20
|
+
def copy_locale
|
21
|
+
copy_file "../../../config/locales/en.yml", "config/locales/seo_sensei.en.yml"
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def rails5_and_up?
|
27
|
+
Rails::VERSION::MAJOR >= 5
|
28
|
+
end
|
29
|
+
|
30
|
+
def migration_version
|
31
|
+
if rails5_and_up?
|
32
|
+
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CreateSeoSensei < ActiveRecord::Migration<%= migration_version %>
|
4
|
+
def change
|
5
|
+
create_table :seo_tags do |t|
|
6
|
+
t.references :seoable, polymorphic: true
|
7
|
+
t.string :title
|
8
|
+
t.string :keywords
|
9
|
+
t.string :description
|
10
|
+
|
11
|
+
t.timestamps null: false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -9,21 +9,17 @@ module SeoSensei
|
|
9
9
|
def enable_seo(options = {})
|
10
10
|
before_action(options) do
|
11
11
|
resource_name = options.delete(:for) || controller_name
|
12
|
-
translated_seo =
|
13
|
-
|
12
|
+
if (translated_seo = ::SeoSensei::Lookup.call(controller_name: resource_name, action_name: action_name))
|
13
|
+
set_meta_tags(translated_seo)
|
14
|
+
end
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
19
|
def seo_tags_with(resource)
|
19
|
-
|
20
|
-
|
21
|
-
seo_attributes = translated_seo.keys.inject({}) do |h, k|
|
22
|
-
h[k] = I18n.t("seo.#{controller_name}.#{action_name}.#{k.to_s}", attributes.symbolize_keys)
|
23
|
-
h
|
20
|
+
if (translated_seo = ::SeoSensei::Lookup.call(controller_name: controller_name, action_name: action_name, resource: resource))
|
21
|
+
set_meta_tags(translated_seo)
|
24
22
|
end
|
25
|
-
|
26
|
-
set_meta_tags(seo_attributes) if seo_attributes.present?
|
27
23
|
end
|
28
24
|
end
|
29
25
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'seo_sensei/lookups/database'
|
2
|
+
require 'seo_sensei/lookups/translation_attributes'
|
3
|
+
require 'seo_sensei/lookups/translation'
|
4
|
+
require 'seo_sensei/lookups/default_translation'
|
5
|
+
|
6
|
+
module SeoSensei
|
7
|
+
class Lookup
|
8
|
+
def self.call(controller_name:, action_name:, resource: nil)
|
9
|
+
lookup = ::SeoSensei::Lookups::Database.call(resource) ||
|
10
|
+
::SeoSensei::Lookups::Translation.call(controller_name, action_name, resource) ||
|
11
|
+
::SeoSensei::Lookups::DefaultTranslation.call
|
12
|
+
|
13
|
+
lookup.to_h.presence
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module SeoSensei
|
2
|
+
module Lookups
|
3
|
+
class Database
|
4
|
+
def self.call(resource)
|
5
|
+
return if SeoSensei.configuration.disable_database_lookup
|
6
|
+
return if resource.blank? || resource.is_a?(Hash)
|
7
|
+
|
8
|
+
::SeoSensei::Models::SeoTag.find_by(seoable: resource)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module SeoSensei
|
2
|
+
module Lookups
|
3
|
+
class DefaultTranslation
|
4
|
+
def self.call
|
5
|
+
translation_key = [
|
6
|
+
SeoSensei.configuration.translation_key.to_s,
|
7
|
+
'default'
|
8
|
+
].join('.')
|
9
|
+
|
10
|
+
return unless I18n.exists?(translation_key)
|
11
|
+
|
12
|
+
I18n.t(translation_key)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SeoSensei
|
2
|
+
module Lookups
|
3
|
+
class Translation
|
4
|
+
def self.call(controller_name, action_name, resource)
|
5
|
+
translation_key = [
|
6
|
+
SeoSensei.configuration.translation_key.to_s,
|
7
|
+
controller_name,
|
8
|
+
action_name
|
9
|
+
].join('.')
|
10
|
+
|
11
|
+
return unless I18n.exists?(translation_key)
|
12
|
+
|
13
|
+
translations = {}
|
14
|
+
translation_attributes = ::SeoSensei::Lookups::TranslationAttributes.for(resource)
|
15
|
+
|
16
|
+
I18n.t(translation_key).keys.each do |key|
|
17
|
+
translations[key] = I18n.t("#{translation_key}.#{key}", translation_attributes.symbolize_keys)
|
18
|
+
end
|
19
|
+
|
20
|
+
translations
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/seo_sensei/version.rb
CHANGED
data/lib/seo_sensei.rb
CHANGED
@@ -1,8 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'meta-tags'
|
4
|
+
require 'seo_sensei/lookup'
|
4
5
|
require 'seo_sensei/controllers/helpers'
|
6
|
+
require 'seo_sensei/models/seo_tag'
|
5
7
|
|
6
8
|
ActiveSupport.on_load(:action_controller) do
|
7
9
|
include ::SeoSensei::Controllers::Helpers
|
8
10
|
end
|
11
|
+
|
12
|
+
module SeoSensei
|
13
|
+
class << self
|
14
|
+
attr_accessor :configuration
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.configure
|
18
|
+
self.configuration ||= Configuration.new
|
19
|
+
yield(configuration)
|
20
|
+
end
|
21
|
+
|
22
|
+
class Configuration
|
23
|
+
attr_accessor :translation_key, :disable_seo, :disable_database_lookup
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@disable_database_lookup = false
|
27
|
+
@disable_seo = true
|
28
|
+
@translation_key = :seo
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seo_sensei
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.0.
|
4
|
+
version: 0.0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paweł Dąbrowski
|
@@ -78,8 +78,18 @@ executables: []
|
|
78
78
|
extensions: []
|
79
79
|
extra_rdoc_files: []
|
80
80
|
files:
|
81
|
+
- lib/generators/seo_sensei/generate_translations_generator.rb
|
82
|
+
- lib/generators/seo_sensei/install_generator.rb
|
83
|
+
- lib/generators/templates/migration.rb
|
84
|
+
- lib/generators/templates/seo_sensei.rb
|
81
85
|
- lib/seo_sensei.rb
|
82
86
|
- lib/seo_sensei/controllers/helpers.rb
|
87
|
+
- lib/seo_sensei/lookup.rb
|
88
|
+
- lib/seo_sensei/lookups/database.rb
|
89
|
+
- lib/seo_sensei/lookups/default_translation.rb
|
90
|
+
- lib/seo_sensei/lookups/translation.rb
|
91
|
+
- lib/seo_sensei/lookups/translation_attributes.rb
|
92
|
+
- lib/seo_sensei/models/seo_tag.rb
|
83
93
|
- lib/seo_sensei/version.rb
|
84
94
|
homepage: http://github.com/rubyhero/seo_sensei
|
85
95
|
licenses:
|