Skip to content

Commit 83b9255

Browse files
author
Lasse Bunk
committed
Merge branch '3.0.0'
2 parents 3a6c657 + ad3e765 commit 83b9255

File tree

15 files changed

+442
-87
lines changed

15 files changed

+442
-87
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: ruby
22
rvm:
3+
- 2.1.0
34
- 2.0.0
45
- 1.9.3
56
notifications:

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Changelog
2+
3+
## Version 3.0.0
4+
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.
7+
* Add shortcut helpers for easy setting of meta tags.

README.md

Lines changed: 170 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
[![Build Status](https://secure.travis-ci.org/lassebunk/metamagic.png)](http://travis-ci.org/lassebunk/metamagic)
22

3+
![Meta Magic Motherfuckers](http://i.imgur.com/4KtY4qX.png)
4+
35
Metamagic
46
=========
57

68
Metamagic is a simple [Ruby on Rails](http://rubyonrails.org) plugin for creating meta tags.
9+
It supports regular meta tags, [OpenGraph](http://ogp.me/) (Facebook), [Twitter Cards](https://dev.twitter.com/docs/cards/types/summary-card), and custom tags.
10+
11+
See the [changelog](https://github.com/lassebunk/metamagic/blob/master/CHANGELOG.md) for changes in version 3.0.
712

813
Installation
914
------------
1015

1116
In your *Gemfile*:
1217

1318
```ruby
14-
gem 'metamagic'
19+
gem 'metamagic', '3.0.0.beta2'
1520
```
1621

1722
Then run `bundle install`.
@@ -34,30 +39,55 @@ Then, at the top of your view, e.g. *app/views/posts/show.html.erb*:
3439

3540
```erb
3641
<%
37-
meta :title => "My title",
38-
:description => "My description",
39-
:keywords => %w(keyword1 keyword2 keyword3)
42+
meta title: "My Title",
43+
description: "My description",
44+
keywords: %w(keyword1 keyword2 keyword3)
4045
%>
4146
```
4247

4348
This will generate the following:
4449

4550
```html
4651
<head>
47-
<title>My title</title>
52+
<title>My Title</title>
4853
<meta content="My description" name="description" />
4954
<meta content="keyword1, keyword2, keyword3" name="keywords" />
5055
...
5156
</head>
5257
```
5358

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+
5484
### Specifying default meta tag values
5585

5686
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*:
5787

5888
```erb
5989
<head>
60-
<%= metamagic :title => "My default title", :description => "My default description.", :keywords => %w(keyword1 keyword2 keyword3) %>
90+
<%= metamagic title: "My default title", description: "My default description.", keywords: %w(keyword1 keyword2 keyword3) %>
6191
...
6292
</head>
6393
```
@@ -66,11 +96,11 @@ These values are then inserted if a view doesn't set others.
6696

6797
### Custom meta tags
6898

69-
For custom meta tags, just call it like this in the top of your view:
99+
For custom meta tags, you can use it like this:
70100

71101
```erb
72102
<%
73-
meta :my_custom_tag => "My custom value"
103+
meta my_custom_name: "My custom value"
74104
%>
75105
```
76106

@@ -79,18 +109,20 @@ This will generate the following:
79109
```html
80110
<head>
81111
...
82-
<meta content="My custom value" name="my_custom_tag" />
112+
<meta content="My custom value" name="my_custom_name" />
83113
...
84114
</head>
85115
```
86116

87-
### Custom properties (like Open Graph)
117+
### Custom properties
88118

89-
With custom properties:
119+
#### OpenGraph (Facebook)
90120

91121
```erb
92122
<%
93-
meta [:property => "og:image", :content => "http://mydomain.com/images/my_image.jpg"]
123+
meta og: {
124+
image: "http://mydomain.com/images/my_image.jpg"
125+
}
94126
%>
95127
```
96128

@@ -104,6 +136,127 @@ This will generate the following:
104136
</head>
105137
```
106138

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+
147+
#### Twitter Cards
148+
149+
```erb
150+
<%
151+
meta twitter: {
152+
card: "summary",
153+
site: "@flickr"
154+
}
155+
%>
156+
```
157+
158+
This will generate the following:
159+
160+
```html
161+
<head>
162+
...
163+
<meta content="summary" property="twitter:card" />
164+
<meta content="@flickr" property="twitter:site" />
165+
...
166+
</head>
167+
```
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+
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+
221+
### Custom tags
222+
223+
You can add custom rendering for tag prefixes you specify.
224+
225+
In *config/initializers/metamagic.rb*:
226+
227+
```ruby
228+
Metamagic::Renderer.register_tag_type :custom, ->(key, value) { tag(:custom_tag, first: key, second: value) }
229+
```
230+
231+
In your view:
232+
233+
```erb
234+
<%
235+
meta title: "My Title",
236+
custom: {
237+
key_one: "My first key",
238+
key_two: "My second key"
239+
}
240+
%>
241+
```
242+
243+
This will render the following:
244+
245+
```html
246+
<title>My Title</title>
247+
<custom_tag first="custom:key_one" second="My first key" />
248+
<custom_tag first="custom:key_two" second="My second key" />
249+
```
250+
251+
When you register a new tag type, a shortcut helper is automatically defined. The above could therefore also be written as:
252+
253+
```erb
254+
<%
255+
custom key_one: "My first key",
256+
key_two: "My second key"
257+
%>
258+
```
259+
107260
Requirements
108261
------------
109262

@@ -120,14 +273,14 @@ Contributing
120273

121274
1. Fork the project
122275
2. Create your feature branch (`git checkout -b my-new-feature`)
123-
3. Commit your changes (`git commit -am 'Add new feature'`)
124-
4. Push to the branch (`git push origin my-new-feature`)
125-
5. Create new pull r
126-
equest
276+
3. Make your changes and make sure the tests pass (run `rake`)
277+
4. Commit your changes (`git commit -am 'Add new feature'`)
278+
5. Push to the branch (`git push origin my-new-feature`)
279+
6. Create new pull request
127280

128281
Contributors
129282
------------
130283

131284
* [See the list of contributors](https://github.com/lassebunk/metamagic/graphs/contributors)
132285

133-
Copyright (c) 2010-2013 [Lasse Bunk](http://lassebunk.dk), released under the MIT license
286+
Copyright (c) 2010-2014 [Lasse Bunk](http://lassebunk.dk), released under the MIT license

lib/metamagic.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
require "metamagic/version"
2-
require 'metamagic/helper_methods'
1+
%w{
2+
version
3+
tag
4+
tags/meta_tag
5+
tags/title_tag
6+
tags/property_tag
7+
tags/custom_tag
8+
renderer
9+
view_helper
10+
}.each { |f| require "metamagic/#{f}" }
311

4-
ActionView::Base.send :include, Metamagic::HelperMethods
12+
ActionView::Base.send :include, Metamagic::ViewHelper

lib/metamagic/helper_methods.rb

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)