metamagic 3.1.4 → 3.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0bd1c5cb5eaeec1a81f04a1351ffa0d4ebcb6bda
4
- data.tar.gz: aeb4fd251d0f1a35d2fb671f646786e1e16723cd
3
+ metadata.gz: 1ad1cfb51aa95e26223fc02287031c0e05541514
4
+ data.tar.gz: 290dc71df03bd998dad9bd0fc5c1af19e6722b9b
5
5
  SHA512:
6
- metadata.gz: 5d26a67f84c95eab8de16287d5c5cb4140109b390ac238f862e8b8a709d58e6745e210c912be710634db2b1d6eb13a617bbfe0bad44aab601c95a43955d3bb64
7
- data.tar.gz: e075cf385f3da913b9d7ff8e775d1c4633f02cfa7dbfbd717c50e4943632bf85bd8873fc5d7017e4ca9c1f9fb2997ff4299c71af3c5ea910807f135671de9494
6
+ metadata.gz: 2cac024a9c26e40f864b03b2fcfa3c5e6dea7b92e82a17321e4b2d50fb5f48cb13fe0fa4a0d755f55906fd893fb6ad1e93af1907b6a87da9ba9472c0c0c8070a
7
+ data.tar.gz: c8c70d7029d85fd580c0d8d0ffa4f61b287a54b2a9961ccf8c11f6c456ecf1a1a8ee2faca1c5f61e4b9f9ce76269ca0a7b81dba28134f3243a7ce941843f9f45
@@ -1,8 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 3.1.5
4
+
5
+ * Adds support for duplicating tags, e.g. setting `twitter:image` to the value of `og:image`.
6
+
3
7
  ## Version 3.1.4
4
8
 
5
- * Fixes a bug where symbol-like strings inside meta tags would raise an exception
9
+ * Fixes a bug where symbol-like strings inside meta tags would raise an exception.
6
10
 
7
11
  ## Version 3.1.3
8
12
 
data/README.md CHANGED
@@ -162,6 +162,34 @@ Templates are supported on all tag types. You can access the values set in the
162
162
  view by replacing colons (`:`) in your meta keys with underscores (`_`), so for
163
163
  example `og:image` can be accessed with `og_image`.
164
164
 
165
+ ### Duplicating tags
166
+
167
+ Sometimes you want tags to be the same for e.g. Twitter and Facebook (OpenGraph).
168
+ To circumvent the need to duplicate these tags every time you write them in your code, you can let Metamagic do this for you.
169
+
170
+ Given that you want to add the same tags for Twitter as you have for Facebook, you can do this, in your view:
171
+
172
+ ```erb
173
+ <%
174
+ og title: "My Title",
175
+ image: "http://test.com/image.jpg",
176
+ description: "My description."
177
+ %>
178
+ ```
179
+
180
+ And in your layout:
181
+
182
+ ```erb
183
+ <%= metamagic twitter: {
184
+ card: "summary",
185
+ title: :og_title,
186
+ image: :og_image,
187
+ description: :og_description
188
+ }
189
+ ```
190
+
191
+ Now you only need to set OpenGraph data and these will be copied to Twitter.
192
+
165
193
  ### Shortcut helpers
166
194
 
167
195
  For easy setting of meta tags, you can use the shortcut helpers like this:
@@ -69,7 +69,7 @@ module Metamagic
69
69
  end
70
70
 
71
71
  def has_tag_type?(prefix)
72
- self.class.tag_types.has_key?(prefix)
72
+ self.class.tag_types.has_key?(prefix.to_sym)
73
73
  end
74
74
 
75
75
  def title_template
@@ -94,8 +94,12 @@ module Metamagic
94
94
  tags.sort.map(&:to_html).compact.join("\n").html_safe
95
95
  end
96
96
 
97
- def method_missing(*args)
98
- context.send(*args)
97
+ def method_missing(method, *args, &block)
98
+ if method.to_s =~ /^([^_]+)/ && has_tag_type?($1) # Adds support for calling e.g. `og_image`
99
+ tags.find { |t| t.key == method.to_s.gsub("_", ":") }.try(:interpolated_values)
100
+ else
101
+ context.send(method, *args, &block)
102
+ end
99
103
  end
100
104
 
101
105
  private
@@ -1,3 +1,3 @@
1
1
  module Metamagic
2
- VERSION = "3.1.4"
2
+ VERSION = "3.1.5"
3
3
  end
@@ -23,8 +23,12 @@ module Metamagic
23
23
 
24
24
  def method_missing(method, *args, &block)
25
25
  if metamagic_renderer.has_tag_type?(method)
26
- args.first.tap do |value|
26
+ if args.length > 0
27
+ value = args.first
27
28
  meta method => value
29
+ value
30
+ else
31
+ metamagic_renderer.send method
28
32
  end
29
33
  else
30
34
  super
@@ -82,4 +82,12 @@ class MetamagicTest < ActionView::TestCase
82
82
  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" />},
83
83
  metamagic
84
84
  end
85
+
86
+ test "duplicating tags" do
87
+ og image: "http://test.com/image.png",
88
+ description: "My description."
89
+
90
+ assert_equal %{<meta content="http://test.com/image.png" property="og:image" />\n<meta content="http://test.com/default.png" property="og:image" />\n<meta content="My description." property="og:description" />\n<meta content="http://test.com/image.png" property="twitter:image" />\n<meta content="http://test.com/default.png" property="twitter:image" />\n<meta content="summary" property="twitter:card" />\n<meta content="My description." property="twitter:description" />},
91
+ metamagic(og: { image: [:value, "http://test.com/default.png"] }, twitter: { card: "summary", image: :og_image, description: :og_description, other: :og_nonexisting })
92
+ end
85
93
  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.1.4
4
+ version: 3.1.5
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-08-07 00:00:00.000000000 Z
11
+ date: 2014-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails