meta-tags 1.1.1 → 1.2.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.
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  rdoc
2
2
  doc
3
3
  pkg
4
- .yardoc
4
+ .yardoc
5
+ .DS_Store
data/README.rdoc CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  Search Engine Optimization (SEO) plugin for Ruby on Rails applications.
4
4
 
5
+ == Rails 3
6
+
7
+ MetaTags master branch is now fully supports Rails 3 and is backward
8
+ compatible.
9
+
5
10
  == Installation
6
11
 
7
12
  There are two options when approaching meta-tags installation:
@@ -11,7 +16,7 @@ There are two options when approaching meta-tags installation:
11
16
 
12
17
  To install as a gem, add this to your environment.rb:
13
18
 
14
- config.gem 'meta-tags', :lib => 'meta_tags', :source => 'http://gemcutter.org'
19
+ config.gem 'meta-tags', :lib => 'meta_tags'
15
20
 
16
21
  And then run the command:
17
22
 
@@ -146,7 +151,7 @@ Also there is +set_meta_tags+ method exists:
146
151
  :description => 'Member login page.',
147
152
  :keywords => 'Site, Login, Members' %>
148
153
 
149
- The +title+ methods returns title itself, so you can use it to show the title
154
+ The +title+ method returns title itself, so you can use it to show the title
150
155
  somewhere on the page:
151
156
 
152
157
  <h1><%= title 'Member Login' %></h1>
@@ -174,14 +179,14 @@ Use these options to customize the title format:
174
179
 
175
180
  And here are a few examples to give you ideas.
176
181
 
177
- <%= title :separator => "&mdash;" %>
178
- <%= title :prefix => false, :separator => ":" %>
179
- <%= title :lowercase => true %>
180
- <%= title :reverse => true, :prefix => false %>
182
+ <%= display_meta_tags :separator => "&mdash;" %>
183
+ <%= display_meta_tags :prefix => false, :separator => ":" %>
184
+ <%= display_meta_tags :lowercase => true %>
185
+ <%= display_meta_tags :reverse => true, :prefix => false %>
181
186
 
182
187
  === Allowed values
183
188
 
184
- You can specify +title+ as a string or array:
189
+ You can specify <tt>:title</tt> as a string or array:
185
190
 
186
191
  set_meta_tags :title => ['part1', 'part2'], :site => 'site'
187
192
  # site | part1 | part2
@@ -207,3 +212,4 @@ There are several plugins influenced me to create this one:
207
212
  * Dmytro Shteflyuk (author) <kpumuk@kpumuk.info> http://kpumuk.info
208
213
  * Morgan Roderick (contributor) <morgan@roderick.dk> http://roderick.dk
209
214
  * Sergio Cambra (contributor) <sergio@entrecables.com>
215
+ * Kristoffer Renholm (contributor) <kristoffer@renholm.se>
data/Rakefile CHANGED
@@ -39,7 +39,7 @@ begin
39
39
  if ENV['PRIVATE']
40
40
  t.options.concat ['--protected', '--private']
41
41
  else
42
- t.options << '--no-private'
42
+ t.options.concat ['--protected', '--no-private']
43
43
  end
44
44
  end
45
45
  rescue LoadError
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- :patch: 1
2
+ :patch: 0
3
3
  :build:
4
4
  :major: 1
5
- :minor: 1
5
+ :minor: 2
data/init.rb CHANGED
@@ -1 +1 @@
1
- require File.dirname(__FILE__) + '/lib/meta_tags'
1
+ require 'meta_tags'
data/lib/meta_tags.rb CHANGED
@@ -1,8 +1,10 @@
1
+ require 'action_controller'
2
+ require 'action_view'
3
+
1
4
  module MetaTags
5
+ autoload :ViewHelper, 'meta_tags/view_helper'
6
+ autoload :ControllerHelper, 'meta_tags/controller_helper'
2
7
  end
3
8
 
4
- require File.dirname(__FILE__) + '/meta_tags/view_helper'
5
- require File.dirname(__FILE__) + '/meta_tags/controller_helper'
6
-
7
9
  ActionView::Base.send :include, MetaTags::ViewHelper
8
10
  ActionController::Base.send :include, MetaTags::ControllerHelper
@@ -1,43 +1,35 @@
1
- # Contains methods to use in controllers.
2
- #
3
- # You can define several instance variables to set meta tags:
4
- # @page_title = 'Member Login'
5
- # @page_description = 'Member login page.'
6
- # @page_keywords = 'Site, Login, Members'
7
- #
8
- # Also you can use +set_meta_tags+ method, that have the same parameters
9
- # as <tt>MetaTags.set_meta_tags</tt>.
10
1
  module MetaTags
2
+ # Contains methods to use in controllers.
3
+ #
4
+ # You can define several instance variables to set meta tags:
5
+ # @page_title = 'Member Login'
6
+ # @page_description = 'Member login page.'
7
+ # @page_keywords = 'Site, Login, Members'
8
+ #
9
+ # Also you can use {InstanceMethods#set_meta_tags} method, that have the same parameters
10
+ # as {ViewHelper#set_meta_tags}.
11
+ #
11
12
  module ControllerHelper
12
- def self.included(base)
13
- base.send :include, InstanceMethods
14
- base.class_eval do
15
- alias_method_chain :render, :meta_tags
16
- end
17
- end
18
-
19
- module InstanceMethods
20
- protected
13
+ # Processes the <tt>@page_title</tt>, <tt>@page_keywords</tt>, and
14
+ # <tt>@page_description</tt> instance variables and calls +render+.
15
+ def render(*args, &block)
16
+ meta_tags = {}
17
+ meta_tags[:title] = @page_title if @page_title
18
+ meta_tags[:keywords] = @page_keywords if @page_keywords
19
+ meta_tags[:description] = @page_description if @page_description
20
+ set_meta_tags(meta_tags)
21
21
 
22
- # Processes the <tt>@page_title</tt>, <tt>@page_keywords</tt>, and
23
- # <tt>@page_description</tt> instance variables and calls +render+.
24
- def render_with_meta_tags(options = nil, extra_options = {}, &block)
25
- meta_tags = {}
26
- meta_tags[:title] = @page_title if @page_title
27
- meta_tags[:keywords] = @page_keywords if @page_keywords
28
- meta_tags[:description] = @page_description if @page_description
29
- set_meta_tags(meta_tags)
22
+ super(*args, &block)
23
+ end
30
24
 
31
- render_without_meta_tags(options, extra_options, &block)
32
- end
33
-
34
- # Set meta tags for the page.
35
- #
36
- # See <tt>MetaTags.set_meta_tags</tt> for details.
37
- def set_meta_tags(meta_tags)
38
- @meta_tags ||= {}
39
- @meta_tags.merge!(meta_tags || {})
40
- end
25
+ # Set meta tags for the page.
26
+ #
27
+ # See <tt>MetaTags.set_meta_tags</tt> for details.
28
+ def set_meta_tags(meta_tags)
29
+ @meta_tags ||= {}
30
+ @meta_tags.merge!(meta_tags || {})
41
31
  end
32
+
33
+ protected :set_meta_tags
42
34
  end
43
- end
35
+ end
@@ -1,5 +1,6 @@
1
- # Contains methods to use in views and helpers.
2
1
  module MetaTags
2
+ # Contains methods to use in views and helpers.
3
+ #
3
4
  module ViewHelper
4
5
  # Set meta tags for the page.
5
6
  #
@@ -7,57 +8,80 @@ module MetaTags
7
8
  # be merged. If you will set the same property several times, last one
8
9
  # will take precedence.
9
10
  #
10
- # Examples:
11
+ # Usually you will not call this method directly. Use {#title}, {#keywords},
12
+ # {#description} for your daily tasks.
13
+ #
14
+ # @param [Hash] meta_tags list of meta tags. See {#display_meta_tags}
15
+ # for allowed options.
16
+ #
17
+ # @example
11
18
  # set_meta_tags :title => 'Login Page', :description => 'Here you can login'
12
19
  # set_meta_tags :keywords => 'authorization, login'
13
20
  #
14
- # Usually you will not call this method directly. Use +title+, +keywords+,
15
- # +description+ for your daily tasks.
21
+ # @see #display_meta_tags
16
22
  #
17
- # See +display_meta_tags+ for allowed options.
18
23
  def set_meta_tags(meta_tags = {})
19
24
  @meta_tags ||= {}
20
25
  @meta_tags.merge!(meta_tags || {})
21
26
  end
22
-
27
+
23
28
  # Set the page title and return it back.
24
29
  #
25
30
  # This method is best suited for use in helpers. It sets the page title
26
31
  # and returns it (or +headline+ if specified).
27
32
  #
28
- # Examples:
29
- # <%= title 'Login Page' %> => title='Login Page', return='Login Page'
30
- # <%= title 'Login Page', 'Please login' %> => title='Login Page', return='Please Login'
33
+ # @param [String, Array] title page title. When passed as an
34
+ # +Array+, parts will be joined divided with configured
35
+ # separator value (see {#display_meta_tags}).
36
+ # @param [String] headline the value to return from method. Useful
37
+ # for using this method in views to set both page title
38
+ # and the content of heading tag.
39
+ # @return [String] returns +title+ value or +headline+ if passed.
40
+ #
41
+ # @example Set HTML title to "Please login", return "Please login"
42
+ # title 'Login Page'
43
+ # @example Set HTML title to "Login Page", return "Please login"
44
+ # title 'Login Page', 'Please login'
45
+ # @example Set title as array of strings
46
+ # title :title => ['part1', 'part2'] # => "part1 | part2"
47
+ #
48
+ # @see #display_meta_tags
31
49
  #
32
- # You can specify +title+ as a string or array:
33
- # title :title => ['part1', 'part2']
34
- # # part1 | part2
35
50
  def title(title, headline = '')
36
51
  set_meta_tags(:title => title)
37
52
  headline.blank? ? title : headline
38
53
  end
39
-
54
+
40
55
  # Set the page keywords.
41
56
  #
42
- # Keywords can be passed as string of comma-separated values, or as an array:
57
+ # @param [String, Array] keywords meta keywords to render in HEAD
58
+ # section of the HTML document.
59
+ # @return [String, Array] passed value.
60
+ #
61
+ # @example
62
+ # keywords 'keyword1, keyword2'
63
+ # keywords %w(keyword1 keyword2)
43
64
  #
44
- # set_meta_tags :keywords => ['tag1', 'tag2']
45
- # # tag1, tag2
65
+ # @see #display_meta_tags
46
66
  #
47
- # Examples:
48
- # <% keywords 'keyword1, keyword2' %>
49
- # <% keywords %w(keyword1 keyword2) %>
50
67
  def keywords(keywords)
51
68
  set_meta_tags(:keywords => keywords)
52
69
  keywords
53
70
  end
54
-
71
+
55
72
  # Set the page description.
56
73
  #
57
- # Description is a string (HTML will be stripped from output string).
74
+ # @param [String] page description to be set in HEAD section of
75
+ # the HTML document. Please note, any HTML tags will be stripped
76
+ # from output string, and string will be truncated to 200
77
+ # characters.
78
+ # @return [String] passed value.
79
+ #
80
+ # @example
81
+ # description 'This is login page'
82
+ #
83
+ # @see #display_meta_tags
58
84
  #
59
- # Examples:
60
- # <% description 'This is login page' %>
61
85
  def description(description)
62
86
  set_meta_tags(:description => description)
63
87
  description
@@ -65,11 +89,15 @@ module MetaTags
65
89
 
66
90
  # Set the noindex meta tag
67
91
  #
68
- # You can specify noindex as a boolean or string
92
+ # @param [Boolean, String] noindex a noindex value.
93
+ # @return [Boolean, String] passed value.
94
+ #
95
+ # @example
96
+ # noindex true
97
+ # noindex 'googlebot'
98
+ #
99
+ # @see #display_meta_tags
69
100
  #
70
- # Examples:
71
- # <% noindex true %>
72
- # <% noindex 'googlebot' %>
73
101
  def noindex(noindex)
74
102
  set_meta_tags(:noindex => noindex)
75
103
  noindex
@@ -77,123 +105,121 @@ module MetaTags
77
105
 
78
106
  # Set the nofollow meta tag
79
107
  #
80
- # You can specify nofollow as a boolean or string
108
+ # @param [Boolean, String] nofollow a nofollow value.
109
+ # @return [Boolean, String] passed value.
110
+ #
111
+ # @example
112
+ # nofollow true
113
+ # nofollow 'googlebot'
114
+ #
115
+ # @see #display_meta_tags
81
116
  #
82
- # Examples:
83
- # <% nofollow true %>
84
- # <% nofollow 'googlebot' %>
85
117
  def nofollow(nofollow)
86
118
  set_meta_tags(:nofollow => nofollow)
87
119
  nofollow
88
120
  end
89
-
90
- # Set default meta tag values and display meta tags.
91
- #
92
- # This method should be used in layout file.
93
- #
94
- # Examples:
121
+
122
+ # Set default meta tag values and display meta tags. This method
123
+ # should be used in layout file.
124
+ #
125
+ # @param [Hash] default default meta tag values.
126
+ # @option default [String] :site (nil) site title;
127
+ # @option default [String] :title ("") page title;
128
+ # @option default [String] :description (nil) page description;
129
+ # @option default [String] :keywords (nil) page keywords;
130
+ # @option default [String, Boolean] :prefix (" ") text between site name and separator; when +false+, no prefix will be rendered;
131
+ # @option default [String] :separator ("|") text used to separate website name from page title;
132
+ # @option default [String, Boolean] :suffix (" ") text between separator and page title; when +false+, no suffix will be rendered;
133
+ # @option default [Boolean] :lowercase (false) when true, the page name will be lowercase;
134
+ # @option default [Boolean] :reverse (false) when true, the page and site names will be reversed;
135
+ # @option default [Boolean, String] :noindex (false) add noindex meta tag; when true, 'robots' will be used, otherwise the string will be used;
136
+ # @option default [Boolean, String] :nofollow (false) add nofollow meta tag; when true, 'robots' will be used, otherwise the string will be used;
137
+ # @option default [String] :canonical (nil) add canonical link tag.
138
+ # @return [String] HTML meta tags to render in HEAD section of the
139
+ # HTML document.
140
+ #
141
+ # @example
95
142
  # <head>
96
143
  # <%= display_meta_tags :site => 'My website' %>
97
144
  # </head>
98
145
  #
99
- # Allowed options:
100
- # * <tt>:site</tt> -- site title;
101
- # * <tt>:title</tt> -- page title;
102
- # * <tt>:description</tt> -- page description;
103
- # * <tt>:keywords</tt> -- page keywords;
104
- # * <tt>:prefix</tt> -- text between site name and separator;
105
- # * <tt>:separator</tt> -- text used to separate website name from page title;
106
- # * <tt>:suffix</tt> -- text between separator and page title;
107
- # * <tt>:lowercase</tt> -- when true, the page name will be lowercase;
108
- # * <tt>:reverse</tt> -- when true, the page and site names will be reversed;
109
- # * <tt>:noindex</tt> -- add noindex meta tag; when true, 'robots' will be used, otherwise the string will be used;
110
- # * <tt>:nofollow</tt> -- add nofollow meta tag; when true, 'robots' will be used, otherwise the string will be used;
111
- # * <tt>:canonical</tt> -- add canonical link tag.
112
146
  def display_meta_tags(default = {})
113
147
  meta_tags = (default || {}).merge(@meta_tags || {})
114
148
 
115
149
  # Prefix (leading space)
116
- if meta_tags[:prefix]
117
- prefix = meta_tags[:prefix]
118
- elsif meta_tags[:prefix] === false
119
- prefix = ''
120
- else
121
- prefix = ' '
122
- end
123
-
150
+ prefix = meta_tags[:prefix] === false ? '' : (meta_tags[:prefix] || ' ')
151
+
124
152
  # Separator
125
- unless meta_tags[:separator].blank?
126
- separator = meta_tags[:separator]
127
- else
128
- separator = '|'
129
- end
130
-
153
+ separator = meta_tags[:separator].blank? ? '|' : meta_tags[:separator]
154
+
131
155
  # Suffix (trailing space)
132
- if meta_tags[:suffix]
133
- suffix = meta_tags[:suffix]
134
- elsif meta_tags[:suffix] === false
135
- suffix = ''
136
- else
137
- suffix = ' '
138
- end
139
-
156
+ suffix = meta_tags[:suffix] === false ? '' : (meta_tags[:suffix] || ' ')
157
+
140
158
  # Title
141
159
  title = meta_tags[:title]
142
- if meta_tags[:lowercase] === true
143
- title = title.downcase unless title.blank?
160
+ if meta_tags[:lowercase] === true and !title.blank?
161
+ title = if title.is_a?(Array)
162
+ title.map { |t| t.downcase }
163
+ else
164
+ title.downcase
165
+ end
144
166
  end
145
-
167
+
168
+ result = []
169
+
146
170
  # title
147
171
  if title.blank?
148
- result = content_tag :title, meta_tags[:site]
172
+ result << content_tag(:title, meta_tags[:site])
149
173
  else
150
174
  title = normalize_title(title)
151
175
  title = [meta_tags[:site]] + title
152
176
  title.reverse! if meta_tags[:reverse] === true
153
177
  sep = prefix + separator + suffix
154
- result = content_tag(:title, title.join(sep))
178
+ result << content_tag(:title, title.join(sep))
155
179
  end
156
180
 
157
181
  # description
158
182
  description = normalize_description(meta_tags[:description])
159
- result << "\n" + tag(:meta, :name => :description, :content => description) unless description.blank?
160
-
183
+ result << tag(:meta, :name => :description, :content => description) unless description.blank?
184
+
161
185
  # keywords
162
186
  keywords = normalize_keywords(meta_tags[:keywords])
163
- result << "\n" + tag(:meta, :name => :keywords, :content => keywords) unless keywords.blank?
187
+ result << tag(:meta, :name => :keywords, :content => keywords) unless keywords.blank?
164
188
 
165
189
  # noindex & nofollow
166
190
  noindex_name = meta_tags[:noindex].is_a?(String) ? meta_tags[:noindex] : 'robots'
167
191
  nofollow_name = meta_tags[:nofollow].is_a?(String) ? meta_tags[:nofollow] : 'robots'
168
-
192
+
169
193
  if noindex_name == nofollow_name
170
194
  content = [(meta_tags[:noindex] ? 'noindex' : nil), (meta_tags[:nofollow] ? 'nofollow' : nil)].compact.join(', ')
171
- result << "\n" + tag(:meta, :name => noindex_name, :content => content) unless content.blank?
195
+ result << tag(:meta, :name => noindex_name, :content => content) unless content.blank?
172
196
  else
173
- result << "\n" + tag(:meta, :name => noindex_name, :content => 'noindex') if meta_tags[:noindex]
174
- result << "\n" + tag(:meta, :name => nofollow_name, :content => 'nofollow') if meta_tags[:nofollow]
197
+ result << tag(:meta, :name => noindex_name, :content => 'noindex') if meta_tags[:noindex]
198
+ result << tag(:meta, :name => nofollow_name, :content => 'nofollow') if meta_tags[:nofollow]
175
199
  end
176
200
 
177
201
  # canonical
178
- result << "\n" + tag(:link, :rel => :canonical, :href => meta_tags[:canonical]) unless meta_tags[:canonical].blank?
202
+ result << tag(:link, :rel => :canonical, :href => meta_tags[:canonical]) unless meta_tags[:canonical].blank?
179
203
 
180
- return result
204
+ result = result.join("\n")
205
+ result.html_safe! if result.respond_to?(:html_safe!)
206
+ result
181
207
  end
182
-
208
+
183
209
  private
184
-
210
+
185
211
  def normalize_title(title)
186
212
  if title.is_a? String
187
213
  title = [title]
188
214
  end
189
215
  title.map { |t| h(strip_tags(t)) }
190
216
  end
191
-
217
+
192
218
  def normalize_description(description)
193
219
  return '' unless description
194
220
  truncate(strip_tags(description).gsub(/\s+/, ' '), :length => 200)
195
221
  end
196
-
222
+
197
223
  def normalize_keywords(keywords)
198
224
  return '' unless keywords
199
225
  keywords = keywords.flatten.join(', ') if keywords.is_a?(Array)
data/meta-tags.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{meta-tags}
8
- s.version = "1.1.1"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dmytro Shteflyuk"]
12
- s.date = %q{2009-11-21}
12
+ s.date = %q{2010-05-31}
13
13
  s.description = %q{Search Engine Optimization (SEO) plugin for Ruby on Rails applications.}
14
14
  s.email = %q{kpumuk@kpumuk.info}
15
15
  s.extra_rdoc_files = [
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
32
32
  s.homepage = %q{http://github.com/kpumuk/meta-tags}
33
33
  s.rdoc_options = ["--charset=UTF-8"]
34
34
  s.require_paths = ["lib"]
35
- s.rubygems_version = %q{1.3.5}
35
+ s.rubygems_version = %q{1.3.7}
36
36
  s.summary = %q{Collection of SEO helpers for Ruby on Rails}
37
37
  s.test_files = [
38
38
  "spec/meta_tags_spec.rb",
@@ -43,7 +43,7 @@ Gem::Specification.new do |s|
43
43
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
44
  s.specification_version = 3
45
45
 
46
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
47
  else
48
48
  end
49
49
  else
@@ -135,6 +135,10 @@ describe MetaTags::ViewHelper do
135
135
  @view.display_meta_tags(:site => 'someSite', :title => ['someTitle', 'anotherTitle']).should == '<title>someSite | someTitle | anotherTitle</title>'
136
136
  end
137
137
 
138
+ it 'shold allow Arrays in title with :lowercase' do
139
+ @view.display_meta_tags(:site => 'someSite', :title => ['someTitle', 'anotherTitle'], :lowercase => true).should == '<title>someSite | sometitle | anothertitle</title>'
140
+ end
141
+
138
142
  it 'shold build title in reverse order if :reverse' do
139
143
  @view.display_meta_tags(:site => 'someSite',
140
144
  :title => ['someTitle', 'anotherTitle'],
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meta-tags
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 2
9
+ - 0
10
+ version: 1.2.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Dmytro Shteflyuk
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-11-21 00:00:00 +02:00
18
+ date: 2010-05-31 00:00:00 +03:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -44,21 +50,27 @@ rdoc_options:
44
50
  require_paths:
45
51
  - lib
46
52
  required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
47
54
  requirements:
48
55
  - - ">="
49
56
  - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
50
60
  version: "0"
51
- version:
52
61
  required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
53
63
  requirements:
54
64
  - - ">="
55
65
  - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
56
69
  version: "0"
57
- version:
58
70
  requirements: []
59
71
 
60
72
  rubyforge_project:
61
- rubygems_version: 1.3.5
73
+ rubygems_version: 1.3.7
62
74
  signing_key:
63
75
  specification_version: 3
64
76
  summary: Collection of SEO helpers for Ruby on Rails