[![Build Status](https://secure.travis-ci.org/lassebunk/metamagic.png)](http://travis-ci.org/lassebunk/metamagic)
Metamagic
=========
Metamagic is a simple [Ruby on Rails](http://rubyonrails.org) plugin for creating meta tags.
It supports regular meta tags, [OpenGraph](http://ogp.me/) (Facebook), [Twitter Cards](https://dev.twitter.com/docs/cards/types/summary-card), and custom tags.
See the [changelog](https://github.com/lassebunk/metamagic/blob/master/CHANGELOG.md) for changes in version 3.0.
Installation
------------
In your *Gemfile*:
```ruby
gem 'metamagic', '3.0.0.beta1'
```
Then run `bundle install`.
Examples
--------
### Basic usage
In your *app/views/layouts/application.html.erb*:
```erb
<%= metamagic %>
...
```
Then, at the top of your view, e.g. *app/views/posts/show.html.erb*:
```erb
<%
meta title: "My Title",
description: "My description",
keywords: %w(keyword1 keyword2 keyword3)
%>
```
This will generate the following:
```html
My Title
...
```
### Specifying default meta tag values
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*:
```erb
<%= metamagic title: "My default title", description: "My default description.", keywords: %w(keyword1 keyword2 keyword3) %>
...
```
These values are then inserted if a view doesn't set others.
### Custom meta tags
For custom meta tags, you can use it like this:
```erb
<%
meta my_custom_name: "My custom value"
%>
```
This will generate the following:
```html
...
...
```
### Custom properties
#### OpenGraph (Facebook)
```erb
<%
meta og: {
image: "http://mydomain.com/images/my_image.jpg"
}
%>
```
This will generate the following:
```html
...
...
```
#### Twitter Cards
```erb
<%
meta twitter: {
card: "summary",
site: "@flickr"
}
%>
```
This will generate the following:
```html
...
...
```
### Custom tags
You can add custom rendering for tag prefixes you specify.
In *config/initializers/metamagic.rb*:
```ruby
Metamagic::Renderer.register_tag_type :custom, ->(key, value) { tag(:custom_tag, first: key, second: value) }
```
In your view:
```erb
<%
meta title: "My Title",
custom: {
key_one: "My first key",
key_two: "My second key"
}
%>
```
This will render the following:
```html
My Title
```
Requirements
------------
* Rails 3.0 or above
* Ruby 1.9 or above
Versioning
----------
Follows [semantic versioning](http://semver.org/).
Contributing
------------
1. Fork the project
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Make your changes and make sure the tests pass (run `rake`)
4. Commit your changes (`git commit -am 'Add new feature'`)
5. Push to the branch (`git push origin my-new-feature`)
6. Create new pull request
Contributors
------------
* [See the list of contributors](https://github.com/lassebunk/metamagic/graphs/contributors)
Copyright (c) 2010-2014 [Lasse Bunk](http://lassebunk.dk), released under the MIT license