metamagic 3.0.0.beta1 → 3.0.0.beta2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db6ed555cf9378801321e62f86e74a5bd55924a6
4
- data.tar.gz: 5f77f984c6dc4edbc9ccc9a3f846caeaab8f1f08
3
+ metadata.gz: 342a5ebb2b3d5ff1fe29e205d95701adeebd3d02
4
+ data.tar.gz: cf7883c37ea41aff399936e83c21f54269f8902f
5
5
  SHA512:
6
- metadata.gz: dcd1a96e0f49eed0ea2809cd593a5ffe59228dd71c24cdf5f967a0d7770acf5a14a3dc1faaf42a46c5824ceff5656128766fa49c2475c51679845b84846751d7
7
- data.tar.gz: 85928f766fca9e6e661130a83045036d9958d892e52d4993017e845e83f95e0d351eb8e835f68cf3af74e360770dfc14fb1e2f30324fbf088bdaa264344d56fc
6
+ metadata.gz: 7bd3ccb3fcccf427ccf315538abd1e0cb2828859d132c25f1ae4c865e9e5ac5c7eb4b660588472d80f1cba4e9bfc5d00ab7af0184c0037b4b15f036709cead98
7
+ data.tar.gz: 99ad11931155753db54a95b219049a401dd050ca07e014e3937550dceeed31145a0f720861c9f0785f7f3b9a268aeb7d606e31405b79f49af42863ef65308596
data/CHANGELOG.md CHANGED
@@ -3,4 +3,5 @@
3
3
  ## Version 3.0.0
4
4
 
5
5
  * Rewritten to simplify Open Graph (Facebook), Twitter Cards, and custom tags.
6
- Some features are incompatible with 2.x but are easy to rewrite.
6
+ Some features are incompatible with 2.x but are easy to rewrite.
7
+ * Add shortcut helpers for easy setting of meta tags.
data/README.md CHANGED
@@ -1,5 +1,7 @@
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/lwYIfEG.png)
4
+
3
5
  Metamagic
4
6
  =========
5
7
 
@@ -54,6 +56,31 @@ This will generate the following:
54
56
  </head>
55
57
  ```
56
58
 
59
+ ### Shortcut helpers
60
+
61
+ For easy setting of meta tags, you can use the shortcut helpers like this:
62
+
63
+ ```erb
64
+ <%
65
+ title "My Title"
66
+ description "My description"
67
+ keywords %w(keyword1 keyword2 keyword3)
68
+ %>
69
+ ```
70
+
71
+ This will generate the following:
72
+
73
+ ```html
74
+ <head>
75
+ <title>My Title</title>
76
+ <meta content="My description" name="description" />
77
+ <meta content="keyword1, keyword2, keyword3" name="keywords" />
78
+ ...
79
+ </head>
80
+ ```
81
+
82
+ **Note:** Shortcut helpers will never override methods already present in the view context, so for example if you have a method named `title`, this will not be overridden.
83
+
57
84
  ### Specifying default meta tag values
58
85
 
59
86
  It's possible to specify default values to be shown if a view doesn't specify its own values. In your *app/views/layouts/application.html.erb*:
@@ -109,6 +136,14 @@ This will generate the following:
109
136
  </head>
110
137
  ```
111
138
 
139
+ The above can also be written with the shortcut helper:
140
+
141
+ ```erb
142
+ <%
143
+ og image: "http://mydomain.com/images/my_image.jpg"
144
+ %>
145
+ ```
146
+
112
147
  #### Twitter Cards
113
148
 
114
149
  ```erb
@@ -131,6 +166,15 @@ This will generate the following:
131
166
  </head>
132
167
  ```
133
168
 
169
+ The above can also be written with the shortcut helper:
170
+
171
+ ```erb
172
+ <%
173
+ twitter card: "summary",
174
+ site: "@flickr"
175
+ %>
176
+ ```
177
+
134
178
  ### Custom tags
135
179
 
136
180
  You can add custom rendering for tag prefixes you specify.
data/lib/metamagic.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  tags/property_tag
7
7
  tags/custom_tag
8
8
  renderer
9
- helper_methods
9
+ view_helper
10
10
  }.each { |f| require "metamagic/#{f}" }
11
11
 
12
- ActionView::Base.send :include, Metamagic::HelperMethods
12
+ ActionView::Base.send :include, Metamagic::ViewHelper
@@ -1,9 +1,11 @@
1
1
  module Metamagic
2
2
  class Renderer
3
3
  DEFAULT_TAG_TYPES = {
4
- title: TitleTag,
5
- og: PropertyTag,
6
- twitter: PropertyTag
4
+ title: TitleTag,
5
+ description: MetaTag,
6
+ keywords: MetaTag,
7
+ og: PropertyTag,
8
+ twitter: PropertyTag
7
9
  }
8
10
 
9
11
  class << self
@@ -43,6 +45,10 @@ module Metamagic
43
45
  end
44
46
  end
45
47
 
48
+ def has_tag_type?(prefix)
49
+ self.class.tag_types.has_key?(prefix)
50
+ end
51
+
46
52
  def render
47
53
  tags.map(&:to_html).join("\n").html_safe
48
54
  end
@@ -1,3 +1,3 @@
1
1
  module Metamagic
2
- VERSION = "3.0.0.beta1"
2
+ VERSION = "3.0.0.beta2"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  module Metamagic
2
- module HelperMethods
2
+ module ViewHelper
3
3
  def meta(hash = {})
4
4
  metamagic_renderer.add hash
5
5
  end
@@ -9,6 +9,14 @@ module Metamagic
9
9
  metamagic_renderer.render
10
10
  end
11
11
 
12
+ def method_missing(method, *args, &block)
13
+ if metamagic_renderer.has_tag_type?(method)
14
+ meta method => args.first
15
+ else
16
+ super
17
+ end
18
+ end
19
+
12
20
  private
13
21
 
14
22
  def metamagic_renderer
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class HelperMethodsTest < ActionView::TestCase
4
- include Metamagic::HelperMethods
4
+ include Metamagic::ViewHelper
5
5
 
6
6
  test "meta tags generation" do
7
7
  meta title: "My Title",
@@ -67,4 +67,16 @@ class HelperMethodsTest < ActionView::TestCase
67
67
  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" />},
68
68
  metamagic
69
69
  end
70
+
71
+ test "shortcut helpers" do
72
+ title "My Title"
73
+ description "My description"
74
+ keywords %w{one two three}
75
+ og image: "http://test.com/img.jpg"
76
+ twitter card: :summary, site: "@flickr"
77
+ meta bla: "Test"
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="http://test.com/img.jpg" property="og:image" />\n<meta content="summary" property="twitter:card" />\n<meta content="@flickr" property="twitter:site" />\n<meta content="Test" name="bla" />},
80
+ metamagic
81
+ end
70
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metamagic
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.beta1
4
+ version: 3.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lasse Bunk
@@ -53,7 +53,6 @@ files:
53
53
  - README.md
54
54
  - Rakefile
55
55
  - lib/metamagic.rb
56
- - lib/metamagic/helper_methods.rb
57
56
  - lib/metamagic/renderer.rb
58
57
  - lib/metamagic/tag.rb
59
58
  - lib/metamagic/tags/custom_tag.rb
@@ -61,6 +60,7 @@ files:
61
60
  - lib/metamagic/tags/property_tag.rb
62
61
  - lib/metamagic/tags/title_tag.rb
63
62
  - lib/metamagic/version.rb
63
+ - lib/metamagic/view_helper.rb
64
64
  - metamagic.gemspec
65
65
  - test/dummy/README.rdoc
66
66
  - test/dummy/Rakefile