metanol 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -4
- data/lib/metanol.rb +7 -0
- data/lib/metanol/engine_controller.rb +24 -56
- data/lib/metanol/helpers.rb +19 -26
- data/lib/metanol/meta/base.rb +24 -12
- data/lib/metanol/meta/main.rb +3 -2
- data/lib/metanol/meta/micro_data.rb +13 -0
- data/lib/metanol/meta/open_graph.rb +12 -4
- data/lib/metanol/meta/webmaster.rb +2 -2
- data/lib/metanol/support.rb +8 -0
- data/lib/metanol/version.rb +1 -1
- data/metanol.gemspec +2 -2
- data/spec/controllers/tests_controller_spec.rb +10 -3
- metadata +6 -4
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# Metanol
|
2
2
|
|
3
|
-
This is a meta tags plugin which helps to manage meta tags in your Rails application. It supports some OpenGraph meta tags, Webmaster's meta tags (such as Google, Bing, Yandex, Alexa verification meta tags) and other standard HTML meta tags (such as a description). It can be used by Rails 3.2+ applications.
|
3
|
+
This is a meta tags plugin which helps to manage meta tags in your Rails application. It supports some OpenGraph meta tags, Webmaster's meta tags (such as Google, Bing, Yandex, Alexa verification meta tags), MicroData meta tags and other standard HTML meta tags (such as a description). It can be used by Rails 3.2+ applications.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
gem 'metanol', '~> 0.0.
|
9
|
+
gem 'metanol', '~> 0.0.5'
|
10
10
|
|
11
11
|
And then execute:
|
12
12
|
|
@@ -59,6 +59,7 @@ There are three methods for setting values for meta tags:
|
|
59
59
|
* `meta(meta_name, value) or meta({meta_name: value, meta_name2: value2, ...})` - sets a value(s) for common meta tags
|
60
60
|
* `og_meta` - sets a value(s) for OpenGraph's meta tags
|
61
61
|
* `wm_meta` - sets a value(s) for Webmaster verification's meta tags
|
62
|
+
* `md_meta` - sets a value(s) for MicroData meta tags
|
62
63
|
|
63
64
|
This plugin also gives you the ability to set the TITLE tag: `meta :title, "Page title"` renders into `<title>Page title</title>`.
|
64
65
|
|
@@ -70,8 +71,9 @@ There are some filters which you can set for methods above:
|
|
70
71
|
|
71
72
|
There are some methods for getting a meta's value:
|
72
73
|
* `get_meta(name)` - returns a value of a specified HTML meta tag
|
73
|
-
* `get_og_meta(name)` - returns a value of a specified OpenGraph meta
|
74
|
-
* `get_wm_meta(name)` - returns a value of a specified Webmaster meta
|
74
|
+
* `get_og_meta(name)` - returns a value of a specified OpenGraph meta tag
|
75
|
+
* `get_wm_meta(name)` - returns a value of a specified Webmaster meta tag
|
76
|
+
* `get_md_meta(name)` - returns a value of a specified MicroData meta tag
|
75
77
|
|
76
78
|
### Helpers
|
77
79
|
|
@@ -79,6 +81,7 @@ Here is the helper's methods for rendering meta tags:
|
|
79
81
|
* `metanol_tags` - renders all meta tags (Webmaster, OpenGraph and other)
|
80
82
|
* `metanol_og_tags` - renders only OpenGraph's meta tags
|
81
83
|
* `metanol_wm_tags` - renders Webmaster verification tags
|
84
|
+
* `metanol_md_tags` - renders MicroData tags (which has itemprop as a meta's key)
|
82
85
|
* `metanol_main_tags` - renders other meta tags, such as keywords, description, etc.
|
83
86
|
|
84
87
|
Also the plugin provides some helper's methods for getting a meta's value: `get_meta(name)`, `get_og_meta(name)`, `get_wm_meta(name)`.
|
data/lib/metanol.rb
CHANGED
@@ -2,6 +2,13 @@ require 'metanol/version'
|
|
2
2
|
|
3
3
|
require 'rails'
|
4
4
|
|
5
|
+
require 'metanol/meta/base'
|
6
|
+
require 'metanol/meta/main'
|
7
|
+
require 'metanol/meta/open_graph'
|
8
|
+
require 'metanol/meta/webmaster'
|
9
|
+
require 'metanol/meta/micro_data'
|
10
|
+
|
11
|
+
require 'metanol/support'
|
5
12
|
require 'metanol/helpers'
|
6
13
|
require 'metanol/engine_controller'
|
7
14
|
require 'metanol/railtie'
|
@@ -1,7 +1,3 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'meta/base')
|
2
|
-
require File.join(File.dirname(__FILE__), 'meta/main')
|
3
|
-
require File.join(File.dirname(__FILE__), 'meta/open_graph')
|
4
|
-
require File.join(File.dirname(__FILE__), 'meta/webmaster')
|
5
1
|
require 'active_support/dependencies'
|
6
2
|
|
7
3
|
module Metanol
|
@@ -15,28 +11,16 @@ module Metanol
|
|
15
11
|
@@metanol_options ||= {}
|
16
12
|
end
|
17
13
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
add_meta_tag(:og, *args)
|
24
|
-
end
|
25
|
-
|
26
|
-
def wm_meta(*args)
|
27
|
-
add_meta_tag(:wm, *args)
|
28
|
-
end
|
29
|
-
|
30
|
-
def get_meta(name)
|
31
|
-
get_meta_by_type(:main, name)
|
32
|
-
end
|
33
|
-
|
34
|
-
def get_og_meta(name)
|
35
|
-
get_meta_by_type(:og, name)
|
36
|
-
end
|
14
|
+
SUPPORT_GROUPS.keys.each do |method|
|
15
|
+
method_name = "#{method == :main ? '' : "#{method}_"}meta"
|
16
|
+
define_method method_name do |*args|
|
17
|
+
add_meta_tag(method, *args)
|
18
|
+
end
|
37
19
|
|
38
|
-
|
39
|
-
|
20
|
+
get_method_name = "get_#{method_name}"
|
21
|
+
define_method get_method_name do |name|
|
22
|
+
get_meta_by_type(method, name)
|
23
|
+
end
|
40
24
|
end
|
41
25
|
|
42
26
|
private
|
@@ -56,59 +40,43 @@ module Metanol
|
|
56
40
|
end
|
57
41
|
|
58
42
|
def add_meta_by_type(type, name, value, filters=[])
|
59
|
-
|
60
|
-
key =
|
43
|
+
meta_class = SUPPORT_GROUPS[type]
|
44
|
+
key = get_meta_key(type, name)
|
61
45
|
if metanol_options.key? key
|
62
46
|
metanol_options[key].value = value
|
63
47
|
metanol_options[key].filters = filters
|
64
48
|
else
|
65
|
-
metanol_options[key] =
|
49
|
+
metanol_options[key] = meta_class.new(name, value, filters)
|
66
50
|
end
|
67
51
|
end
|
68
52
|
|
69
53
|
def get_meta_by_type(type, name)
|
70
|
-
|
71
|
-
key = data[:key]
|
54
|
+
key = get_meta_key(type, name)
|
72
55
|
metanol_options.key?(key) ? metanol_options[key].value : nil
|
73
56
|
end
|
74
57
|
|
75
|
-
def
|
76
|
-
{
|
77
|
-
main: { key: name, type: Meta::Main },
|
78
|
-
og: { key: "og:#{name}", type: Meta::OpenGraph },
|
79
|
-
wm: { key: "wm:#{name}", type: Meta::Webmaster }
|
80
|
-
}
|
58
|
+
def get_meta_key(type, name)
|
59
|
+
"#{type}:#{name}"
|
81
60
|
end
|
82
|
-
end
|
83
61
|
|
84
|
-
def meta(*args)
|
85
|
-
self.class.meta(*args)
|
86
62
|
end
|
87
63
|
|
88
|
-
|
89
|
-
|
90
|
-
|
64
|
+
SUPPORT_GROUPS.keys.each do |method|
|
65
|
+
method_name = "#{method == :main ? '' : "#{method}_"}meta"
|
66
|
+
define_method method_name do |*args|
|
67
|
+
self.class.send(method_name, *args)
|
68
|
+
end
|
91
69
|
|
92
|
-
|
93
|
-
|
70
|
+
get_method_name = "get_#{method_name}"
|
71
|
+
define_method get_method_name do |name|
|
72
|
+
self.class.send(get_method_name, name)
|
73
|
+
end
|
94
74
|
end
|
95
75
|
|
96
76
|
def metanol_options
|
97
77
|
self.class.metanol_options
|
98
78
|
end
|
99
79
|
|
100
|
-
def get_meta(name)
|
101
|
-
self.class.get_meta name
|
102
|
-
end
|
103
|
-
|
104
|
-
def get_og_meta(name)
|
105
|
-
self.class.get_og_meta name
|
106
|
-
end
|
107
|
-
|
108
|
-
def get_wm_meta(name)
|
109
|
-
self.class.get_wm_meta name
|
110
|
-
end
|
111
|
-
|
112
80
|
end
|
113
81
|
|
114
82
|
end
|
data/lib/metanol/helpers.rb
CHANGED
@@ -3,27 +3,32 @@ module Metanol
|
|
3
3
|
|
4
4
|
# Render all meta tags
|
5
5
|
def metanol_tags
|
6
|
-
result =
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
result = ''
|
7
|
+
SUPPORT_GROUPS.keys.each do |type|
|
8
|
+
result << send("metanol_#{type}_tags")
|
9
|
+
end
|
10
|
+
result.html_safe
|
10
11
|
end
|
11
12
|
|
12
13
|
# Render OpenGraph meta tags
|
13
14
|
def metanol_og_tags
|
14
15
|
result = metanol_render_tags ::Metanol::Meta::OpenGraph
|
15
|
-
result << ::Metanol::Meta::OpenGraph.render_current_url(current_url)
|
16
|
-
result
|
16
|
+
result << ::Metanol::Meta::OpenGraph.render_current_url(current_url)
|
17
|
+
result.html_safe
|
17
18
|
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
SUPPORT_GROUPS.keys.each do |method|
|
21
|
+
get_method_name = "get_#{method == :main ? '' : "#{method}_"}meta"
|
22
|
+
define_method get_method_name do |name|
|
23
|
+
self.controller.send(get_method_name, name)
|
24
|
+
end
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
next if method == :og
|
27
|
+
method_name = "metanol_#{method}_tags"
|
28
|
+
class_type = SUPPORT_GROUPS[method]
|
29
|
+
define_method method_name do
|
30
|
+
metanol_render_tags(class_type).html_safe
|
31
|
+
end
|
27
32
|
end
|
28
33
|
|
29
34
|
# Return a current URL
|
@@ -31,18 +36,6 @@ module Metanol
|
|
31
36
|
request.original_url
|
32
37
|
end
|
33
38
|
|
34
|
-
def get_meta(name)
|
35
|
-
self.controller.get_meta(name)
|
36
|
-
end
|
37
|
-
|
38
|
-
def get_og_meta(name)
|
39
|
-
self.controller.get_og_meta(name)
|
40
|
-
end
|
41
|
-
|
42
|
-
def get_wm_meta(name)
|
43
|
-
self.controller.get_wm_meta(name)
|
44
|
-
end
|
45
|
-
|
46
39
|
private
|
47
40
|
|
48
41
|
def metanol_render_tags(type)
|
@@ -51,7 +44,7 @@ module Metanol
|
|
51
44
|
next unless value.is_a? type
|
52
45
|
result << value.render
|
53
46
|
end
|
54
|
-
result
|
47
|
+
result
|
55
48
|
end
|
56
49
|
|
57
50
|
end
|
data/lib/metanol/meta/base.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
module Metanol::Meta
|
2
2
|
|
3
3
|
class Base
|
4
|
-
|
5
|
-
attr_accessor :value
|
4
|
+
attr_writer :value
|
6
5
|
|
7
6
|
SUPPORTED_FILTERS = [:html, :overspaces, :whitespaces, :clean]
|
8
7
|
|
@@ -18,7 +17,21 @@ module Metanol::Meta
|
|
18
17
|
end
|
19
18
|
|
20
19
|
def render
|
21
|
-
|
20
|
+
result = self.value
|
21
|
+
!result.blank? ? "<meta #{self.attr_name}=\"#{self.name}\" #{self.attr_value}=\"#{result}\" />" : ''
|
22
|
+
end
|
23
|
+
|
24
|
+
def name
|
25
|
+
@name
|
26
|
+
end
|
27
|
+
|
28
|
+
def value
|
29
|
+
result = @value
|
30
|
+
return result unless filters?
|
31
|
+
result = self.class.filter_html(result) if @filters.include?(:html) || @filters.include?(:clean)
|
32
|
+
result = self.class.filter_whitespaces(result) if @filters.include?(:whitespaces) || @filters.include?(:clean)
|
33
|
+
result = self.class.filter_overspaces(result) if @filters.include?(:overspaces) || @filters.include?(:clean)
|
34
|
+
result
|
22
35
|
end
|
23
36
|
|
24
37
|
def self.filter_html(text)
|
@@ -40,19 +53,18 @@ module Metanol::Meta
|
|
40
53
|
true
|
41
54
|
end
|
42
55
|
|
43
|
-
def filtered_value
|
44
|
-
result = @value
|
45
|
-
return result unless filters?
|
46
|
-
result = self.class.filter_html(result) if @filters.include?(:html) || @filters.include?(:clean)
|
47
|
-
result = self.class.filter_whitespaces(result) if @filters.include?(:whitespaces) || @filters.include?(:clean)
|
48
|
-
result = self.class.filter_overspaces(result) if @filters.include?(:overspaces) || @filters.include?(:clean)
|
49
|
-
result
|
50
|
-
end
|
51
|
-
|
52
56
|
def filters?
|
53
57
|
@filters && !@filters.empty?
|
54
58
|
end
|
55
59
|
|
60
|
+
def attr_name
|
61
|
+
'name'
|
62
|
+
end
|
63
|
+
|
64
|
+
def attr_value
|
65
|
+
'content'
|
66
|
+
end
|
67
|
+
|
56
68
|
private
|
57
69
|
|
58
70
|
def validate_filters(filters=[])
|
data/lib/metanol/meta/main.rb
CHANGED
@@ -2,8 +2,9 @@ module Metanol::Meta
|
|
2
2
|
|
3
3
|
class Main < Base
|
4
4
|
def render
|
5
|
-
|
6
|
-
|
5
|
+
result = self.value
|
6
|
+
return (!result.blank? ? "<title>#{result}</title>": '') if @name == :title
|
7
|
+
super
|
7
8
|
end
|
8
9
|
end
|
9
10
|
|
@@ -1,13 +1,21 @@
|
|
1
1
|
module Metanol::Meta
|
2
2
|
|
3
3
|
class OpenGraph < Base
|
4
|
-
def render
|
5
|
-
"<meta property=\"og:#{@name}\" content=\"#{filtered_value}\" />"
|
6
|
-
end
|
7
4
|
|
8
5
|
def self.render_current_url(url)
|
9
|
-
"<meta property=\"og:url\" content=\"#{url}\" />"
|
6
|
+
!url.blank? ? "<meta property=\"og:url\" content=\"#{url}\" />" : ''
|
7
|
+
end
|
8
|
+
|
9
|
+
def name
|
10
|
+
"og:#{@name}"
|
10
11
|
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def attr_name
|
16
|
+
'property'
|
17
|
+
end
|
18
|
+
|
11
19
|
end
|
12
20
|
|
13
21
|
end
|
data/lib/metanol/version.rb
CHANGED
data/metanol.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.platform = Gem::Platform::RUBY
|
10
10
|
gem.authors = ["Eugene Kondratyuk"]
|
11
11
|
gem.email = ["ekondr@gmail.com"]
|
12
|
-
gem.description = %q{This is a meta tags plugin which helps to manage meta tags in your Rails application. It supports some OpenGraph meta tags, Webmaster's meta tags (such as Google, Bing, Yandex, Alexa verification meta tags) and other standard HTML meta tags (such as a description). It can be used by Rails 3.2+ applications}
|
13
|
-
gem.summary = %q{A
|
12
|
+
gem.description = %q{This is a meta tags plugin which helps to manage meta tags in your Rails application. It supports some OpenGraph meta tags, Webmaster's meta tags (such as Google, Bing, Yandex, Alexa verification meta tags), MicroData meta tags and other standard HTML meta tags (such as a description). It can be used by Rails 3.2+ applications.}
|
13
|
+
gem.summary = %q{A <META> tags engine plugin for Rails 3.2+ applications}
|
14
14
|
gem.homepage = "https://github.com/ekondr/metanol"
|
15
15
|
|
16
16
|
gem.rubyforge_project = 'metanol'
|
@@ -50,6 +50,7 @@ describe TestsController do
|
|
50
50
|
meta :title, "Users List"
|
51
51
|
meta :description, "Description for a users list"
|
52
52
|
og_meta title: "OpenGraph Title", description: "OpenGraph Description"
|
53
|
+
md_meta description: "MicroData Description"
|
53
54
|
render :inline => <<-ERB
|
54
55
|
<%= metanol_tags %>
|
55
56
|
ERB
|
@@ -62,6 +63,7 @@ describe TestsController do
|
|
62
63
|
it { response.should have_selector('meta[content="OpenGraph Description"]', property: 'og:description') }
|
63
64
|
it { response.should have_selector('title', content: 'Users List') }
|
64
65
|
it { response.should have_selector('meta[content="Description for a users list"]', name: 'description') }
|
66
|
+
it { response.should have_selector('meta[content="MicroData Description"]', itemprop: 'description') }
|
65
67
|
end
|
66
68
|
|
67
69
|
context "raise exception for unsupported metas" do
|
@@ -156,19 +158,22 @@ describe TestsController do
|
|
156
158
|
context "returns meta values in a controller and in a view" do
|
157
159
|
controller do
|
158
160
|
def index
|
159
|
-
meta :title,
|
160
|
-
wm_meta :alexa,
|
161
|
-
og_meta title:
|
161
|
+
meta :title, 'Users List'
|
162
|
+
wm_meta :alexa, 'alexa code'
|
163
|
+
og_meta title: 'OpenGraph Title'
|
164
|
+
md_meta description: 'MicroData Desc'
|
162
165
|
|
163
166
|
@meta = get_meta :title
|
164
167
|
@wm_meta = get_wm_meta :alexa
|
165
168
|
@og_meta = get_og_meta :title
|
169
|
+
@md_meta = get_md_meta :description
|
166
170
|
@og_no_meta = get_og_meta :bad_meta_name
|
167
171
|
|
168
172
|
render :inline => <<-ERB
|
169
173
|
<span>Main meta is <%= get_meta :title %></span>
|
170
174
|
<span>OpenGraph meta is <%= get_og_meta :title %></span>
|
171
175
|
<span>Webmaster meta is <%= get_wm_meta :alexa %></span>
|
176
|
+
<span>MicroData meta is <%= get_md_meta :description %></span>
|
172
177
|
ERB
|
173
178
|
end
|
174
179
|
end
|
@@ -178,9 +183,11 @@ describe TestsController do
|
|
178
183
|
it { response.should have_selector('span', content: 'Main meta is Users List') }
|
179
184
|
it { response.should have_selector('span', content: 'OpenGraph meta is OpenGraph Title') }
|
180
185
|
it { response.should have_selector('span', content: 'Webmaster meta is alexa code') }
|
186
|
+
it { response.should have_selector('span', content: 'MicroData meta is MicroData Desc') }
|
181
187
|
it { assigns(:meta).should == 'Users List' }
|
182
188
|
it { assigns(:wm_meta).should == 'alexa code' }
|
183
189
|
it { assigns(:og_meta).should == 'OpenGraph Title' }
|
190
|
+
it { assigns(:md_meta).should == 'MicroData Desc' }
|
184
191
|
it { assigns(:og_no_meta).should == nil }
|
185
192
|
end
|
186
193
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metanol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -29,8 +29,8 @@ dependencies:
|
|
29
29
|
version: '3.2'
|
30
30
|
description: This is a meta tags plugin which helps to manage meta tags in your Rails
|
31
31
|
application. It supports some OpenGraph meta tags, Webmaster's meta tags (such as
|
32
|
-
Google, Bing, Yandex, Alexa verification meta tags)
|
33
|
-
tags (such as a description). It can be used by Rails 3.2+ applications
|
32
|
+
Google, Bing, Yandex, Alexa verification meta tags), MicroData meta tags and other
|
33
|
+
standard HTML meta tags (such as a description). It can be used by Rails 3.2+ applications.
|
34
34
|
email:
|
35
35
|
- ekondr@gmail.com
|
36
36
|
executables: []
|
@@ -48,9 +48,11 @@ files:
|
|
48
48
|
- lib/metanol/helpers.rb
|
49
49
|
- lib/metanol/meta/base.rb
|
50
50
|
- lib/metanol/meta/main.rb
|
51
|
+
- lib/metanol/meta/micro_data.rb
|
51
52
|
- lib/metanol/meta/open_graph.rb
|
52
53
|
- lib/metanol/meta/webmaster.rb
|
53
54
|
- lib/metanol/railtie.rb
|
55
|
+
- lib/metanol/support.rb
|
54
56
|
- lib/metanol/version.rb
|
55
57
|
- metanol.gemspec
|
56
58
|
- spec/controllers/home_controller_spec.rb
|
@@ -81,7 +83,7 @@ rubyforge_project: metanol
|
|
81
83
|
rubygems_version: 1.8.25
|
82
84
|
signing_key:
|
83
85
|
specification_version: 3
|
84
|
-
summary: A
|
86
|
+
summary: A <META> tags engine plugin for Rails 3.2+ applications
|
85
87
|
test_files:
|
86
88
|
- spec/controllers/home_controller_spec.rb
|
87
89
|
- spec/controllers/tests_controller_spec.rb
|