such_meta 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +1 -0
- data/.rubocop.yml +39 -0
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +138 -0
- data/Rakefile +1 -0
- data/config/locales/such_meta.en.yml +31 -0
- data/lib/generators/such_meta/install_generator.rb +13 -0
- data/lib/such_meta.rb +17 -0
- data/lib/such_meta/controller_extensions.rb +37 -0
- data/lib/such_meta/exceptions.rb +5 -0
- data/lib/such_meta/fetcher.rb +17 -0
- data/lib/such_meta/fetchers/default_i18n_fetcher.rb +9 -0
- data/lib/such_meta/fetchers/i18n_fetcher.rb +23 -0
- data/lib/such_meta/fetchers/override_hash_fetcher.rb +14 -0
- data/lib/such_meta/fetchers/specific_i18n_fetcher.rb +9 -0
- data/lib/such_meta/version.rb +3 -0
- data/spec/data/test.yml +31 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/such_meta/controller_extensions_spec.rb +60 -0
- data/spec/such_meta/fetcher_spec.rb +20 -0
- data/spec/such_meta/fetchers/default_i18n_fetcher_spec.rb +20 -0
- data/spec/such_meta/fetchers/i18n_fetcher_spec.rb +32 -0
- data/spec/such_meta/fetchers/override_hash_fetcher_spec.rb +14 -0
- data/spec/such_meta/fetchers/specific_i18n_fetcher_spec.rb +20 -0
- data/such_meta.gemspec +35 -0
- metadata +251 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 14982da1bb32c3747a98aaa0609dfa816a648bad
|
4
|
+
data.tar.gz: c4830e3d52d116c9c49172521fc864a570055285
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3253b00d9fbdf090c8848c570a0a6c663e2e8ebaf6b16834c4beb5b7065bc5d8c4544338f695867ea6d4c1aac5ff1611cb509e822f46ca2db861a5b161f9ef93
|
7
|
+
data.tar.gz: 6167d13668634c402128d0f29df41daaf26175e2c843612c9b1503f838e28301edb7ae7d76c21bbb9f8f4525c8eeaf8e6e6ac9e624a0884f2dc1ea98ff92af0a
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--format documentation --color
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
AllCops:
|
2
|
+
RunRailsCops: false
|
3
|
+
Excludes:
|
4
|
+
- spec/test_app/**
|
5
|
+
- bin/**
|
6
|
+
|
7
|
+
LineLength:
|
8
|
+
Max: 120
|
9
|
+
|
10
|
+
ClassLength:
|
11
|
+
CountComments: false # count full line comments?
|
12
|
+
Max: 175
|
13
|
+
|
14
|
+
MethodLength:
|
15
|
+
CountComments: false # count full line comments?
|
16
|
+
Max: 10
|
17
|
+
|
18
|
+
HashSyntax:
|
19
|
+
EnforcedStyle: hash_rockets
|
20
|
+
|
21
|
+
Documentation:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
DefaultScope:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
CollectionMethods:
|
28
|
+
PreferredMethods:
|
29
|
+
map: 'collect'
|
30
|
+
map!: 'collect!'
|
31
|
+
reduce: 'inject'
|
32
|
+
find: 'detect'
|
33
|
+
find_all: 'select'
|
34
|
+
|
35
|
+
Output:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
HasAndBelongsToMany:
|
39
|
+
Enabled: false
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
guard 'rspec', :cmd => 'rspec --colour', :all_on_start => false, :all_after_pass => false do
|
2
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
3
|
+
watch(%r{^spec/.+_spec\.rb})
|
4
|
+
watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
5
|
+
end
|
6
|
+
|
7
|
+
guard :rubocop do
|
8
|
+
watch(/.+\.gemspec$/)
|
9
|
+
watch(/.+\.rb$/)
|
10
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
11
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Anisha Vasandani
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
# SuchMeta
|
2
|
+
|
3
|
+
A gem that simplifies SEO meta tags, allowing for customization and internationalization.
|
4
|
+
|
5
|
+
## Setup & Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'such_meta'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install such_meta
|
20
|
+
|
21
|
+
Use the built-in generator to set up `such_meta.en.yml`:
|
22
|
+
|
23
|
+
|
24
|
+
$ bundle exec rails g such_meta:install
|
25
|
+
|
26
|
+
|
27
|
+
The generator will add the `such_meta.en.yml` file to `config/locales/such_meta.en.yml`. Use this yml file to set **default** meta tags for the site and to target **specific** controller actions. Examples are included below.
|
28
|
+
|
29
|
+
## Included In This Gem:
|
30
|
+
|
31
|
+
There are two basic ways to configure your meta tags:
|
32
|
+
|
33
|
+
### Get
|
34
|
+
|
35
|
+
You can either "get" the meta tag, by passing a `tag_type`: `such_meta(tag_type)`. If there is a controller/action defined in such_meta.en.yml under `specific`, the custom tag is returned. Otherwise, the default tags defined under `default`.
|
36
|
+
|
37
|
+
|
38
|
+
### Set
|
39
|
+
|
40
|
+
Or, you can "set" the meta tag, by passing the `tag_type` and the `value` that you'd like to override: `such_meta(tag_type, value)`.
|
41
|
+
|
42
|
+
## Setting Up Your Yaml File
|
43
|
+
|
44
|
+
### Default Meta Tags:
|
45
|
+
```
|
46
|
+
en:
|
47
|
+
such_meta:
|
48
|
+
default:
|
49
|
+
title: 'Default'
|
50
|
+
description: 'Default description for Such Meta'
|
51
|
+
keywords: 'Default Keyword 1, Default Keyword 2, Default Keyword 3'
|
52
|
+
og:
|
53
|
+
title: 'Default Facebook Title'
|
54
|
+
type: 'Default Facebook Type'
|
55
|
+
image: 'Default Image'
|
56
|
+
twitter:
|
57
|
+
card: 'Default Twitter'
|
58
|
+
site: 'Default Site'
|
59
|
+
```
|
60
|
+
|
61
|
+
### Specific Meta Tags
|
62
|
+
```
|
63
|
+
en:
|
64
|
+
such_meta:
|
65
|
+
default: <!-- please see above -->
|
66
|
+
specific:
|
67
|
+
controller_name:
|
68
|
+
index:
|
69
|
+
title: 'Controller Index Title'
|
70
|
+
description: 'Description for Controller Index'
|
71
|
+
keywords: 'Keyword 1, Keyword 2, Keyword 3'
|
72
|
+
show:
|
73
|
+
title: 'Controller Show Title'
|
74
|
+
description: 'Description for Controller Show'
|
75
|
+
keywords:
|
76
|
+
og:
|
77
|
+
title: 'Facebook'
|
78
|
+
type: 'Type'
|
79
|
+
url: 'http://www.sampleurl.com'
|
80
|
+
image: 'https://image.com/300/400'
|
81
|
+
twitter:
|
82
|
+
card: 'Twitter'
|
83
|
+
site: 'Site'
|
84
|
+
```
|
85
|
+
|
86
|
+
## Recommended Usage
|
87
|
+
|
88
|
+
Here are some recommended meta tags to get you started. These tags belong in `application.html.erb` in a traditional Rails application:
|
89
|
+
|
90
|
+
### Title
|
91
|
+
|
92
|
+
`<title><%= such_meta(:title) %></title>`
|
93
|
+
|
94
|
+
### Description
|
95
|
+
|
96
|
+
`<meta name="description" content="<%= such_meta(:description) %>">`
|
97
|
+
|
98
|
+
### Keywords
|
99
|
+
|
100
|
+
`<meta name="keywords" content="<%= such_meta(:keywords) %>">`
|
101
|
+
|
102
|
+
### Facebook
|
103
|
+
|
104
|
+
`<meta property="og:title" content="<%= such_meta('og.title') %>">`
|
105
|
+
|
106
|
+
`<meta property="og:type" content="<%= such_meta('og.type') %>">`
|
107
|
+
|
108
|
+
`<meta property="og:image" content="<%= such_meta('og.image') %>">`
|
109
|
+
|
110
|
+
`<meta property="og:url" content="<%= such_meta('og.url') %>">`
|
111
|
+
|
112
|
+
### Twitter
|
113
|
+
|
114
|
+
`<meta property="twitter:card" content="<%= such_meta('twitter.card') %>">`
|
115
|
+
|
116
|
+
`<meta property="twitter:description" content="<%= such_meta('twitter.description') %>">`
|
117
|
+
|
118
|
+
`<meta property="twitter:site" content="<%= such_meta('twitter.site') %>">`
|
119
|
+
|
120
|
+
`<meta property="twitter:title" content="<%= such_meta('twitter.title') %>">`
|
121
|
+
|
122
|
+
`<meta property="twitter:image" content="<%= such_meta('twitter.image') %>">`
|
123
|
+
|
124
|
+
|
125
|
+
## Contributing
|
126
|
+
|
127
|
+
1. Fork it ( https://github.com/crushlovely/suchmeta/fork )
|
128
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
129
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
130
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
131
|
+
5. Create a new Pull Request
|
132
|
+
|
133
|
+
## Running tests
|
134
|
+
|
135
|
+
```bash
|
136
|
+
bundle exec guard
|
137
|
+
```
|
138
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
en:
|
2
|
+
such_meta:
|
3
|
+
default:
|
4
|
+
title: 'Default'
|
5
|
+
description: 'Default description for Such Meta'
|
6
|
+
keywords: 'Default Keyword 1, Default Keyword 2, Default Keyword 3'
|
7
|
+
og:
|
8
|
+
title: 'Default Facebook Title'
|
9
|
+
type: 'Default Facebook Type'
|
10
|
+
image: 'Default Image'
|
11
|
+
twitter:
|
12
|
+
card: 'Default Twitter'
|
13
|
+
site: 'Default Site'
|
14
|
+
specific:
|
15
|
+
muppets:
|
16
|
+
index:
|
17
|
+
title: 'Muppets Index Title'
|
18
|
+
description: 'Description for Muppets'
|
19
|
+
keywords: 'Keyword 1, Keyword 2, Keyword 3'
|
20
|
+
show:
|
21
|
+
title: 'Muppets Show Title'
|
22
|
+
description:
|
23
|
+
keywords:
|
24
|
+
og:
|
25
|
+
title: 'Muppet Facebook'
|
26
|
+
type: 'Muppet Type'
|
27
|
+
url: 'http://www.muppets.com'
|
28
|
+
image: 'https://placekitten.com/300/400'
|
29
|
+
twitter:
|
30
|
+
card: 'Muppet Twitter'
|
31
|
+
site: 'Muppet Site'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module SuchMeta
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path('../', __FILE__)
|
7
|
+
|
8
|
+
def copy_locale
|
9
|
+
copy_file '../../../config/locales/such_meta.en.yml', 'config/locales/such_meta.en.yml'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/such_meta.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'action_controller'
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
require 'such_meta/version'
|
5
|
+
require 'such_meta/exceptions'
|
6
|
+
require 'such_meta/fetcher'
|
7
|
+
require 'such_meta/fetchers/override_hash_fetcher'
|
8
|
+
require 'such_meta/fetchers/i18n_fetcher'
|
9
|
+
require 'such_meta/fetchers/default_i18n_fetcher'
|
10
|
+
require 'such_meta/fetchers/specific_i18n_fetcher'
|
11
|
+
|
12
|
+
require 'such_meta/controller_extensions'
|
13
|
+
|
14
|
+
module SuchMeta
|
15
|
+
end
|
16
|
+
|
17
|
+
ActionController::Base.send :include, SuchMeta::ControllerExtensions
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module SuchMeta
|
2
|
+
module ControllerExtensions
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
helper_method :such_meta
|
7
|
+
end
|
8
|
+
|
9
|
+
def such_meta(tag_type, value = nil)
|
10
|
+
value ? set_meta_data(tag_type, value) : get_meta_data(tag_type)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def such_meta_data
|
16
|
+
@such_meta_data ||= {}
|
17
|
+
end
|
18
|
+
|
19
|
+
def set_meta_data(tag_type, value)
|
20
|
+
such_meta_data[tag_type.to_sym] = value
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_meta_data(tag_type)
|
24
|
+
content = [
|
25
|
+
# 1. Check the override hash
|
26
|
+
OverrideHashFetcher.new(tag_type, such_meta_data),
|
27
|
+
# 2. Check for specific I18n data
|
28
|
+
SpecificI18nFetcher.new(tag_type, controller_name, action_name),
|
29
|
+
# 3. Check for default I18n data
|
30
|
+
DefaultI18nFetcher.new(tag_type, controller_name, action_name)
|
31
|
+
].detect(&:content?)
|
32
|
+
|
33
|
+
# Return the content or raise an error
|
34
|
+
content ? content.call : fail(MissingMetaDataError, "Missing meta data for key: #{tag_type}")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module SuchMeta
|
2
|
+
class I18nFetcher < Fetcher
|
3
|
+
attr_reader :controller, :action
|
4
|
+
|
5
|
+
def initialize(tag_type, controller, action)
|
6
|
+
super(tag_type)
|
7
|
+
@controller = controller
|
8
|
+
@action = action
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
I18n.t(translation_key, :raise => true)
|
13
|
+
rescue I18n::MissingTranslationData
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def translation_key
|
20
|
+
fail OverrideInSubclassError
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/data/test.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
en:
|
2
|
+
such_meta:
|
3
|
+
default:
|
4
|
+
title: 'Default'
|
5
|
+
description: 'Default description for Such Meta'
|
6
|
+
keywords: 'Default Keyword 1, Default Keyword 2, Default Keyword 3'
|
7
|
+
og:
|
8
|
+
title: 'Default Facebook Title'
|
9
|
+
type: 'Default Facebook Type'
|
10
|
+
image: 'Default Image'
|
11
|
+
twitter:
|
12
|
+
card: 'Default Twitter'
|
13
|
+
site: 'Default Site'
|
14
|
+
specific:
|
15
|
+
muppets:
|
16
|
+
index:
|
17
|
+
title: 'Muppets Index Title'
|
18
|
+
description: 'Description for Muppets'
|
19
|
+
keywords: 'Keyword 1, Keyword 2, Keyword 3'
|
20
|
+
show:
|
21
|
+
title: 'Muppets Show Title'
|
22
|
+
description:
|
23
|
+
keywords:
|
24
|
+
og:
|
25
|
+
title: 'Muppet Facebook'
|
26
|
+
type: 'Muppet Type'
|
27
|
+
url: 'http://www.muppets.com'
|
28
|
+
image: 'https://placekitten.com/300/400'
|
29
|
+
twitter:
|
30
|
+
card: 'Muppet Twitter'
|
31
|
+
site: 'Muppet Site'
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'such_meta'
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class MuppetsController < ActionController::Base
|
4
|
+
def index
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
describe SuchMeta::ControllerExtensions do
|
9
|
+
subject { MuppetsController.new }
|
10
|
+
|
11
|
+
before do
|
12
|
+
I18n.backend.load_translations('spec/data/test.yml')
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'SuchMeta module' do
|
16
|
+
it 'should be mixed into ActionController::Base' do
|
17
|
+
expect(ActionController::Base.included_modules).to include(SuchMeta::ControllerExtensions)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should respond to 'such_meta' helper" do
|
21
|
+
expect(subject).to respond_to(:such_meta)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#such_meta' do
|
26
|
+
let(:tag_type) { :title }
|
27
|
+
let(:value) { nil }
|
28
|
+
let(:default_translation_key) { "such_meta.default.#{tag_type}" }
|
29
|
+
|
30
|
+
context 'specific translation is not provided' do
|
31
|
+
it 'returns default translation for tag_type' do
|
32
|
+
expect(subject.such_meta(tag_type)).to eq(I18n.t(default_translation_key))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'overriding the defaults' do
|
37
|
+
context 'via a controller/action specific translation' do
|
38
|
+
before do
|
39
|
+
ActionController::Base.any_instance.stub(:controller_name).and_return('muppets')
|
40
|
+
ActionController::Base.any_instance.stub(:action_name).and_return('show')
|
41
|
+
end
|
42
|
+
|
43
|
+
let(:specific_translation_key) { "such_meta.specific.muppets.show.#{tag_type}" }
|
44
|
+
|
45
|
+
it 'returns specific translation for tag_type' do
|
46
|
+
expect(subject.such_meta(tag_type)).to eq(I18n.t(specific_translation_key))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'via a value passed in' do
|
51
|
+
let(:value) { 'Sample String' }
|
52
|
+
|
53
|
+
it 'returns overriden translation for tag_type' do
|
54
|
+
subject.such_meta(tag_type, value)
|
55
|
+
expect(subject.such_meta(tag_type)).to eq(value)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SuchMeta::Fetcher do
|
4
|
+
subject { SuchMeta::Fetcher.new(tag_type) }
|
5
|
+
let(:tag_type) { :title }
|
6
|
+
|
7
|
+
context 'tag type is provided' do
|
8
|
+
it 'returns appropriate tag type' do
|
9
|
+
expect(subject.tag_type).to eq(tag_type)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#call' do
|
14
|
+
subject { SuchMeta::Fetcher.new(tag_type).call }
|
15
|
+
|
16
|
+
it 'throws an error' do
|
17
|
+
expect { subject }.to raise_error(SuchMeta::OverrideInSubclassError)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SuchMeta::DefaultI18nFetcher do
|
4
|
+
before do
|
5
|
+
I18n.backend.load_translations('spec/data/test.yml')
|
6
|
+
end
|
7
|
+
|
8
|
+
subject { SuchMeta::DefaultI18nFetcher.new(tag_type, controller, action) }
|
9
|
+
let(:tag_type) { :title }
|
10
|
+
let(:controller) { nil }
|
11
|
+
let(:action) { nil }
|
12
|
+
|
13
|
+
context 'I18n translations are not available for given controller and action' do
|
14
|
+
describe '#call' do
|
15
|
+
it 'returns the default title' do
|
16
|
+
expect(subject.call).to eq(I18n.t("such_meta.default.#{tag_type}"))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SuchMeta::I18nFetcher do
|
4
|
+
before do
|
5
|
+
I18n.backend.load_translations('spec/data/test.yml')
|
6
|
+
end
|
7
|
+
|
8
|
+
subject { SuchMeta::I18nFetcher.new(tag_type, controller, action) }
|
9
|
+
let(:tag_type) { :title }
|
10
|
+
|
11
|
+
context 'I18n translations are available for given controller and action' do
|
12
|
+
let(:controller) { 'muppets' }
|
13
|
+
let(:action) { 'index' }
|
14
|
+
|
15
|
+
describe '#call' do
|
16
|
+
it 'throws an error' do
|
17
|
+
expect { subject.call }.to raise_error(SuchMeta::OverrideInSubclassError)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'I18n translations are not available for given controller and action' do
|
23
|
+
let(:controller) { nil }
|
24
|
+
let(:action) { nil }
|
25
|
+
|
26
|
+
describe '#call' do
|
27
|
+
it 'throws an error' do
|
28
|
+
expect { subject.call }.to raise_error(SuchMeta::OverrideInSubclassError)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SuchMeta::OverrideHashFetcher do
|
4
|
+
subject { SuchMeta::OverrideHashFetcher.new(tag_type, :title => 'custom title') }
|
5
|
+
let(:tag_type) { :title }
|
6
|
+
|
7
|
+
context 'custom hash is provided' do
|
8
|
+
describe '#call' do
|
9
|
+
it 'returns overriden value of hash' do
|
10
|
+
expect(subject.call).to eq('custom title')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SuchMeta::SpecificI18nFetcher do
|
4
|
+
before do
|
5
|
+
I18n.backend.load_translations('spec/data/test.yml')
|
6
|
+
end
|
7
|
+
|
8
|
+
subject { SuchMeta::SpecificI18nFetcher.new(tag_type, controller, action) }
|
9
|
+
let(:tag_type) { :title }
|
10
|
+
let(:controller) { 'muppets' }
|
11
|
+
let(:action) { 'index' }
|
12
|
+
|
13
|
+
context 'I18n translations are available for given controller and action' do
|
14
|
+
describe '#call' do
|
15
|
+
it 'returns an internationalized, custom meta data' do
|
16
|
+
expect(subject.call).to eq(I18n.t("such_meta.specific.#{controller}.#{action}.#{tag_type}"))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/such_meta.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'such_meta/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'such_meta'
|
9
|
+
spec.version = SuchMeta::VERSION
|
10
|
+
spec.authors = ['Anisha Vasandani', 'PJ Kelly']
|
11
|
+
spec.email = ['anisha@crushlovely.com', 'pj@crushlovely.com']
|
12
|
+
spec.summary = 'Simple SEO meta tag helper that offers customization and internationalization.'
|
13
|
+
spec.description = 'Simple SEO meta tag helper that offers customization and internationalization.'
|
14
|
+
spec.homepage = 'https://github.com/crushlovely/such_meta'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'actionpack'
|
23
|
+
spec.add_dependency 'i18n'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'rails', '~> 4.2.0'
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
27
|
+
spec.add_development_dependency 'pry'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.4.2'
|
29
|
+
spec.add_development_dependency 'rspec'
|
30
|
+
spec.add_development_dependency 'rubocop'
|
31
|
+
spec.add_development_dependency 'guard'
|
32
|
+
spec.add_development_dependency 'guard-rspec'
|
33
|
+
spec.add_development_dependency 'guard-rubocop'
|
34
|
+
spec.add_development_dependency 'codeclimate-test-reporter'
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,251 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: such_meta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anisha Vasandani
|
8
|
+
- PJ Kelly
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: actionpack
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: i18n
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rails
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 4.2.0
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 4.2.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: bundler
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.7'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.7'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: pry
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rake
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 10.4.2
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 10.4.2
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rspec
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: rubocop
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: guard
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: guard-rspec
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
type: :development
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
- !ruby/object:Gem::Dependency
|
155
|
+
name: guard-rubocop
|
156
|
+
requirement: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
type: :development
|
162
|
+
prerelease: false
|
163
|
+
version_requirements: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
- !ruby/object:Gem::Dependency
|
169
|
+
name: codeclimate-test-reporter
|
170
|
+
requirement: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
type: :development
|
176
|
+
prerelease: false
|
177
|
+
version_requirements: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
description: Simple SEO meta tag helper that offers customization and internationalization.
|
183
|
+
email:
|
184
|
+
- anisha@crushlovely.com
|
185
|
+
- pj@crushlovely.com
|
186
|
+
executables: []
|
187
|
+
extensions: []
|
188
|
+
extra_rdoc_files: []
|
189
|
+
files:
|
190
|
+
- ".gitignore"
|
191
|
+
- ".rspec"
|
192
|
+
- ".rubocop.yml"
|
193
|
+
- Gemfile
|
194
|
+
- Guardfile
|
195
|
+
- LICENSE.txt
|
196
|
+
- README.md
|
197
|
+
- Rakefile
|
198
|
+
- config/locales/such_meta.en.yml
|
199
|
+
- lib/generators/such_meta/install_generator.rb
|
200
|
+
- lib/such_meta.rb
|
201
|
+
- lib/such_meta/controller_extensions.rb
|
202
|
+
- lib/such_meta/exceptions.rb
|
203
|
+
- lib/such_meta/fetcher.rb
|
204
|
+
- lib/such_meta/fetchers/default_i18n_fetcher.rb
|
205
|
+
- lib/such_meta/fetchers/i18n_fetcher.rb
|
206
|
+
- lib/such_meta/fetchers/override_hash_fetcher.rb
|
207
|
+
- lib/such_meta/fetchers/specific_i18n_fetcher.rb
|
208
|
+
- lib/such_meta/version.rb
|
209
|
+
- spec/data/test.yml
|
210
|
+
- spec/spec_helper.rb
|
211
|
+
- spec/such_meta/controller_extensions_spec.rb
|
212
|
+
- spec/such_meta/fetcher_spec.rb
|
213
|
+
- spec/such_meta/fetchers/default_i18n_fetcher_spec.rb
|
214
|
+
- spec/such_meta/fetchers/i18n_fetcher_spec.rb
|
215
|
+
- spec/such_meta/fetchers/override_hash_fetcher_spec.rb
|
216
|
+
- spec/such_meta/fetchers/specific_i18n_fetcher_spec.rb
|
217
|
+
- such_meta.gemspec
|
218
|
+
homepage: https://github.com/crushlovely/such_meta
|
219
|
+
licenses:
|
220
|
+
- MIT
|
221
|
+
metadata: {}
|
222
|
+
post_install_message:
|
223
|
+
rdoc_options: []
|
224
|
+
require_paths:
|
225
|
+
- lib
|
226
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
227
|
+
requirements:
|
228
|
+
- - ">="
|
229
|
+
- !ruby/object:Gem::Version
|
230
|
+
version: '0'
|
231
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
232
|
+
requirements:
|
233
|
+
- - ">="
|
234
|
+
- !ruby/object:Gem::Version
|
235
|
+
version: '0'
|
236
|
+
requirements: []
|
237
|
+
rubyforge_project:
|
238
|
+
rubygems_version: 2.4.5
|
239
|
+
signing_key:
|
240
|
+
specification_version: 4
|
241
|
+
summary: Simple SEO meta tag helper that offers customization and internationalization.
|
242
|
+
test_files:
|
243
|
+
- spec/data/test.yml
|
244
|
+
- spec/spec_helper.rb
|
245
|
+
- spec/such_meta/controller_extensions_spec.rb
|
246
|
+
- spec/such_meta/fetcher_spec.rb
|
247
|
+
- spec/such_meta/fetchers/default_i18n_fetcher_spec.rb
|
248
|
+
- spec/such_meta/fetchers/i18n_fetcher_spec.rb
|
249
|
+
- spec/such_meta/fetchers/override_hash_fetcher_spec.rb
|
250
|
+
- spec/such_meta/fetchers/specific_i18n_fetcher_spec.rb
|
251
|
+
has_rdoc:
|