meta-tags 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,8 @@
1
1
  rvm:
2
- - 1.8.7
3
- - 1.9.2
4
2
  - ree
3
+ - 1.8.7
4
+ - 1.9.3
5
+ - 2.0.0
5
6
 
6
7
  notifications:
7
8
  recipients:
@@ -1,3 +1,9 @@
1
+ ## 1.4.0 (March 14, 2013)
2
+
3
+ Features:
4
+
5
+ - Added support of custom meta tags
6
+
1
7
  ## 1.3.0 (February 13, 2013)
2
8
 
3
9
  Features:
data/README.md CHANGED
@@ -175,6 +175,22 @@ Further reading:
175
175
 
176
176
  * [Twitter Cards Documentation](https://dev.twitter.com/docs/cards/)
177
177
 
178
+ ### Custom meta tags
179
+
180
+ Starting from version 1.3.1, you can specify arbitrary meta tags, and they will
181
+ be rendered on the page, even if meta-tags gem does not know about them.
182
+
183
+ Example:
184
+
185
+ set_meta_tags :author => "Dmytro Shteflyuk"
186
+ # <meta name="author" content="Dmytro Shteflyuk"/>
187
+
188
+ You can also specify value as an Array, and values will be displayed as a list
189
+ of `meta` tags:
190
+
191
+ set_meta_tags :author => [ "Dmytro Shteflyuk", "John Doe" ]
192
+ # <meta name="author" content="Dmytro Shteflyuk"/>
193
+ # <meta name="author" content="John Doe"/>
178
194
 
179
195
  ## MetaTags Usage
180
196
 
@@ -332,3 +348,5 @@ There are several plugins influenced me to create this one:
332
348
  * [Jürg Lehni](https://github.com/lehni) (contributor)
333
349
  * [Tom Coleman](https://github.com/tmeasday) (contributor)
334
350
  * [Guille Lopez](https://github.com/guillelopez) (contributor)
351
+ * [Holger Frohloff](https://github.com/jazzgumpy) (contributor)
352
+ * [Jakub Wojtysiak](https://github.com/schiza) (contributor)
@@ -1,3 +1,3 @@
1
1
  module MetaTags
2
- VERSION = '1.3.0'
2
+ VERSION = '1.4.0'
3
3
  end
@@ -161,11 +161,11 @@ module MetaTags
161
161
  result << content_tag(:title, title) unless title.blank?
162
162
 
163
163
  # description
164
- description = normalize_description(meta_tags[:description])
164
+ description = normalize_description(meta_tags.delete(:description))
165
165
  result << tag(:meta, :name => :description, :content => description) unless description.blank?
166
166
 
167
167
  # keywords
168
- keywords = normalize_keywords(meta_tags[:keywords])
168
+ keywords = normalize_keywords(meta_tags.delete(:keywords))
169
169
  result << tag(:meta, :name => :keywords, :content => keywords) unless keywords.blank?
170
170
 
171
171
  # noindex & nofollow
@@ -179,34 +179,31 @@ module MetaTags
179
179
  result << tag(:meta, :name => noindex_name, :content => 'noindex') if meta_tags[:noindex] && meta_tags[:noindex] != false
180
180
  result << tag(:meta, :name => nofollow_name, :content => 'nofollow') if meta_tags[:nofollow] && meta_tags[:nofollow] != false
181
181
  end
182
+ meta_tags.delete(:noindex)
183
+ meta_tags.delete(:nofollow)
182
184
 
183
185
  # hashes
184
- meta_tags.each do |property, content|
185
- if content.is_a?(Hash)
186
- result.concat process_tree(property, content)
186
+ meta_tags.each do |property, data|
187
+ if data.is_a?(Hash)
188
+ result.concat process_tree(property, data)
189
+ meta_tags.delete(property)
187
190
  end
188
191
  end
189
192
 
190
193
  # canonical
191
194
  result << tag(:link, :rel => :canonical, :href => meta_tags[:canonical]) unless meta_tags[:canonical].blank?
195
+ meta_tags.delete(:canonical)
192
196
 
193
- result = result.join("\n")
194
- result.respond_to?(:html_safe) ? result.html_safe : result
195
- end
196
-
197
- # Recursive function to process all the hashes and arrays on meta tags
198
- def process_tree(property, content)
199
- result = []
200
- if content.is_a?(Hash)
201
- content.each do |key, value|
202
- result.concat process_tree("#{property}:#{key}", value)
203
- end
204
- else
205
- Array(content).each do |c|
206
- result << tag(:meta, :property => "#{property}", :content => c) unless c.blank?
197
+ # user defined
198
+ meta_tags.each do |name, data|
199
+ Array(data).each do |val|
200
+ result << tag(:meta, :name => name, :content => val)
207
201
  end
202
+ meta_tags.delete(name)
208
203
  end
209
- result
204
+
205
+ result = result.join("\n")
206
+ result.respond_to?(:html_safe) ? result.html_safe : result
210
207
  end
211
208
 
212
209
  # Returns full page title as a string without surrounding <title> tag.
@@ -239,6 +236,21 @@ module MetaTags
239
236
 
240
237
  private
241
238
 
239
+ # Recursive function to process all the hashes and arrays on meta tags
240
+ def process_tree(property, content)
241
+ result = []
242
+ if content.is_a?(Hash)
243
+ content.each do |key, value|
244
+ result.concat process_tree("#{property}:#{key}", value)
245
+ end
246
+ else
247
+ Array(content).each do |c|
248
+ result << tag(:meta, :property => "#{property}", :content => c) unless c.blank?
249
+ end
250
+ end
251
+ result
252
+ end
253
+
242
254
  def normalize_title(title)
243
255
  Array(title).map { |t| h(strip_tags(t)) }
244
256
  end
@@ -263,35 +275,40 @@ module MetaTags
263
275
  def build_full_title(meta_tags)
264
276
  # Prefix (leading space)
265
277
  prefix = meta_tags[:prefix] === false ? '' : (meta_tags[:prefix] || ' ')
278
+ meta_tags.delete(:prefix)
266
279
 
267
280
  # Separator
268
281
  separator = meta_tags[:separator] === false ? '' : (meta_tags[:separator] || '|')
269
282
 
270
283
  # Suffix (trailing space)
271
284
  suffix = meta_tags[:suffix] === false ? '' : (meta_tags[:suffix] || ' ')
285
+ meta_tags.delete(:suffix)
272
286
 
273
287
  # Special case: if separator is hidden, do not display suffix/prefix
274
288
  if meta_tags[:separator] == false
275
289
  prefix = suffix = ''
276
290
  end
291
+ meta_tags.delete(:separator)
277
292
 
278
293
  # Title
279
- title = meta_tags[:title]
280
- if meta_tags[:lowercase] === true and !title.blank?
294
+ title = meta_tags.delete(:title)
295
+ if meta_tags.delete(:lowercase) === true and !title.blank?
281
296
  title = Array(title).map { |t| t.downcase }
282
297
  end
283
298
 
284
299
  # title
285
300
  if title.blank?
286
- meta_tags[:site]
301
+ meta_tags.delete(:reverse)
302
+ meta_tags.delete(:site)
287
303
  else
288
304
  title = normalize_title(title)
289
305
  title.unshift(h(meta_tags[:site])) unless meta_tags[:site].blank?
290
- title.reverse! if meta_tags[:reverse] === true
306
+ title.reverse! if meta_tags.delete(:reverse) === true
291
307
  sep = h(prefix) + h(separator) + h(suffix)
292
308
  title = title.join(sep)
293
309
  # We escaped every chunk of the title, so the whole title should be HTML safe
294
310
  title = title.html_safe if title.respond_to?(:html_safe)
311
+ meta_tags.delete(:site)
295
312
  title
296
313
  end
297
314
  end
@@ -34,7 +34,7 @@ describe MetaTags::ControllerHelper do
34
34
  it 'should set meta tags from instance variables' do
35
35
  subject.index
36
36
  subject.rendered.should be_true
37
- subject.meta_tags.should == { 'title' => 'title', 'keywords' => 'key1, key2, key3', 'description' => 'description' }
37
+ subject.meta_tags.should eq('title' => 'title', 'keywords' => 'key1, key2, key3', 'description' => 'description')
38
38
  end
39
39
  end
40
40
 
@@ -43,102 +43,102 @@ describe MetaTags::ViewHelper do
43
43
 
44
44
  context 'returning values' do
45
45
  it 'should return title' do
46
- subject.title('some-title').should == 'some-title'
46
+ subject.title('some-title').should eq('some-title')
47
47
  end
48
48
 
49
49
  it 'should return headline if specified' do
50
- subject.title('some-title', 'some-headline').should == 'some-headline'
50
+ subject.title('some-title', 'some-headline').should eq('some-headline')
51
51
  end
52
52
 
53
53
  it 'should return title' do
54
- subject.title('some-title').should == 'some-title'
55
- subject.title.should == 'some-title'
54
+ subject.title('some-title').should eq('some-title')
55
+ subject.title.should eq('some-title')
56
56
  end
57
57
 
58
58
  it 'should return description' do
59
- subject.description('some-description').should == 'some-description'
59
+ subject.description('some-description').should eq('some-description')
60
60
  end
61
61
 
62
62
  it 'should return keywords' do
63
- subject.keywords('some-keywords').should == 'some-keywords'
63
+ subject.keywords('some-keywords').should eq('some-keywords')
64
64
  end
65
65
 
66
66
  it 'should return noindex' do
67
- subject.noindex('some-noindex').should == 'some-noindex'
67
+ subject.noindex('some-noindex').should eq('some-noindex')
68
68
  end
69
69
 
70
70
  it 'should return nofollow' do
71
- subject.noindex('some-nofollow').should == 'some-nofollow'
71
+ subject.noindex('some-nofollow').should eq('some-nofollow')
72
72
  end
73
73
  end
74
74
 
75
75
  context 'displaying title' do
76
76
  it 'should not display title if blank' do
77
- subject.display_meta_tags.should == ''
77
+ subject.display_meta_tags.should eq('')
78
78
  subject.title('')
79
- subject.display_meta_tags.should == ''
79
+ subject.display_meta_tags.should eq('')
80
80
  end
81
81
 
82
82
  it 'should use website name if title is empty' do
83
- subject.display_meta_tags(:site => 'someSite').should == '<title>someSite</title>'
83
+ subject.display_meta_tags(:site => 'someSite').should eq('<title>someSite</title>')
84
84
  end
85
85
 
86
86
  it 'should display title when "title" used' do
87
87
  subject.title('someTitle')
88
- subject.display_meta_tags(:site => 'someSite').should == '<title>someSite | someTitle</title>'
88
+ subject.display_meta_tags(:site => 'someSite').should eq('<title>someSite | someTitle</title>')
89
89
  end
90
90
 
91
91
  it 'should display title only when "site" is empty' do
92
92
  subject.title('someTitle')
93
- subject.display_meta_tags.should == '<title>someTitle</title>'
93
+ subject.display_meta_tags.should eq('<title>someTitle</title>')
94
94
  end
95
95
 
96
96
  it 'should display title when "set_meta_tags" used' do
97
97
  subject.set_meta_tags(:title => 'someTitle')
98
- subject.display_meta_tags(:site => 'someSite').should == '<title>someSite | someTitle</title>'
98
+ subject.display_meta_tags(:site => 'someSite').should eq('<title>someSite | someTitle</title>')
99
99
  end
100
100
 
101
101
  it 'should display custom title if given' do
102
102
  subject.title('someTitle')
103
- subject.display_meta_tags(:site => 'someSite', :title => 'defaultTitle').should == '<title>someSite | someTitle</title>'
103
+ subject.display_meta_tags(:site => 'someSite', :title => 'defaultTitle').should eq('<title>someSite | someTitle</title>')
104
104
  end
105
105
 
106
106
  it 'should use website before page by default' do
107
- subject.display_meta_tags(:site => 'someSite', :title => 'someTitle').should == '<title>someSite | someTitle</title>'
107
+ subject.display_meta_tags(:site => 'someSite', :title => 'someTitle').should eq('<title>someSite | someTitle</title>')
108
108
  end
109
109
 
110
110
  it 'should only use markup in titles in the view' do
111
- subject.title('<b>someTitle</b>').should == '<b>someTitle</b>'
112
- subject.display_meta_tags(:site => 'someSite').should == '<title>someSite | someTitle</title>'
111
+ subject.title('<b>someTitle</b>').should eq('<b>someTitle</b>')
112
+ subject.display_meta_tags(:site => 'someSite').should eq('<title>someSite | someTitle</title>')
113
113
  end
114
114
 
115
115
  it 'should use page before website if :reverse' do
116
- subject.display_meta_tags(:site => 'someSite', :title => 'someTitle', :reverse => true).should == '<title>someTitle | someSite</title>'
116
+ subject.display_meta_tags(:site => 'someSite', :title => 'someTitle', :reverse => true).should eq('<title>someTitle | someSite</title>')
117
117
  end
118
118
 
119
119
  it 'should be lowercase if :lowercase' do
120
- subject.display_meta_tags(:site => 'someSite', :title => 'someTitle', :lowercase => true).should == '<title>someSite | sometitle</title>'
120
+ subject.display_meta_tags(:site => 'someSite', :title => 'someTitle', :lowercase => true).should eq('<title>someSite | sometitle</title>')
121
121
  end
122
122
 
123
123
  it 'should use custom separator if :separator' do
124
124
  subject.title('someTitle')
125
- subject.display_meta_tags(:site => 'someSite', :separator => '-').should == '<title>someSite - someTitle</title>'
126
- subject.display_meta_tags(:site => 'someSite', :separator => ':').should == '<title>someSite : someTitle</title>'
127
- subject.display_meta_tags(:site => 'someSite', :separator => '&mdash;').should == '<title>someSite &amp;mdash; someTitle</title>'
128
- subject.display_meta_tags(:site => 'someSite', :separator => '&mdash;'.html_safe).should == '<title>someSite &mdash; someTitle</title>'
129
- subject.display_meta_tags(:site => 'someSite: ', :separator => false).should == '<title>someSite: someTitle</title>'
125
+ subject.display_meta_tags(:site => 'someSite', :separator => '-').should eq('<title>someSite - someTitle</title>')
126
+ subject.display_meta_tags(:site => 'someSite', :separator => ':').should eq('<title>someSite : someTitle</title>')
127
+ subject.display_meta_tags(:site => 'someSite', :separator => '&mdash;').should eq('<title>someSite &amp;mdash; someTitle</title>')
128
+ subject.display_meta_tags(:site => 'someSite', :separator => '&mdash;'.html_safe).should eq('<title>someSite &mdash; someTitle</title>')
129
+ subject.display_meta_tags(:site => 'someSite: ', :separator => false).should eq('<title>someSite: someTitle</title>')
130
130
  end
131
131
 
132
132
  it 'should use custom prefix and suffix if available' do
133
- subject.display_meta_tags(:site => 'someSite', :title => 'someTitle', :prefix => ' -', :suffix => '- ').should == '<title>someSite -|- someTitle</title>'
133
+ subject.display_meta_tags(:site => 'someSite', :title => 'someTitle', :prefix => ' -', :suffix => '- ').should eq('<title>someSite -|- someTitle</title>')
134
134
  end
135
135
 
136
136
  it 'should collapse prefix if false' do
137
- subject.display_meta_tags(:site => 'someSite', :title => 'someTitle', :prefix => false).should == '<title>someSite| someTitle</title>'
137
+ subject.display_meta_tags(:site => 'someSite', :title => 'someTitle', :prefix => false).should eq('<title>someSite| someTitle</title>')
138
138
  end
139
139
 
140
140
  it 'should collapse suffix if false' do
141
- subject.display_meta_tags(:site => 'someSite', :title => 'someTitle', :suffix => false).should == '<title>someSite |someTitle</title>'
141
+ subject.display_meta_tags(:site => 'someSite', :title => 'someTitle', :suffix => false).should eq('<title>someSite |someTitle</title>')
142
142
  end
143
143
 
144
144
  it 'should use all custom options if available' do
@@ -148,15 +148,15 @@ describe MetaTags::ViewHelper do
148
148
  :suffix => '+ ',
149
149
  :separator => ':',
150
150
  :lowercase => true,
151
- :reverse => true).should == '<title>sometitle -:+ someSite</title>'
151
+ :reverse => true).should eq('<title>sometitle -:+ someSite</title>')
152
152
  end
153
153
 
154
154
  it 'shold allow Arrays in title' do
155
- subject.display_meta_tags(:site => 'someSite', :title => ['someTitle', 'anotherTitle']).should == '<title>someSite | someTitle | anotherTitle</title>'
155
+ subject.display_meta_tags(:site => 'someSite', :title => ['someTitle', 'anotherTitle']).should eq('<title>someSite | someTitle | anotherTitle</title>')
156
156
  end
157
157
 
158
158
  it 'shold allow Arrays in title with :lowercase' do
159
- subject.display_meta_tags(:site => 'someSite', :title => ['someTitle', 'anotherTitle'], :lowercase => true).should == '<title>someSite | sometitle | anothertitle</title>'
159
+ subject.display_meta_tags(:site => 'someSite', :title => ['someTitle', 'anotherTitle'], :lowercase => true).should eq('<title>someSite | sometitle | anothertitle</title>')
160
160
  end
161
161
 
162
162
  it 'shold build title in reverse order if :reverse' do
@@ -165,14 +165,14 @@ describe MetaTags::ViewHelper do
165
165
  :prefix => ' -',
166
166
  :suffix => '+ ',
167
167
  :separator => ':',
168
- :reverse => true).should == '<title>anotherTitle -:+ someTitle -:+ someSite</title>'
168
+ :reverse => true).should eq('<title>anotherTitle -:+ someTitle -:+ someSite</title>')
169
169
  end
170
170
  end
171
171
 
172
172
  context 'displaying description' do
173
173
  it 'should not display description if blank' do
174
174
  subject.description('')
175
- subject.display_meta_tags.should == ''
175
+ subject.display_meta_tags.should eq('')
176
176
  end
177
177
 
178
178
  it 'should display description when "description" used' do
@@ -210,10 +210,10 @@ describe MetaTags::ViewHelper do
210
210
  context 'displaying keywords' do
211
211
  it 'should not display keywords if blank' do
212
212
  subject.keywords('')
213
- subject.display_meta_tags.should == ''
213
+ subject.display_meta_tags.should eq('')
214
214
 
215
215
  subject.keywords([])
216
- subject.display_meta_tags.should == ''
216
+ subject.display_meta_tags.should eq('')
217
217
  end
218
218
 
219
219
  it 'should display keywords when "keywords" used' do
@@ -398,7 +398,7 @@ describe MetaTags::ViewHelper do
398
398
 
399
399
  context 'while handling string meta tag names' do
400
400
  it 'should work with common parameters' do
401
- subject.display_meta_tags('site' => 'someSite', 'title' => 'someTitle').should == '<title>someSite | someTitle</title>'
401
+ subject.display_meta_tags('site' => 'someSite', 'title' => 'someTitle').should eq('<title>someSite | someTitle</title>')
402
402
  end
403
403
 
404
404
  it 'should work with open graph parameters' do
@@ -416,7 +416,21 @@ describe MetaTags::ViewHelper do
416
416
  context '.display_title' do
417
417
  it 'should display custom title if given' do
418
418
  subject.title('someTitle')
419
- subject.display_title(:site => 'someSite', :title => 'defaultTitle').should == 'someSite | someTitle'
419
+ subject.display_title(:site => 'someSite', :title => 'defaultTitle').should eq('someSite | someTitle')
420
+ end
421
+ end
422
+
423
+ context 'display any named meta tag that you want to' do
424
+ it 'should display testing meta tag' do
425
+ subject.display_meta_tags(:testing => 'this is a test').should eq('<meta content="this is a test" name="testing" />')
426
+ end
427
+
428
+ it 'should support Array values' do
429
+ subject.display_meta_tags(:testing => ['test1', 'test2']).should eq("<meta content=\"test1\" name=\"testing\" />\n<meta content=\"test2\" name=\"testing\" />")
430
+ end
431
+
432
+ it 'should not render when value is nil' do
433
+ subject.display_meta_tags(:testing => nil).should eq('')
420
434
  end
421
435
  end
422
436
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meta-tags
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 1.3.0
10
+ version: 1.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dmytro Shteflyuk
@@ -15,13 +15,13 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-02-13 00:00:00 -05:00
18
+ date: 2013-03-14 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: actionpack
22
+ type: :runtime
23
23
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
27
  - - ">="
@@ -30,12 +30,12 @@ dependencies:
30
30
  segments:
31
31
  - 0
32
32
  version: "0"
33
- type: :runtime
34
- version_requirements: *id001
33
+ name: actionpack
34
+ requirement: *id001
35
35
  - !ruby/object:Gem::Dependency
36
- name: rake
36
+ type: :development
37
37
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ">="
@@ -44,12 +44,12 @@ dependencies:
44
44
  segments:
45
45
  - 0
46
46
  version: "0"
47
- type: :development
48
- version_requirements: *id002
47
+ name: rake
48
+ requirement: *id002
49
49
  - !ruby/object:Gem::Dependency
50
- name: rspec
50
+ type: :development
51
51
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
55
55
  - - ">="
@@ -58,12 +58,12 @@ dependencies:
58
58
  segments:
59
59
  - 0
60
60
  version: "0"
61
- type: :development
62
- version_requirements: *id003
61
+ name: rspec
62
+ requirement: *id003
63
63
  - !ruby/object:Gem::Dependency
64
- name: yard
64
+ type: :development
65
65
  prerelease: false
66
- requirement: &id004 !ruby/object:Gem::Requirement
66
+ version_requirements: &id004 !ruby/object:Gem::Requirement
67
67
  none: false
68
68
  requirements:
69
69
  - - ">="
@@ -72,12 +72,12 @@ dependencies:
72
72
  segments:
73
73
  - 0
74
74
  version: "0"
75
- type: :development
76
- version_requirements: *id004
75
+ name: yard
76
+ requirement: *id004
77
77
  - !ruby/object:Gem::Dependency
78
- name: bluecloth
78
+ type: :development
79
79
  prerelease: false
80
- requirement: &id005 !ruby/object:Gem::Requirement
80
+ version_requirements: &id005 !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
83
  - - ">="
@@ -86,8 +86,8 @@ dependencies:
86
86
  segments:
87
87
  - 0
88
88
  version: "0"
89
- type: :development
90
- version_requirements: *id005
89
+ name: bluecloth
90
+ requirement: *id005
91
91
  description: Search Engine Optimization (SEO) plugin for Ruby on Rails applications.
92
92
  email:
93
93
  - kpumuk@kpumuk.info