metamagic 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +72 -11
- data/lib/metamagic/renderer.rb +4 -2
- data/lib/metamagic/tag.rb +5 -0
- data/lib/metamagic/tags/custom_tag.rb +4 -0
- data/lib/metamagic/tags/link_tag.rb +7 -0
- data/lib/metamagic/tags/meta_tag.rb +4 -0
- data/lib/metamagic/tags/open_graph_tag.rb +7 -0
- data/lib/metamagic/tags/property_tag.rb +0 -5
- data/lib/metamagic/tags/twitter_tag.rb +7 -0
- data/lib/metamagic/version.rb +1 -1
- data/lib/metamagic.rb +3 -0
- data/test/custom_tag_test.rb +18 -0
- data/test/link_tag_test.rb +22 -0
- data/test/meta_tag_test.rb +16 -0
- data/test/metamagic_test.rb +7 -21
- data/test/open_graph_test.rb +2 -2
- data/test/property_tag_test.rb +8 -0
- data/test/title_tag_test.rb +14 -0
- data/test/{twitter_test.rb → twitter_tag_test.rb} +3 -2
- metadata +20 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 441f987b272f8c0e3ba824f605200ff7bbcfe99c
|
4
|
+
data.tar.gz: 542b12e92fb1dde3e7fda07af2ba2f42c23ad6ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c56cad2e5724979f9c80b674631173a0a4b8212a43f5ed603d08be7f0f929c1fc6198513a3b06805dc570415ffe1294051c60f103117adcaa1bca4c728e4632e
|
7
|
+
data.tar.gz: 3e1bc82654ba692999f50103be16c5a222ac356bd87e70675d7af3c69699e550ffff56decd576da059f826c654db2644e78019340e42b9698dd098d836d11fab
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ Installation
|
|
16
16
|
In your *Gemfile*:
|
17
17
|
|
18
18
|
```ruby
|
19
|
-
gem 'metamagic'
|
19
|
+
gem 'metamagic'
|
20
20
|
```
|
21
21
|
|
22
22
|
Then run `bundle install`.
|
@@ -26,16 +26,7 @@ Examples
|
|
26
26
|
|
27
27
|
### Basic usage
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
```erb
|
32
|
-
<head>
|
33
|
-
<%= metamagic %>
|
34
|
-
...
|
35
|
-
</head>
|
36
|
-
```
|
37
|
-
|
38
|
-
Then, at the top of your view, e.g. *app/views/posts/show.html.erb*:
|
29
|
+
At the top of your view, e.g. *app/views/posts/show.html.erb*:
|
39
30
|
|
40
31
|
```erb
|
41
32
|
<%
|
@@ -45,6 +36,15 @@ meta title: "My Title",
|
|
45
36
|
%>
|
46
37
|
```
|
47
38
|
|
39
|
+
And in *app/views/layouts/application.html.erb*:
|
40
|
+
|
41
|
+
```erb
|
42
|
+
<head>
|
43
|
+
<%= metamagic %>
|
44
|
+
...
|
45
|
+
</head>
|
46
|
+
```
|
47
|
+
|
48
48
|
This will generate the following:
|
49
49
|
|
50
50
|
```html
|
@@ -114,6 +114,67 @@ This will generate the following:
|
|
114
114
|
</head>
|
115
115
|
```
|
116
116
|
|
117
|
+
### Adding relation links
|
118
|
+
|
119
|
+
You can add `<link rel="xx" href="xx">` tags like this:
|
120
|
+
|
121
|
+
```erb
|
122
|
+
<%
|
123
|
+
meta rel: {
|
124
|
+
author: "http://test.com/author.html",
|
125
|
+
publisher: "http://test.com/publisher.html"
|
126
|
+
}
|
127
|
+
%>
|
128
|
+
```
|
129
|
+
|
130
|
+
Or using the `rel` shortcut helper:
|
131
|
+
|
132
|
+
```erb
|
133
|
+
<%
|
134
|
+
rel author: "http://test.com/author.html",
|
135
|
+
publisher: "http://test.com/publisher.html"
|
136
|
+
%>
|
137
|
+
```
|
138
|
+
|
139
|
+
This will generate the following:
|
140
|
+
|
141
|
+
```html
|
142
|
+
<head>
|
143
|
+
...
|
144
|
+
<link href="http://test.com/author.html" rel="author" />
|
145
|
+
<link href="http://test.com/publisher.html" rel="publisher" />
|
146
|
+
...
|
147
|
+
</head>
|
148
|
+
```
|
149
|
+
|
150
|
+
### Canonical links
|
151
|
+
|
152
|
+
For easy setting canonical links, you can use the following:
|
153
|
+
|
154
|
+
```erb
|
155
|
+
<%
|
156
|
+
meta canonical: "http://test.com/page.html"
|
157
|
+
%>
|
158
|
+
```
|
159
|
+
|
160
|
+
Or using the shortcut helper:
|
161
|
+
|
162
|
+
```erb
|
163
|
+
<%
|
164
|
+
canonical "http://test.com/page.html"
|
165
|
+
%>
|
166
|
+
```
|
167
|
+
|
168
|
+
This will generate the following:
|
169
|
+
|
170
|
+
```html
|
171
|
+
<head>
|
172
|
+
...
|
173
|
+
<link href="http://test.com/page.html" rel="canonical" />
|
174
|
+
...
|
175
|
+
</head>
|
176
|
+
```
|
177
|
+
|
117
178
|
### Custom properties
|
118
179
|
|
119
180
|
#### OpenGraph (Facebook)
|
data/lib/metamagic/renderer.rb
CHANGED
data/lib/metamagic/tag.rb
CHANGED
@@ -4,6 +4,7 @@ module Metamagic
|
|
4
4
|
|
5
5
|
def initialize(context, key, value)
|
6
6
|
@context, @key, @value = context, key, value
|
7
|
+
@key = @key.gsub /^[^:]+:/, "" if remove_prefix?
|
7
8
|
end
|
8
9
|
|
9
10
|
def to_html
|
@@ -14,6 +15,10 @@ module Metamagic
|
|
14
15
|
1000
|
15
16
|
end
|
16
17
|
|
18
|
+
def remove_prefix?
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
17
22
|
def ==(other)
|
18
23
|
self.class == other.class && self.key == other.key
|
19
24
|
end
|
@@ -1,10 +1,5 @@
|
|
1
1
|
module Metamagic
|
2
2
|
class PropertyTag < Tag
|
3
|
-
def initialize(context, key, value)
|
4
|
-
super
|
5
|
-
@key = @key.gsub /^property:/, "" # If added via property helper
|
6
|
-
end
|
7
|
-
|
8
3
|
def to_html
|
9
4
|
Array(value).compact.map { |value| tag(:meta, property: key, content: value) }.join("\n").html_safe.presence
|
10
5
|
end
|
data/lib/metamagic/version.rb
CHANGED
data/lib/metamagic.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class CustomTagTest < ActionView::TestCase
|
4
|
+
include Metamagic::ViewHelper
|
5
|
+
|
6
|
+
test "custom tags" do
|
7
|
+
Metamagic::Renderer.register_tag_type :custom, ->(key, value) { tag(:custom_tag, one: key, two: value) }
|
8
|
+
|
9
|
+
meta title: "Test Title",
|
10
|
+
custom: {
|
11
|
+
first: "This is the first",
|
12
|
+
second: "This is the second"
|
13
|
+
}
|
14
|
+
|
15
|
+
assert_equal %{<title>Test Title</title>\n<custom_tag one="custom:first" two="This is the first" />\n<custom_tag one="custom:second" two="This is the second" />},
|
16
|
+
metamagic
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LinkTagTest < ActionView::TestCase
|
4
|
+
include Metamagic::ViewHelper
|
5
|
+
|
6
|
+
test "link rel" do
|
7
|
+
meta rel: {
|
8
|
+
author: "http://test.com/author.html",
|
9
|
+
}
|
10
|
+
rel publisher: "http://test.com/publisher.html"
|
11
|
+
|
12
|
+
assert_equal %{<link href="http://test.com/author.html" rel="author" />\n<link href="http://test.com/publisher.html" rel="publisher" />},
|
13
|
+
metamagic
|
14
|
+
end
|
15
|
+
|
16
|
+
test "canonical shortcut helper" do
|
17
|
+
canonical "http://test.com/page.html"
|
18
|
+
|
19
|
+
assert_equal %{<link href="http://test.com/page.html" rel="canonical" />},
|
20
|
+
metamagic
|
21
|
+
end
|
22
|
+
end
|
data/test/meta_tag_test.rb
CHANGED
@@ -3,6 +3,22 @@ require 'test_helper'
|
|
3
3
|
class MetaTagTest < ActionView::TestCase
|
4
4
|
include Metamagic::ViewHelper
|
5
5
|
|
6
|
+
test "meta tags" do
|
7
|
+
meta keywords: %w{one two three},
|
8
|
+
description: "My description"
|
9
|
+
|
10
|
+
assert_equal %{<meta content="one, two, three" name="keywords" />\n<meta content="My description" name="description" />},
|
11
|
+
metamagic
|
12
|
+
end
|
13
|
+
|
14
|
+
test "shortcut helpers" do
|
15
|
+
keywords %w{one two three}
|
16
|
+
description "My description"
|
17
|
+
|
18
|
+
assert_equal %{<meta content="one, two, three" name="keywords" />\n<meta content="My description" name="description" />},
|
19
|
+
metamagic
|
20
|
+
end
|
21
|
+
|
6
22
|
test "nil meta value" do
|
7
23
|
title "Test Title"
|
8
24
|
description nil
|
data/test/metamagic_test.rb
CHANGED
@@ -31,16 +31,14 @@ class MetamagicTest < ActionView::TestCase
|
|
31
31
|
metamagic
|
32
32
|
end
|
33
33
|
|
34
|
-
test "
|
35
|
-
Metamagic::Renderer.register_tag_type :custom, ->(key, value) { tag(:custom_tag, one: key, two: value) }
|
36
|
-
|
34
|
+
test "not adding existing meta tags by shortcut helpers" do
|
37
35
|
meta title: "Test Title",
|
38
|
-
|
39
|
-
first: "This is the first",
|
40
|
-
second: "This is the second"
|
41
|
-
}
|
36
|
+
description: "Test description."
|
42
37
|
|
43
|
-
|
38
|
+
title "Second Title"
|
39
|
+
description "Second description."
|
40
|
+
|
41
|
+
assert_equal %{<title>Test Title</title>\n<meta content="Test description." name="description" />},
|
44
42
|
metamagic
|
45
43
|
end
|
46
44
|
|
@@ -48,20 +46,8 @@ class MetamagicTest < ActionView::TestCase
|
|
48
46
|
title "My Title"
|
49
47
|
description "My description"
|
50
48
|
keywords %w{one two three}
|
51
|
-
og image: "http://test.com/img.jpg"
|
52
|
-
twitter card: :summary, site: "@flickr"
|
53
|
-
meta bla: "Test"
|
54
|
-
|
55
|
-
assert_equal %{<title>My Title</title>\n<meta content="My description" name="description" />\n<meta content="one, two, three" name="keywords" />\n<meta content="Test" name="bla" />\n<meta content="summary" property="twitter:card" />\n<meta content="@flickr" property="twitter:site" />\n<meta content="http://test.com/img.jpg" property="og:image" />},
|
56
|
-
metamagic
|
57
|
-
end
|
58
|
-
|
59
|
-
test "property helper" do
|
60
|
-
meta property: { one: "Property One", two: "Property Two", "og:image" => "http://test.com/image.png", nested: { a: "Nested A" } }
|
61
|
-
property two: "Property Two second", three: "Property Three", nested: { a: "Nested A second", b: "Nested B" }
|
62
|
-
og title: "My Title", image: "http://test.com/image2.png"
|
63
49
|
|
64
|
-
assert_equal %{<
|
50
|
+
assert_equal %{<title>My Title</title>\n<meta content="My description" name="description" />\n<meta content="one, two, three" name="keywords" />},
|
65
51
|
metamagic
|
66
52
|
end
|
67
53
|
|
data/test/open_graph_test.rb
CHANGED
@@ -7,10 +7,10 @@ class OpenGraphTest < ActionView::TestCase
|
|
7
7
|
meta title: "Test Title",
|
8
8
|
og: {
|
9
9
|
image: {
|
10
|
-
url: "http://test.com/image.jpg"
|
11
|
-
type: "image/png"
|
10
|
+
url: "http://test.com/image.jpg"
|
12
11
|
}
|
13
12
|
}
|
13
|
+
og image: { type: "image/png" }
|
14
14
|
|
15
15
|
assert_equal %{<title>Test Title</title>\n<meta content="http://test.com/image.jpg" property="og:image:url" />\n<meta content="image/png" property="og:image:type" />},
|
16
16
|
metamagic
|
data/test/property_tag_test.rb
CHANGED
@@ -3,6 +3,14 @@ require 'test_helper'
|
|
3
3
|
class PropertyTagTest < ActionView::TestCase
|
4
4
|
include Metamagic::ViewHelper
|
5
5
|
|
6
|
+
test "property tags" do
|
7
|
+
meta property: { one: "Property One", two: "Property Two", "og:image" => "http://test.com/image.png", nested: { a: "Nested A" } }
|
8
|
+
property two: "Property Two second", three: "Property Three", nested: { a: "Nested A second", b: "Nested B" }
|
9
|
+
|
10
|
+
assert_equal %{<meta content="Property One" property="one" />\n<meta content="Property Two" property="two" />\n<meta content="http://test.com/image.png" property="og:image" />\n<meta content="Nested A" property="nested:a" />\n<meta content="Property Three" property="three" />\n<meta content="Nested B" property="nested:b" />},
|
11
|
+
metamagic
|
12
|
+
end
|
13
|
+
|
6
14
|
test "property array" do
|
7
15
|
og image: ["one.jpg", "two.jpg"]
|
8
16
|
|
data/test/title_tag_test.rb
CHANGED
@@ -3,6 +3,20 @@ require 'test_helper'
|
|
3
3
|
class TitleTagTest < ActionView::TestCase
|
4
4
|
include Metamagic::ViewHelper
|
5
5
|
|
6
|
+
test "title tag" do
|
7
|
+
meta title: "My Title"
|
8
|
+
|
9
|
+
assert_equal %{<title>My Title</title>},
|
10
|
+
metamagic
|
11
|
+
end
|
12
|
+
|
13
|
+
test "shortcut helper" do
|
14
|
+
title "My Title"
|
15
|
+
|
16
|
+
assert_equal %{<title>My Title</title>},
|
17
|
+
metamagic
|
18
|
+
end
|
19
|
+
|
6
20
|
test "nil title" do
|
7
21
|
title nil
|
8
22
|
description "Test description"
|
@@ -3,12 +3,13 @@ require 'test_helper'
|
|
3
3
|
class TwitterTest < ActionView::TestCase
|
4
4
|
include Metamagic::ViewHelper
|
5
5
|
|
6
|
-
test "twitter
|
6
|
+
test "twitter tag" do
|
7
7
|
meta title: "Test Title",
|
8
8
|
twitter: {
|
9
9
|
card: :summary,
|
10
|
-
site: "@flickr"
|
11
10
|
}
|
11
|
+
twitter site: "@flickr"
|
12
|
+
|
12
13
|
|
13
14
|
assert_equal %{<title>Test Title</title>\n<meta content="summary" property="twitter:card" />\n<meta content="@flickr" property="twitter:site" />},
|
14
15
|
metamagic
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metamagic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lasse Bunk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sqlite3
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: Metamagic is a simple Ruby on Rails plugin for creating meta tags.
|
@@ -45,8 +45,8 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
- .gitignore
|
49
|
-
- .travis.yml
|
48
|
+
- ".gitignore"
|
49
|
+
- ".travis.yml"
|
50
50
|
- CHANGELOG.md
|
51
51
|
- Gemfile
|
52
52
|
- LICENSE.txt
|
@@ -56,12 +56,16 @@ files:
|
|
56
56
|
- lib/metamagic/renderer.rb
|
57
57
|
- lib/metamagic/tag.rb
|
58
58
|
- lib/metamagic/tags/custom_tag.rb
|
59
|
+
- lib/metamagic/tags/link_tag.rb
|
59
60
|
- lib/metamagic/tags/meta_tag.rb
|
61
|
+
- lib/metamagic/tags/open_graph_tag.rb
|
60
62
|
- lib/metamagic/tags/property_tag.rb
|
61
63
|
- lib/metamagic/tags/title_tag.rb
|
64
|
+
- lib/metamagic/tags/twitter_tag.rb
|
62
65
|
- lib/metamagic/version.rb
|
63
66
|
- lib/metamagic/view_helper.rb
|
64
67
|
- metamagic.gemspec
|
68
|
+
- test/custom_tag_test.rb
|
65
69
|
- test/dummy/README.rdoc
|
66
70
|
- test/dummy/Rakefile
|
67
71
|
- test/dummy/app/assets/images/.keep
|
@@ -102,13 +106,14 @@ files:
|
|
102
106
|
- test/dummy/public/500.html
|
103
107
|
- test/dummy/public/favicon.ico
|
104
108
|
- test/legacy_test.rb
|
109
|
+
- test/link_tag_test.rb
|
105
110
|
- test/meta_tag_test.rb
|
106
111
|
- test/metamagic_test.rb
|
107
112
|
- test/open_graph_test.rb
|
108
113
|
- test/property_tag_test.rb
|
109
114
|
- test/test_helper.rb
|
110
115
|
- test/title_tag_test.rb
|
111
|
-
- test/
|
116
|
+
- test/twitter_tag_test.rb
|
112
117
|
homepage: http://github.com/lassebunk/metamagic
|
113
118
|
licenses:
|
114
119
|
- MIT
|
@@ -119,21 +124,22 @@ require_paths:
|
|
119
124
|
- lib
|
120
125
|
required_ruby_version: !ruby/object:Gem::Requirement
|
121
126
|
requirements:
|
122
|
-
- -
|
127
|
+
- - ">="
|
123
128
|
- !ruby/object:Gem::Version
|
124
129
|
version: '0'
|
125
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
131
|
requirements:
|
127
|
-
- -
|
132
|
+
- - ">="
|
128
133
|
- !ruby/object:Gem::Version
|
129
134
|
version: '0'
|
130
135
|
requirements: []
|
131
136
|
rubyforge_project:
|
132
|
-
rubygems_version: 2.1
|
137
|
+
rubygems_version: 2.2.1
|
133
138
|
signing_key:
|
134
139
|
specification_version: 4
|
135
140
|
summary: Simple Ruby on Rails plugin for creating meta tags.
|
136
141
|
test_files:
|
142
|
+
- test/custom_tag_test.rb
|
137
143
|
- test/dummy/README.rdoc
|
138
144
|
- test/dummy/Rakefile
|
139
145
|
- test/dummy/app/assets/images/.keep
|
@@ -174,10 +180,11 @@ test_files:
|
|
174
180
|
- test/dummy/public/500.html
|
175
181
|
- test/dummy/public/favicon.ico
|
176
182
|
- test/legacy_test.rb
|
183
|
+
- test/link_tag_test.rb
|
177
184
|
- test/meta_tag_test.rb
|
178
185
|
- test/metamagic_test.rb
|
179
186
|
- test/open_graph_test.rb
|
180
187
|
- test/property_tag_test.rb
|
181
188
|
- test/test_helper.rb
|
182
189
|
- test/title_tag_test.rb
|
183
|
-
- test/
|
190
|
+
- test/twitter_tag_test.rb
|