crystalmeta 0.9.4 → 1.0.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.
- checksums.yaml +7 -0
- data/crystalmeta.gemspec +5 -5
- data/lib/crystal/controller_extensions.rb +1 -1
- data/lib/crystal/railtie.rb +1 -1
- data/lib/crystal/tag.rb +1 -1
- data/lib/crystal/version.rb +1 -1
- data/spec/dummy/config/application.rb +4 -2
- data/spec/features/meta_tags_spec.rb +11 -11
- data/spec/unit/hash_with_stringify_keys_spec.rb +6 -6
- data/spec/unit/meta_spec.rb +3 -3
- data/spec/unit/tag_spec.rb +28 -16
- data/spec/unit/tags_spec.rb +13 -13
- metadata +22 -31
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 19331277d1932fee3a6c96921b93845d1f83e083
|
4
|
+
data.tar.gz: beb30a8c5771a24130fda16760b29fbe0323a1eb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a89323f7eba66efbf004e37200bc3901e85588932745f439cdbedf879ddeb4cb55a263b8d777143142fbfa8e77033488e6f45726ea03821fdc87d144b1230c81
|
7
|
+
data.tar.gz: 29348d7a734321352becfa4a21f3603577fc11c3a59b3c8c5046a3355deb78963f09a3f886daf30b1fee1e6d4580d6c7476c2d46dde5ce69761227e3d68de285
|
data/crystalmeta.gemspec
CHANGED
@@ -8,16 +8,16 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = Crystal::VERSION
|
9
9
|
gem.authors = ["Max Savchenko"]
|
10
10
|
gem.email = ["robotector@gmail.com"]
|
11
|
-
gem.description = %q{Crystal clean meta tags for Rails applications.
|
11
|
+
gem.description = %q{Crystal clean meta tags for Rails applications. Supports I18n. Perfect for OpenGraph.}
|
12
12
|
gem.summary = %q{Crystalmeta helps you control meta tags through I18n and/or manually. It plays well with OpenGraph.}
|
13
|
-
gem.homepage = "
|
13
|
+
gem.homepage = "https://github.com/macovsky/crystalmeta"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.add_dependency
|
21
|
-
gem.add_development_dependency 'rspec-rails', '~>
|
22
|
-
gem.add_development_dependency 'capybara', '~> 2.
|
20
|
+
gem.add_dependency 'rails', '>= 5.1.0'
|
21
|
+
gem.add_development_dependency 'rspec-rails', '~> 3.6.0'
|
22
|
+
gem.add_development_dependency 'capybara', '~> 2.15.4'
|
23
23
|
end
|
data/lib/crystal/railtie.rb
CHANGED
@@ -3,7 +3,7 @@ require 'rails/railtie'
|
|
3
3
|
module Crystal
|
4
4
|
class Railtie < Rails::Railtie
|
5
5
|
initializer 'crystalmeta.setup_action_controller' do |app|
|
6
|
-
ActiveSupport.on_load :
|
6
|
+
ActiveSupport.on_load :action_controller_base do
|
7
7
|
Crystal.setup_action_controller self
|
8
8
|
end
|
9
9
|
end
|
data/lib/crystal/tag.rb
CHANGED
data/lib/crystal/version.rb
CHANGED
@@ -20,6 +20,8 @@ module Dummy
|
|
20
20
|
# Custom directories with classes and modules you want to be autoloadable.
|
21
21
|
# config.autoload_paths += %W(#{config.root}/extras)
|
22
22
|
|
23
|
+
config.eager_load = false
|
24
|
+
|
23
25
|
# Only load the plugins named here, in the order given (default is alphabetical).
|
24
26
|
# :all can be used as a placeholder for all plugins not explicitly named.
|
25
27
|
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
@@ -56,9 +58,9 @@ module Dummy
|
|
56
58
|
# config.active_record.whitelist_attributes = true
|
57
59
|
|
58
60
|
# Enable the asset pipeline
|
59
|
-
config.assets.enabled = false
|
61
|
+
# config.assets.enabled = false
|
60
62
|
|
61
63
|
# Version of your assets, change this if you want to expire all your assets
|
62
|
-
config.assets.version = '1.0'
|
64
|
+
# config.assets.version = '1.0'
|
63
65
|
end
|
64
66
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe 'meta tags' do
|
3
|
+
RSpec.describe 'meta tags', type: :feature do
|
4
4
|
def meta_tags(pattern = //)
|
5
|
-
all('meta').select{|meta| pattern === meta[:property] || pattern === meta[:name] }
|
5
|
+
all(:css, 'meta', visible: :hidden).select{|meta| pattern === meta[:property] || pattern === meta[:name] }
|
6
6
|
end
|
7
7
|
|
8
8
|
def value_for(pattern = //)
|
@@ -19,23 +19,23 @@ describe 'meta tags' do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'include og:title from controller' do
|
22
|
-
value_for('og:title').
|
22
|
+
expect(value_for('og:title')).to eq 'The Rock (1996)'
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'include og:image from locale' do
|
26
|
-
value_for('og:image').
|
26
|
+
expect(value_for('og:image')).to eq 'http://www.example.com/images/rock.jpg'
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'include og:image from locale' do
|
30
|
-
value_for('twitter:card').
|
30
|
+
expect(value_for('twitter:card')).to eq 'summary'
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'include og:type from controller defaults' do
|
34
|
-
value_for('og:type').
|
34
|
+
expect(value_for('og:type')).to eq 'video.movie'
|
35
35
|
end
|
36
36
|
|
37
|
-
it 'include title with interpolation' do
|
38
|
-
title.
|
37
|
+
it 'include title expect(with interpolation' do
|
38
|
+
expect(title).to eq 'The Rock (1996) - IMDb'
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -45,12 +45,12 @@ describe 'meta tags' do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'include og:title & og:type from views' do
|
48
|
-
value_for('og:title').
|
49
|
-
value_for('og:type').
|
48
|
+
expect(value_for('og:title')).to eq 'Movies'
|
49
|
+
expect(value_for('og:type')).to eq 'article'
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'include default title' do
|
53
|
-
title.
|
53
|
+
expect(title).to eq 'Movies on IMDb'
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -7,16 +7,16 @@ describe Crystal::HashWithStringifyKeys do
|
|
7
7
|
|
8
8
|
context '.new' do
|
9
9
|
it 'stringifies keys when hash is passed' do
|
10
|
-
new(:
|
10
|
+
expect(new(key: {key2: 1})).to eq Hash['key' => {'key2' => 1}]
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'keeps a default value if one argument has been passed' do
|
14
|
-
new(1)['unknown'].
|
14
|
+
expect(new(1)['unknown']).to eq 1
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'returns an empty hash when no args have been passed' do
|
18
|
-
new.
|
19
|
-
new['unknown'].
|
18
|
+
expect(new).to be_empty
|
19
|
+
expect(new['unknown']).to be_nil
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -24,8 +24,8 @@ describe Crystal::HashWithStringifyKeys do
|
|
24
24
|
it 'returns a hash with stringified keys' do
|
25
25
|
hash = new(:key => {:key2 => 1})
|
26
26
|
merge = hash.deep_merge!(new(:key => {:key2 => 2}))
|
27
|
-
merge.
|
28
|
-
merge.
|
27
|
+
expect(merge).to eq Hash['key' => {'key2' => 2}]
|
28
|
+
expect(merge).to be_kind_of(Crystal::HashWithStringifyKeys)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
data/spec/unit/meta_spec.rb
CHANGED
@@ -9,7 +9,7 @@ describe Crystal::Meta do
|
|
9
9
|
it 'stringifies keys' do
|
10
10
|
subject.store :title => 'something'
|
11
11
|
subject.store :head => 'something else'
|
12
|
-
options.
|
12
|
+
expect(options).to eq Hash['title' => 'something', 'head' => 'something else']
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'merges options deeply' do
|
@@ -28,14 +28,14 @@ describe Crystal::Meta do
|
|
28
28
|
:"fb:admins" => '322132'
|
29
29
|
})
|
30
30
|
|
31
|
-
options.
|
31
|
+
expect(options).to eq Hash[
|
32
32
|
'og' => {
|
33
33
|
'title' => 'og title',
|
34
34
|
'site_name' => 'site name 2',
|
35
35
|
'url' => 'something',
|
36
36
|
},
|
37
37
|
'fb:admins' => '322132'
|
38
|
-
|
38
|
+
]
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
data/spec/unit/tag_spec.rb
CHANGED
@@ -1,14 +1,26 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Crystal::Tag do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
RSpec.describe Crystal::Tag do
|
4
|
+
context 'for OpenGraph' do
|
5
|
+
let(:og_tag) { tag('og:title', 'Caesar must die') }
|
6
|
+
|
7
|
+
it 'has a name of og:title' do
|
8
|
+
expect(og_tag.name).to eq 'og:title'
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'has a value of ‘Caesar must die’' do
|
12
|
+
expect(og_tag.value).to eq 'Caesar must die'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'has a name_key of :property' do
|
16
|
+
expect(og_tag.name_key).to eq :property
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'for Twitter' do
|
21
|
+
it 'has a name_key of :name' do
|
22
|
+
expect(tag('twitter:title', 'Caesar must die').name_key).to eq :name
|
23
|
+
end
|
12
24
|
end
|
13
25
|
|
14
26
|
describe '#value_for_context' do
|
@@ -16,22 +28,22 @@ describe Crystal::Tag do
|
|
16
28
|
|
17
29
|
it 'returns asset path if asset' do
|
18
30
|
image = '1.png'
|
19
|
-
asset_path = "/assets/#{image}"
|
20
|
-
context.
|
21
|
-
tag('og:image', image).value_for_context(context).
|
31
|
+
asset_path = "http://www.example.com/assets/#{image}"
|
32
|
+
allow(context).to receive('image_url').with(image).and_return(asset_path)
|
33
|
+
expect(tag('og:image', image).value_for_context(context)).to eq asset_path
|
22
34
|
end
|
23
35
|
|
24
36
|
it 'returns iso8601 for date' do
|
25
|
-
tag('date', Date.parse('1979-12-09')).value_for_context(context).
|
37
|
+
expect(tag('date', Date.parse('1979-12-09')).value_for_context(context)).to eq '1979-12-09'
|
26
38
|
end
|
27
39
|
|
28
40
|
it 'returns iso8601 for time' do
|
29
|
-
tag('date', DateTime.parse('1979-12-09 13:09')).value_for_context(context).
|
41
|
+
expect(tag('date', DateTime.parse('1979-12-09 13:09')).value_for_context(context)).to eq '1979-12-09T13:09:00+00:00'
|
30
42
|
end
|
31
43
|
|
32
44
|
it 'returns original value otherwise' do
|
33
|
-
tag('og:image:width', 100).value_for_context(context).
|
34
|
-
tag('published', true).value_for_context(context).
|
45
|
+
expect(tag('og:image:width', 100).value_for_context(context)).to eq 100
|
46
|
+
expect(tag('published', true).value_for_context(context)).to be true
|
35
47
|
end
|
36
48
|
end
|
37
49
|
end
|
data/spec/unit/tags_spec.rb
CHANGED
@@ -7,29 +7,29 @@ describe Crystal::Tags do
|
|
7
7
|
|
8
8
|
context '#tags' do
|
9
9
|
it 'folds hashes' do
|
10
|
-
new({
|
10
|
+
expect(new({
|
11
11
|
'og' => {
|
12
12
|
'title' => 'Caesar must die'
|
13
13
|
}
|
14
|
-
}).tags.
|
14
|
+
}).tags).to eq [
|
15
15
|
tag('og:title', 'Caesar must die')
|
16
16
|
]
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'sorts keys in hashes alphabetically' do
|
20
|
-
new({
|
20
|
+
expect(new({
|
21
21
|
'og' => {
|
22
22
|
'type' => 'book',
|
23
23
|
'title' => 'One day of Ivan Denisovich'
|
24
24
|
}
|
25
|
-
}).tags.
|
25
|
+
}).tags).to eq [
|
26
26
|
tag('og:title', 'One day of Ivan Denisovich'),
|
27
27
|
tag('og:type', 'book')
|
28
28
|
]
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'moves url key to the top' do
|
32
|
-
new({
|
32
|
+
expect(new({
|
33
33
|
'og' => {
|
34
34
|
'image' => [
|
35
35
|
{
|
@@ -44,7 +44,7 @@ describe Crystal::Tags do
|
|
44
44
|
},
|
45
45
|
]
|
46
46
|
}
|
47
|
-
}).tags.
|
47
|
+
}).tags).to eq [
|
48
48
|
tag('og:image:url', '1.png'),
|
49
49
|
tag('og:image:height', 300),
|
50
50
|
tag('og:image:width', 200),
|
@@ -55,21 +55,21 @@ describe Crystal::Tags do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'duplicates tags for arrays' do
|
58
|
-
new('og:image' => ['1.png', '2.png']).tags.
|
58
|
+
expect(new('og:image' => ['1.png', '2.png']).tags).to eq [
|
59
59
|
tag('og:image', '1.png'),
|
60
60
|
tag('og:image', '2.png')
|
61
61
|
]
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'interpolates values' do
|
65
|
-
new({
|
65
|
+
expect(new({
|
66
66
|
:og => {
|
67
67
|
:title => 'The Rock (%{year})',
|
68
68
|
:site_name => 'IMDb'
|
69
69
|
},
|
70
70
|
:year => 1996,
|
71
71
|
:head => '%{og:title} - %{og:site_name}'
|
72
|
-
}).tags.
|
72
|
+
}).tags).to eq [
|
73
73
|
tag('head', 'The Rock (1996) - IMDb'),
|
74
74
|
tag('og:site_name', 'IMDb'),
|
75
75
|
tag('og:title', 'The Rock (1996)'),
|
@@ -80,7 +80,7 @@ describe Crystal::Tags do
|
|
80
80
|
|
81
81
|
context '#find_by_name' do
|
82
82
|
it 'returns first tag' do
|
83
|
-
new('og' => {'image' => %w{1.png 2.png}}).find_by_name(:"og:image").value.
|
83
|
+
expect(new('og' => {'image' => %w{1.png 2.png}}).find_by_name(:"og:image").value).to eq '1.png'
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'raises an error if tag was not found' do
|
@@ -101,7 +101,7 @@ describe Crystal::Tags do
|
|
101
101
|
|
102
102
|
context 'without pattern' do
|
103
103
|
it 'returns all tags' do
|
104
|
-
subject.filter.
|
104
|
+
expect(subject.filter).to eq [
|
105
105
|
tag('fb:admins', '322132'),
|
106
106
|
tag('og:image', '1.png'),
|
107
107
|
tag('og:image', '2.png'),
|
@@ -112,7 +112,7 @@ describe Crystal::Tags do
|
|
112
112
|
|
113
113
|
context 'with string' do
|
114
114
|
it 'returns tags with this name' do
|
115
|
-
subject.filter('og:image').
|
115
|
+
expect(subject.filter('og:image')).to eq [
|
116
116
|
tag('og:image', '1.png'),
|
117
117
|
tag('og:image', '2.png')
|
118
118
|
]
|
@@ -121,7 +121,7 @@ describe Crystal::Tags do
|
|
121
121
|
|
122
122
|
context 'with regexp' do
|
123
123
|
it 'returns tags with names matched regexp' do
|
124
|
-
subject.filter(/og/).
|
124
|
+
expect(subject.filter(/og/)).to eq [
|
125
125
|
tag('og:image', '1.png'),
|
126
126
|
tag('og:image', '2.png'),
|
127
127
|
tag('og:title', 'Title')
|
metadata
CHANGED
@@ -1,65 +1,58 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crystalmeta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Max Savchenko
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2018-03-26 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rails
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: 5.1.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
26
|
+
version: 5.1.0
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec-rails
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
33
|
+
version: 3.6.0
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
40
|
+
version: 3.6.0
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: capybara
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- - ~>
|
45
|
+
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: 2.
|
47
|
+
version: 2.15.4
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- - ~>
|
52
|
+
- - "~>"
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version: 2.
|
62
|
-
description: Crystal clean meta tags for Rails applications.
|
54
|
+
version: 2.15.4
|
55
|
+
description: Crystal clean meta tags for Rails applications. Supports I18n. Perfect
|
63
56
|
for OpenGraph.
|
64
57
|
email:
|
65
58
|
- robotector@gmail.com
|
@@ -67,7 +60,7 @@ executables: []
|
|
67
60
|
extensions: []
|
68
61
|
extra_rdoc_files: []
|
69
62
|
files:
|
70
|
-
- .gitignore
|
63
|
+
- ".gitignore"
|
71
64
|
- CHANGELOG.markdown
|
72
65
|
- Gemfile
|
73
66
|
- Rakefile
|
@@ -120,29 +113,28 @@ files:
|
|
120
113
|
- spec/unit/meta_spec.rb
|
121
114
|
- spec/unit/tag_spec.rb
|
122
115
|
- spec/unit/tags_spec.rb
|
123
|
-
homepage:
|
116
|
+
homepage: https://github.com/macovsky/crystalmeta
|
124
117
|
licenses: []
|
118
|
+
metadata: {}
|
125
119
|
post_install_message:
|
126
120
|
rdoc_options: []
|
127
121
|
require_paths:
|
128
122
|
- lib
|
129
123
|
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
-
none: false
|
131
124
|
requirements:
|
132
|
-
- -
|
125
|
+
- - ">="
|
133
126
|
- !ruby/object:Gem::Version
|
134
127
|
version: '0'
|
135
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
-
none: false
|
137
129
|
requirements:
|
138
|
-
- -
|
130
|
+
- - ">="
|
139
131
|
- !ruby/object:Gem::Version
|
140
132
|
version: '0'
|
141
133
|
requirements: []
|
142
134
|
rubyforge_project:
|
143
|
-
rubygems_version:
|
135
|
+
rubygems_version: 2.5.2
|
144
136
|
signing_key:
|
145
|
-
specification_version:
|
137
|
+
specification_version: 4
|
146
138
|
summary: Crystalmeta helps you control meta tags through I18n and/or manually. It
|
147
139
|
plays well with OpenGraph.
|
148
140
|
test_files:
|
@@ -182,4 +174,3 @@ test_files:
|
|
182
174
|
- spec/unit/meta_spec.rb
|
183
175
|
- spec/unit/tag_spec.rb
|
184
176
|
- spec/unit/tags_spec.rb
|
185
|
-
has_rdoc:
|