meta-tags 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ rdoc
2
+ doc
3
+ pkg
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Dmytro Shteflyuk
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,195 @@
1
+ = MetaTags
2
+
3
+ Search Engine Optimization (SEO) plugin for Ruby on Rails applications.
4
+
5
+ == Installation
6
+
7
+ There are two options when approaching meta-tags installation:
8
+
9
+ * using the gem (recommended)
10
+ * install as a Rails plugin
11
+
12
+ To install as a gem, add this to your environment.rb:
13
+
14
+ config.gem 'meta-tags', :lib => 'meta_tags', :source => 'http://gemcutter.org'
15
+
16
+ And then run the command:
17
+
18
+ sudo rake gems:install
19
+
20
+ To install meta-tags as a Rails plugin use this:
21
+
22
+ script/plugin install git://github.com/kpumuk/meta-tags.git
23
+
24
+ == Titles
25
+
26
+ Page titles are very important for Search engines. The titles in the
27
+ browser are displayed in the title bar. The search engines would look at
28
+ the this title bar to determine what the page is all about.
29
+
30
+ <title>Some Page Title</title>
31
+ <title>Page Title | Site Title</title>
32
+
33
+ Recommended title tag length: up to <b>70 characters</b>, <b>10 words</b>.
34
+
35
+ == Description
36
+
37
+ Description tags are called meta tags as they are not displayed by the
38
+ browsers as that of titles. But these descriptions may be displayed by
39
+ some search engines. They are used to describe the contents of a page in
40
+ 2 or 3 sentences.
41
+
42
+ <meta name="description" content="All text about keywords, other keywords" />
43
+
44
+ Recommended description tag length: up to <b>160 characters</b>.
45
+
46
+ == Keywords
47
+
48
+ Meta keywords tag are used to place your keywords that you think a
49
+ surfer would search in Search engines. Repeating keywords unnecessarily
50
+ would be considered spam and you may get permanently banned from SERP's
51
+
52
+ <meta name="keywords" content="keyword1, keyword2, keyword3" />
53
+
54
+ Recommended keywords tag length: up to <b>255 characters</b>, <b>20 words</b>.
55
+
56
+ == Noindex
57
+
58
+ By using the noindex meta tag, you can signal to search engines to not
59
+ include specific pages in their indexes.
60
+
61
+ <meta name="robots" content="noindex">
62
+ <meta name="googlebot" content="noindex">
63
+
64
+ This is useful for pages like login, password reset, privacy policy, etc.
65
+
66
+ Further reading:
67
+ * Blocking Google http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=93708
68
+ * Using meta tags to block access to your site http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=93710
69
+
70
+ == Nofollow
71
+
72
+ Nofollow meta tag tells a search engine not to follow the links on a specific
73
+ page. It's entirely likely that a robot might find the same links on some
74
+ other page without a nofollow (perhaps on some other site), and so
75
+ still arrives at your undesired page.
76
+
77
+ <meta name="robots" content="nofollow">
78
+ <meta name="googlebot" content="nofollow">
79
+
80
+ Further reading:
81
+ * About rel="nofollow" http://www.google.com/support/webmasters/bin/answer.py?answer=96569
82
+ * Meta tags http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=79812
83
+
84
+ == MetaTags Usage
85
+
86
+ First, add this code to your main layout:
87
+
88
+ <head>
89
+ <%= display_meta_tags :site => 'My website' %>
90
+ </head>
91
+
92
+ Then, to set the page title, add this to each of your views (see below for other options):
93
+
94
+ <h1><%= title 'My page title' %></h1>
95
+
96
+ When views are rendered, the page title will be included in the right spots:
97
+
98
+ <head>
99
+ <title>My website | My page title</title>
100
+ </head>
101
+ <body>
102
+ <h1>My page title</h1>
103
+ </body>
104
+
105
+ You can find allowed options for +display_meta_tags+ method below.
106
+
107
+ === Using MetaTags in controller
108
+
109
+ You can define following instance variables:
110
+
111
+ @page_title = 'Member Login'
112
+ @page_description = 'Member login page.'
113
+ @page_keywords = 'Site, Login, Members'
114
+
115
+ Also you could use +set_meta_tags+ method to define all meta tags simultaneously:
116
+
117
+ set_meta_tags :title => 'Member Login',
118
+ :description => 'Member login page.',
119
+ :keywords => 'Site, Login, Members'
120
+
121
+ You can find allowed options for +set_meta_tags+ method below.
122
+
123
+ === Using MetaTags in view
124
+
125
+ To set meta tags you can use following methods:
126
+
127
+ <% title 'Member Login' %>
128
+ <% description 'Member login page.' %>
129
+ <% keywords 'Member login page.' %>
130
+
131
+ Also there is +set_meta_tags+ method exists:
132
+
133
+ <% set_meta_tags :title => 'Member Login',
134
+ :description => 'Member login page.',
135
+ :keywords => 'Site, Login, Members' %>
136
+
137
+ The +title+ methods returns title itself, so you can use it to show the title
138
+ somewhere on the page:
139
+
140
+ <h1><%= title 'Member Login' %></h1>
141
+
142
+ If you want to set the title and display another text, use this:
143
+
144
+ <h1><%= title 'Member Login', 'Here you can login to the site:' %></h1>
145
+
146
+ === Allowed options for +display_meta_tags+ and +set_meta_tags+ methods
147
+
148
+ Use these options to customize the title format:
149
+
150
+ * <tt>:site</tt> -- site title;
151
+ * <tt>:title</tt> -- page title;
152
+ * <tt>:description</tt> -- page description;
153
+ * <tt>:keywords</tt> -- page keywords;
154
+ * <tt>:prefix</tt> -- text between site name and separator;
155
+ * <tt>:separator</tt> -- text used to separate website name from page title;
156
+ * <tt>:suffix</tt> -- text between separator and page title;
157
+ * <tt>:lowercase</tt> -- when true, the page name will be lowercase;
158
+ * <tt>:reverse</tt> -- when true, the page and site names will be reversed;
159
+ * <tt>:noindex</tt> -- add noindex meta tag; when true, 'robots' will be used, otherwise the string will be used;
160
+ * <tt>:nofollow</tt> -- add nofollow meta tag; when true, 'robots' will be used, otherwise the string will be used.
161
+
162
+ And here are a few examples to give you ideas.
163
+
164
+ <%= title :separator => "&mdash;" %>
165
+ <%= title :prefix => false, :separator => ":" %>
166
+ <%= title :lowercase => true %>
167
+ <%= title :reverse => true, :prefix => false %>
168
+
169
+ === Allowed values
170
+
171
+ You can specify +title+ as a string or array:
172
+
173
+ set_meta_tags :title => ['part1', 'part2'], :site => 'site'
174
+ # site | part1 | part2
175
+ set_meta_tags :title => ['part1', 'part2'], :reverse => true, :site => 'site'
176
+ # part2 | part1 | site
177
+
178
+ Keywords can be passed as string of comma-separated values, or as an array:
179
+
180
+ set_meta_tags :keywords => ['tag1', 'tag2']
181
+ # tag1, tag2
182
+
183
+ Description is a string (HTML will be stripped from output string).
184
+
185
+ == Alternatives
186
+
187
+ There are several plugins influenced me to create this one:
188
+
189
+ * Headliner: http://github.com/mokolabs/headliner
190
+ * meta_on_rals: http://github.com/ashchan/meta_on_rails
191
+
192
+ == Credits
193
+
194
+ * Dmytro Shteflyuk (author) <kpumuk@kpumuk.info> http://kpumuk.info
195
+ * Morgan Roderick (contributor) <morgan@roderick.dk> http://roderick.dk
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ require 'rake'
2
+ require 'spec/rake/spectask'
3
+ require 'rake/rdoctask'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gemspec|
8
+ gemspec.name = 'meta-tags'
9
+ gemspec.summary = 'Collection of SEO helpers for Ruby on Rails'
10
+ gemspec.description = 'Search Engine Optimization (SEO) plugin for Ruby on Rails applications.'
11
+ gemspec.email = 'kpumuk@kpumuk.info'
12
+ gemspec.homepage = 'http://github.com/kpumuk/meta-tags'
13
+ gemspec.authors = ['Dmytro Shteflyuk']
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts 'Jeweler not available. Install it with: sudo gem install jeweler'
18
+ end
19
+
20
+ desc 'Default: run unit tests.'
21
+ task :default => :spec
22
+
23
+ desc 'Test the meta-tags plugin.'
24
+ Spec::Rake::SpecTask.new(:spec) do |t|
25
+ t.libs << 'lib'
26
+ t.pattern = 'spec/**/*_spec.rb'
27
+ t.verbose = true
28
+ t.spec_opts = ['-cfs']
29
+ end
30
+
31
+ desc 'Generate documentation for the meta-tags plugin.'
32
+ Rake::RDocTask.new(:rdoc) do |rdoc|
33
+ rdoc.rdoc_dir = 'rdoc'
34
+ rdoc.title = 'MetaTags'
35
+ rdoc.options << '--line-numbers' << '--inline-source'
36
+ rdoc.rdoc_files.include('README.rdoc')
37
+ rdoc.rdoc_files.include('lib/**/*.rb')
38
+ end
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 1
3
+ :minor: 1
4
+ :patch: 0
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + '/lib/meta_tags'
data/lib/meta_tags.rb ADDED
@@ -0,0 +1,8 @@
1
+ module MetaTags
2
+ end
3
+
4
+ require File.dirname(__FILE__) + '/meta_tags/view_helper'
5
+ require File.dirname(__FILE__) + '/meta_tags/controller_helper'
6
+
7
+ ActionView::Base.send :include, MetaTags::ViewHelper
8
+ ActionController::Base.send :include, MetaTags::ControllerHelper
@@ -0,0 +1,43 @@
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
+ module MetaTags
11
+ 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
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)
30
+
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
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,199 @@
1
+ # Contains methods to use in views and helpers.
2
+ module MetaTags
3
+ module ViewHelper
4
+ # Set meta tags for the page.
5
+ #
6
+ # Method could be used several times, and all options passed will
7
+ # be merged. If you will set the same property several times, last one
8
+ # will take precedence.
9
+ #
10
+ # Examples:
11
+ # set_meta_tags :title => 'Login Page', :description => 'Here you can login'
12
+ # set_meta_tags :keywords => 'authorization, login'
13
+ #
14
+ # Usually you will not call this method directly. Use +title+, +keywords+,
15
+ # +description+ for your daily tasks.
16
+ #
17
+ # See +display_meta_tags+ for allowed options.
18
+ def set_meta_tags(meta_tags = {})
19
+ @meta_tags ||= {}
20
+ @meta_tags.merge!(meta_tags || {})
21
+ end
22
+
23
+ # Set the page title and return it back.
24
+ #
25
+ # This method is best suited for use in helpers. It sets the page title
26
+ # and returns it (or +headline+ if specified).
27
+ #
28
+ # Examples:
29
+ # <%= title 'Login Page' %> => title='Login Page', return='Login Page'
30
+ # <%= title 'Login Page', 'Please login' %> => title='Login Page', return='Please Login'
31
+ #
32
+ # You can specify +title+ as a string or array:
33
+ # title :title => ['part1', 'part2']
34
+ # # part1 | part2
35
+ def title(title, headline = '')
36
+ set_meta_tags(:title => title)
37
+ headline.blank? ? title : headline
38
+ end
39
+
40
+ # Set the page keywords.
41
+ #
42
+ # Keywords can be passed as string of comma-separated values, or as an array:
43
+ #
44
+ # set_meta_tags :keywords => ['tag1', 'tag2']
45
+ # # tag1, tag2
46
+ #
47
+ # Examples:
48
+ # <% keywords 'keyword1, keyword2' %>
49
+ # <% keywords %w(keyword1 keyword2) %>
50
+ def keywords(keywords)
51
+ set_meta_tags(:keywords => keywords)
52
+ keywords
53
+ end
54
+
55
+ # Set the page description.
56
+ #
57
+ # Description is a string (HTML will be stripped from output string).
58
+ #
59
+ # Examples:
60
+ # <% description 'This is login page' %>
61
+ def description(description)
62
+ set_meta_tags(:description => description)
63
+ description
64
+ end
65
+
66
+ # Set the noindex meta tag
67
+ #
68
+ # You can specify noindex as a boolean or string
69
+ #
70
+ # Examples:
71
+ # <% noindex true %>
72
+ # <% noindex 'googlebot' %>
73
+ def noindex(noindex)
74
+ set_meta_tags(:noindex => noindex)
75
+ noindex
76
+ end
77
+
78
+ # Set the nofollow meta tag
79
+ #
80
+ # You can specify nofollow as a boolean or string
81
+ #
82
+ # Examples:
83
+ # <% nofollow true %>
84
+ # <% nofollow 'googlebot' %>
85
+ def nofollow(nofollow)
86
+ set_meta_tags(:nofollow => nofollow)
87
+ nofollow
88
+ 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:
95
+ # <head>
96
+ # <%= display_meta_tags :site => 'My website' %>
97
+ # </head>
98
+ #
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
+ def display_meta_tags(default = {})
112
+ meta_tags = (default || {}).merge(@meta_tags || {})
113
+
114
+ # Prefix (leading space)
115
+ if meta_tags[:prefix]
116
+ prefix = meta_tags[:prefix]
117
+ elsif meta_tags[:prefix] === false
118
+ prefix = ''
119
+ else
120
+ prefix = ' '
121
+ end
122
+
123
+ # Separator
124
+ unless meta_tags[:separator].blank?
125
+ separator = meta_tags[:separator]
126
+ else
127
+ separator = '|'
128
+ end
129
+
130
+ # Suffix (trailing space)
131
+ if meta_tags[:suffix]
132
+ suffix = meta_tags[:suffix]
133
+ elsif meta_tags[:suffix] === false
134
+ suffix = ''
135
+ else
136
+ suffix = ' '
137
+ end
138
+
139
+ # Title
140
+ title = meta_tags[:title]
141
+ if meta_tags[:lowercase] === true
142
+ title = title.downcase unless title.blank?
143
+ end
144
+
145
+ # title
146
+ if title.blank?
147
+ result = content_tag :title, meta_tags[:site]
148
+ else
149
+ title = normalize_title(title)
150
+ title = [meta_tags[:site]] + title
151
+ title.reverse! if meta_tags[:reverse] === true
152
+ sep = prefix + separator + suffix
153
+ result = content_tag(:title, title.join(sep))
154
+ end
155
+
156
+ # description
157
+ description = normalize_description(meta_tags[:description])
158
+ result << "\n" + tag(:meta, :name => :description, :content => description) unless description.blank?
159
+
160
+ # keywords
161
+ keywords = normalize_keywords(meta_tags[:keywords])
162
+ result << "\n" + tag(:meta, :name => :keywords, :content => keywords) unless keywords.blank?
163
+
164
+ # noindex & nofollow
165
+ noindex_name = meta_tags[:noindex].is_a?(String) ? meta_tags[:noindex] : 'robots'
166
+ nofollow_name = meta_tags[:nofollow].is_a?(String) ? meta_tags[:nofollow] : 'robots'
167
+
168
+ if noindex_name == nofollow_name
169
+ content = [(meta_tags[:noindex] ? 'noindex' : nil), (meta_tags[:nofollow] ? 'nofollow' : nil)].compact.join(', ')
170
+ result << "\n" + tag(:meta, :name => noindex_name, :content => content) unless content.blank?
171
+ else
172
+ result << "\n" + tag(:meta, :name => noindex_name, :content => 'noindex') if meta_tags[:noindex]
173
+ result << "\n" + tag(:meta, :name => nofollow_name, :content => 'nofollow') if meta_tags[:nofollow]
174
+ end
175
+
176
+ return result
177
+ end
178
+
179
+ private
180
+
181
+ def normalize_title(title)
182
+ if title.is_a? String
183
+ title = [title]
184
+ end
185
+ title.map { |t| h(strip_tags(t)) }
186
+ end
187
+
188
+ def normalize_description(description)
189
+ return '' unless description
190
+ truncate(strip_tags(description).gsub(/\s+/, ' '), :length => 200)
191
+ end
192
+
193
+ def normalize_keywords(keywords)
194
+ return '' unless keywords
195
+ keywords = keywords.flatten.join(', ') if keywords.is_a?(Array)
196
+ strip_tags(keywords).mb_chars.downcase
197
+ end
198
+ end
199
+ end
data/meta-tags.gemspec ADDED
@@ -0,0 +1,52 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{meta-tags}
8
+ s.version = "1.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Dmytro Shteflyuk"]
12
+ s.date = %q{2009-11-05}
13
+ s.description = %q{Search Engine Optimization (SEO) plugin for Ruby on Rails applications.}
14
+ s.email = %q{kpumuk@kpumuk.info}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "MIT-LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION.yml",
24
+ "init.rb",
25
+ "lib/meta_tags.rb",
26
+ "lib/meta_tags/controller_helper.rb",
27
+ "lib/meta_tags/view_helper.rb",
28
+ "meta-tags.gemspec",
29
+ "spec/meta_tags_spec.rb",
30
+ "spec/spec_helper.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/kpumuk/meta-tags}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.5}
36
+ s.summary = %q{Collection of SEO helpers for Ruby on Rails}
37
+ s.test_files = [
38
+ "spec/meta_tags_spec.rb",
39
+ "spec/spec_helper.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ else
48
+ end
49
+ else
50
+ end
51
+ end
52
+
@@ -0,0 +1,278 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe MetaTags::ViewHelper do
4
+ before :each do
5
+ @view = ActionView::Base.new
6
+ end
7
+
8
+ context 'module' do
9
+ it 'should be mixed into ActionView::Base' do
10
+ ActionView::Base.included_modules.should include(MetaTags::ViewHelper)
11
+ end
12
+
13
+ it 'should respond to "title" helper' do
14
+ @view.should respond_to(:title)
15
+ end
16
+
17
+ it 'should respond to "description" helper' do
18
+ @view.should respond_to(:description)
19
+ end
20
+
21
+ it 'should respond to "keywords" helper' do
22
+ @view.should respond_to(:keywords)
23
+ end
24
+
25
+ it 'should respond to "noindex" helper' do
26
+ @view.should respond_to(:noindex)
27
+ end
28
+
29
+ it 'should respond to "nofollow" helper' do
30
+ @view.should respond_to(:nofollow)
31
+ end
32
+
33
+ it 'should respond to "set_meta_tags" helper' do
34
+ @view.should respond_to(:set_meta_tags)
35
+ end
36
+
37
+ it 'should respond to "display_meta_tags" helper' do
38
+ @view.should respond_to(:display_meta_tags)
39
+ end
40
+ end
41
+
42
+ context 'returning values' do
43
+ it 'should return title' do
44
+ @view.title('some-title').should == 'some-title'
45
+ end
46
+
47
+ it 'should return headline if specified' do
48
+ @view.title('some-title', 'some-headline').should == 'some-headline'
49
+ end
50
+
51
+ it 'should return description' do
52
+ @view.description('some-description').should == 'some-description'
53
+ end
54
+
55
+ it 'should return keywords' do
56
+ @view.keywords('some-keywords').should == 'some-keywords'
57
+ end
58
+
59
+ it 'should return noindex' do
60
+ @view.noindex('some-noindex').should == 'some-noindex'
61
+ end
62
+
63
+ it 'should return nofollow' do
64
+ @view.noindex('some-nofollow').should == 'some-nofollow'
65
+ end
66
+ end
67
+
68
+ context 'title' do
69
+ it 'should use website name if title is empty' do
70
+ @view.display_meta_tags(:site => 'someSite').should == '<title>someSite</title>'
71
+ end
72
+
73
+ it 'should display title when "title" used' do
74
+ @view.title('someTitle')
75
+ @view.display_meta_tags(:site => 'someSite').should == '<title>someSite | someTitle</title>'
76
+ end
77
+
78
+ it 'should display title when "set_meta_tags" used' do
79
+ @view.set_meta_tags(:title => 'someTitle')
80
+ @view.display_meta_tags(:site => 'someSite').should == '<title>someSite | someTitle</title>'
81
+ end
82
+
83
+ it 'should display custom title if given' do
84
+ @view.title('someTitle')
85
+ @view.display_meta_tags(:site => 'someSite', :title => 'defaultTitle').should == '<title>someSite | someTitle</title>'
86
+ end
87
+
88
+ it 'should use website before page by default' do
89
+ @view.display_meta_tags(:site => 'someSite', :title => 'someTitle').should == '<title>someSite | someTitle</title>'
90
+ end
91
+
92
+ it 'should only use markup in titles in the view' do
93
+ @view.title('<b>someTitle</b>').should == '<b>someTitle</b>'
94
+ @view.display_meta_tags(:site => 'someSite').should == '<title>someSite | someTitle</title>'
95
+ end
96
+
97
+ it 'should use page before website if :reverse' do
98
+ @view.display_meta_tags(:site => 'someSite', :title => 'someTitle', :reverse => true).should == '<title>someTitle | someSite</title>'
99
+ end
100
+
101
+ it 'should be lowercase if :lowercase' do
102
+ @view.display_meta_tags(:site => 'someSite', :title => 'someTitle', :lowercase => true).should == '<title>someSite | sometitle</title>'
103
+ end
104
+
105
+ it 'should use custom separator if :separator' do
106
+ @view.title('someTitle')
107
+ @view.display_meta_tags(:site => 'someSite', :separator => '-').should == '<title>someSite - someTitle</title>'
108
+ @view.display_meta_tags(:site => 'someSite', :separator => ':').should == '<title>someSite : someTitle</title>'
109
+ @view.display_meta_tags(:site => 'someSite', :separator => '&mdash;').should == '<title>someSite &mdash; someTitle</title>'
110
+ end
111
+
112
+ it 'should use custom prefix and suffix if available' do
113
+ @view.display_meta_tags(:site => 'someSite', :title => 'someTitle', :prefix => ' -', :suffix => '- ').should == '<title>someSite -|- someTitle</title>'
114
+ end
115
+
116
+ it 'should collapse prefix if false' do
117
+ @view.display_meta_tags(:site => 'someSite', :title => 'someTitle', :prefix => false).should == '<title>someSite| someTitle</title>'
118
+ end
119
+
120
+ it 'should collapse suffix if false' do
121
+ @view.display_meta_tags(:site => 'someSite', :title => 'someTitle', :suffix => false).should == '<title>someSite |someTitle</title>'
122
+ end
123
+
124
+ it 'should use all custom options if available' do
125
+ @view.display_meta_tags(:site => 'someSite',
126
+ :title => 'someTitle',
127
+ :prefix => ' -',
128
+ :suffix => '+ ',
129
+ :separator => ':',
130
+ :lowercase => true,
131
+ :reverse => true).should == '<title>sometitle -:+ someSite</title>'
132
+ end
133
+
134
+ it 'shold allow Arrays in title' do
135
+ @view.display_meta_tags(:site => 'someSite', :title => ['someTitle', 'anotherTitle']).should == '<title>someSite | someTitle | anotherTitle</title>'
136
+ end
137
+
138
+ it 'shold build title in reverse order if :reverse' do
139
+ @view.display_meta_tags(:site => 'someSite',
140
+ :title => ['someTitle', 'anotherTitle'],
141
+ :prefix => ' -',
142
+ :suffix => '+ ',
143
+ :separator => ':',
144
+ :reverse => true).should == '<title>anotherTitle -:+ someTitle -:+ someSite</title>'
145
+ end
146
+ end
147
+
148
+ context 'displaying description' do
149
+ it 'should display description when "description" used' do
150
+ @view.description('someDescription')
151
+ @view.display_meta_tags(:site => 'someSite').should include('<meta content="someDescription" name="description" />')
152
+ end
153
+
154
+ it 'should display description when "set_meta_tags" used' do
155
+ @view.set_meta_tags(:description => 'someDescription')
156
+ @view.display_meta_tags(:site => 'someSite').should include('<meta content="someDescription" name="description" />')
157
+ end
158
+
159
+ it 'should display default description' do
160
+ @view.display_meta_tags(:site => 'someSite', :description => 'someDescription').should include('<meta content="someDescription" name="description" />')
161
+ end
162
+
163
+ it 'should use custom description if given' do
164
+ @view.description('someDescription')
165
+ @view.display_meta_tags(:site => 'someSite', :description => 'defaultDescription').should include('<meta content="someDescription" name="description" />')
166
+ end
167
+
168
+ it 'should strip multiple spaces' do
169
+ @view.display_meta_tags(:site => 'someSite', :description => "some \n\r\t description").should include('<meta content="some description" name="description" />')
170
+ end
171
+
172
+ it 'should strip HTML' do
173
+ @view.display_meta_tags(:site => 'someSite', :description => "<p>some <b>description</b></p>").should include('<meta content="some description" name="description" />')
174
+ end
175
+ end
176
+
177
+ context 'displaying keywords' do
178
+ it 'should display keywords when "keywords" used' do
179
+ @view.keywords('some-keywords')
180
+ @view.display_meta_tags(:site => 'someSite').should include('<meta content="some-keywords" name="keywords" />')
181
+ end
182
+
183
+ it 'should display keywords when "set_meta_tags" used' do
184
+ @view.set_meta_tags(:keywords => 'some-keywords')
185
+ @view.display_meta_tags(:site => 'someSite').should include('<meta content="some-keywords" name="keywords" />')
186
+ end
187
+
188
+ it 'should display default keywords' do
189
+ @view.display_meta_tags(:site => 'someSite', :keywords => 'some-keywords').should include('<meta content="some-keywords" name="keywords" />')
190
+ end
191
+
192
+ it 'should use custom keywords if given' do
193
+ @view.keywords('some-keywords')
194
+ @view.display_meta_tags(:site => 'someSite', :keywords => 'default_keywords').should include('<meta content="some-keywords" name="keywords" />')
195
+ end
196
+
197
+ it 'should lowercase keywords' do
198
+ @view.display_meta_tags(:site => 'someSite', :keywords => 'someKeywords').should include('<meta content="somekeywords" name="keywords" />')
199
+ end
200
+
201
+ it 'should join keywords from Array' do
202
+ @view.display_meta_tags(:site => 'someSite', :keywords => %w(keyword1 keyword2)).should include('<meta content="keyword1, keyword2" name="keywords" />')
203
+ end
204
+
205
+ it 'should join keywords from nested Arrays' do
206
+ @view.display_meta_tags(:site => 'someSite', :keywords => [%w(keyword1 keyword2), 'keyword3']).should include('<meta content="keyword1, keyword2, keyword3" name="keywords" />')
207
+ end
208
+ end
209
+
210
+ context 'displaying noindex' do
211
+ it 'should display noindex when "noindex" used' do
212
+ @view.noindex(true)
213
+ @view.display_meta_tags(:site => 'someSite').should include('<meta content="noindex" name="robots" />')
214
+ end
215
+
216
+ it 'should display noindex when "set_meta_tags" used' do
217
+ @view.set_meta_tags(:noindex => true)
218
+ @view.display_meta_tags(:site => 'someSite').should include('<meta content="noindex" name="robots" />')
219
+ end
220
+
221
+ it 'should use custom noindex if given' do
222
+ @view.noindex('some-noindex')
223
+ @view.display_meta_tags(:site => 'someSite').should include('<meta content="noindex" name="some-noindex" />')
224
+ end
225
+
226
+ it 'should display nothing by default' do
227
+ @view.display_meta_tags(:site => 'someSite').should_not include('<meta content="noindex"')
228
+ end
229
+ end
230
+
231
+ context 'displaying nofollow' do
232
+ it 'should display nofollow when "nofollow" used' do
233
+ @view.nofollow(true)
234
+ @view.display_meta_tags(:site => 'someSite').should include('<meta content="nofollow" name="robots" />')
235
+ end
236
+
237
+ it 'should display nofollow when "set_meta_tags" used' do
238
+ @view.set_meta_tags(:nofollow => true)
239
+ @view.display_meta_tags(:site => 'someSite').should include('<meta content="nofollow" name="robots" />')
240
+ end
241
+
242
+ it 'should use custom nofollow if given' do
243
+ @view.nofollow('some-nofollow')
244
+ @view.display_meta_tags(:site => 'someSite').should include('<meta content="nofollow" name="some-nofollow" />')
245
+ end
246
+
247
+ it 'should display nothing by default' do
248
+ @view.display_meta_tags(:site => 'someSite').should_not include('<meta content="nofollow"')
249
+ end
250
+ end
251
+
252
+ context 'displaying both nofollow and noindex' do
253
+ it 'should be displayed when set using helpers' do
254
+ @view.noindex(true)
255
+ @view.nofollow(true)
256
+ @view.display_meta_tags(:site => 'someSite').should include('<meta content="noindex, nofollow" name="robots" />')
257
+ end
258
+
259
+ it 'should be displayed when "set_meta_tags" used' do
260
+ @view.set_meta_tags(:nofollow => true, :noindex => true)
261
+ @view.display_meta_tags(:site => 'someSite').should include('<meta content="noindex, nofollow" name="robots" />')
262
+ end
263
+
264
+ it 'should use custom name if string is used' do
265
+ @view.noindex('some-name')
266
+ @view.nofollow('some-name')
267
+ @view.display_meta_tags(:site => 'someSite').should include('<meta content="noindex, nofollow" name="some-name" />')
268
+ end
269
+
270
+ it 'should display two meta tags when different names used' do
271
+ @view.noindex('some-noindex')
272
+ @view.nofollow('some-nofollow')
273
+ content = @view.display_meta_tags(:site => 'someSite')
274
+ content.should include('<meta content="noindex" name="some-noindex" />')
275
+ content.should include('<meta content="nofollow" name="some-nofollow" />')
276
+ end
277
+ end
278
+ end
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'action_controller'
3
+ require 'action_view'
4
+
5
+ require File.join(File.dirname(__FILE__), "../init")
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: meta-tags
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dmytro Shteflyuk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-05 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Search Engine Optimization (SEO) plugin for Ruby on Rails applications.
17
+ email: kpumuk@kpumuk.info
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - .gitignore
26
+ - MIT-LICENSE
27
+ - README.rdoc
28
+ - Rakefile
29
+ - VERSION.yml
30
+ - init.rb
31
+ - lib/meta_tags.rb
32
+ - lib/meta_tags/controller_helper.rb
33
+ - lib/meta_tags/view_helper.rb
34
+ - meta-tags.gemspec
35
+ - spec/meta_tags_spec.rb
36
+ - spec/spec_helper.rb
37
+ has_rdoc: true
38
+ homepage: http://github.com/kpumuk/meta-tags
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options:
43
+ - --charset=UTF-8
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.3.5
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Collection of SEO helpers for Ruby on Rails
65
+ test_files:
66
+ - spec/meta_tags_spec.rb
67
+ - spec/spec_helper.rb