metamagic 3.0.0.beta2 → 3.0.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +45 -2
- data/lib/metamagic/renderer.rb +4 -3
- data/lib/metamagic/tag.rb +12 -0
- data/lib/metamagic/tags/meta_tag.rb +4 -0
- data/lib/metamagic/tags/property_tag.rb +9 -0
- data/lib/metamagic/tags/title_tag.rb +4 -0
- data/lib/metamagic/version.rb +1 -1
- data/test/metamagic_test.rb +21 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7768fc3e2aa2de60d8bfc92153d5d7fb4c1bf866
|
4
|
+
data.tar.gz: bec05d33cae27e0e3fb2f8cd9a7b144b4133fbcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 350d4181da76a6eb163a68709c95d555cedd6b44d772140cf9b538b342d4a3dd66657739f48df88011df6f7d132ef670649a54ad5fe4f9a7172605b10cb6a210
|
7
|
+
data.tar.gz: de4ca669406cd60f156a17e669ec4aff3a1b673ebefa65fed909c92fd783211169cc45e3aab46893670edd0ec5f0067f8606d95dff60b3857a9b4879b8dd9a6b
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
[![Build Status](https://secure.travis-ci.org/lassebunk/metamagic.png)](http://travis-ci.org/lassebunk/metamagic)
|
2
2
|
|
3
|
-
![Meta Magic Motherfuckers](http://i.imgur.com/
|
3
|
+
![Meta Magic Motherfuckers](http://i.imgur.com/4KtY4qX.png)
|
4
4
|
|
5
5
|
Metamagic
|
6
6
|
=========
|
@@ -16,7 +16,7 @@ Installation
|
|
16
16
|
In your *Gemfile*:
|
17
17
|
|
18
18
|
```ruby
|
19
|
-
gem 'metamagic', '3.0.0.
|
19
|
+
gem 'metamagic', '3.0.0.beta2'
|
20
20
|
```
|
21
21
|
|
22
22
|
Then run `bundle install`.
|
@@ -175,6 +175,49 @@ twitter card: "summary",
|
|
175
175
|
%>
|
176
176
|
```
|
177
177
|
|
178
|
+
#### Other custom properties
|
179
|
+
|
180
|
+
You can add custom properties like this:
|
181
|
+
|
182
|
+
```erb
|
183
|
+
<%
|
184
|
+
meta property: {
|
185
|
+
one: "Property One",
|
186
|
+
two: "Property Two",
|
187
|
+
nested: {
|
188
|
+
a: "Nested A",
|
189
|
+
b: "Nested B"
|
190
|
+
}
|
191
|
+
}
|
192
|
+
%>
|
193
|
+
```
|
194
|
+
|
195
|
+
This will generate the following:
|
196
|
+
|
197
|
+
```html
|
198
|
+
<head>
|
199
|
+
...
|
200
|
+
<meta content="Property One" property="one" />
|
201
|
+
<meta content="Property Two" property="two" />
|
202
|
+
<meta content="Nested A" property="nested:a" />
|
203
|
+
<meta content="Nested B" property="nested:b" />
|
204
|
+
...
|
205
|
+
</head>
|
206
|
+
```
|
207
|
+
|
208
|
+
The above could also be written with the `property` shortcut helper:
|
209
|
+
|
210
|
+
```erb
|
211
|
+
<%
|
212
|
+
property one: "Property One",
|
213
|
+
two: "Property Two",
|
214
|
+
nested: {
|
215
|
+
a: "Nested A",
|
216
|
+
b: "Nested B"
|
217
|
+
}
|
218
|
+
%>
|
219
|
+
```
|
220
|
+
|
178
221
|
### Custom tags
|
179
222
|
|
180
223
|
You can add custom rendering for tag prefixes you specify.
|
data/lib/metamagic/renderer.rb
CHANGED
@@ -4,6 +4,7 @@ module Metamagic
|
|
4
4
|
title: TitleTag,
|
5
5
|
description: MetaTag,
|
6
6
|
keywords: MetaTag,
|
7
|
+
property: PropertyTag,
|
7
8
|
og: PropertyTag,
|
8
9
|
twitter: PropertyTag
|
9
10
|
}
|
@@ -36,12 +37,12 @@ module Metamagic
|
|
36
37
|
def add(hash = {})
|
37
38
|
transform_hash(hash).each do |k, v|
|
38
39
|
klass = self.class.tag_type_for_key(k)
|
39
|
-
|
40
|
-
tags << if klass.is_a?(Proc)
|
40
|
+
tag = if klass.is_a?(Proc)
|
41
41
|
CustomTag.new(self, k, v, klass)
|
42
42
|
else
|
43
43
|
klass.new(self, k, v)
|
44
44
|
end
|
45
|
+
tags << tag unless tags.include?(tag)
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
@@ -50,7 +51,7 @@ module Metamagic
|
|
50
51
|
end
|
51
52
|
|
52
53
|
def render
|
53
|
-
tags.map(&:to_html).join("\n").html_safe
|
54
|
+
tags.sort.map(&:to_html).join("\n").html_safe
|
54
55
|
end
|
55
56
|
|
56
57
|
def method_missing(*args)
|
data/lib/metamagic/tag.rb
CHANGED
@@ -10,6 +10,18 @@ module Metamagic
|
|
10
10
|
raise "#{self.class.name}#to_html must be overridden to render tag"
|
11
11
|
end
|
12
12
|
|
13
|
+
def sort_order
|
14
|
+
1000
|
15
|
+
end
|
16
|
+
|
17
|
+
def ==(other)
|
18
|
+
self.class == other.class && self.key == other.key
|
19
|
+
end
|
20
|
+
|
21
|
+
def <=>(other)
|
22
|
+
[sort_order, self.class.name] <=> [other.sort_order, other.class.name]
|
23
|
+
end
|
24
|
+
|
13
25
|
def method_missing(*args)
|
14
26
|
context.send(*args)
|
15
27
|
end
|
@@ -1,7 +1,16 @@
|
|
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
|
+
|
3
8
|
def to_html
|
4
9
|
Array(value).map { |value| tag(:meta, property: key, content: value) }.join("\n").html_safe
|
5
10
|
end
|
11
|
+
|
12
|
+
def sort_order
|
13
|
+
3
|
14
|
+
end
|
6
15
|
end
|
7
16
|
end
|
data/lib/metamagic/version.rb
CHANGED
data/test/metamagic_test.rb
CHANGED
@@ -76,7 +76,27 @@ class HelperMethodsTest < ActionView::TestCase
|
|
76
76
|
twitter card: :summary, site: "@flickr"
|
77
77
|
meta bla: "Test"
|
78
78
|
|
79
|
-
assert_equal %{<title>My Title</title>\n<meta content="My description" name="description" />\n<meta content="one, two, three" name="keywords" />\n<meta content="
|
79
|
+
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" />},
|
80
|
+
metamagic
|
81
|
+
end
|
82
|
+
|
83
|
+
test "property helper" do
|
84
|
+
meta property: { one: "Property One", two: "Property Two", "og:image" => "http://test.com/image.png", nested: { a: "Nested A" } }
|
85
|
+
property two: "Property Two second", three: "Property Three", nested: { a: "Nested A second", b: "Nested B" }
|
86
|
+
og title: "My Title", image: "http://test.com/image2.png"
|
87
|
+
|
88
|
+
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" />\n<meta content="My Title" property="og:title" />},
|
89
|
+
metamagic
|
90
|
+
end
|
91
|
+
|
92
|
+
test "sorting tags" do
|
93
|
+
twitter card: :summary
|
94
|
+
og image: "http://test.com/image.png"
|
95
|
+
description "My description."
|
96
|
+
keywords %w{one two three}
|
97
|
+
title "My Title"
|
98
|
+
|
99
|
+
assert_equal %{<title>My Title</title>\n<meta content="one, two, three" name="keywords" />\n<meta content="My description." name="description" />\n<meta content="http://test.com/image.png" property="og:image" />\n<meta content="summary" property="twitter:card" />},
|
80
100
|
metamagic
|
81
101
|
end
|
82
102
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metamagic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.
|
4
|
+
version: 3.0.0.beta3
|
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-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|