Skip to content

Simple Ruby on Rails plugin for creating meta tags.

License

Notifications You must be signed in to change notification settings

copass/metamagic

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Metamagic

Metamagic is a simple Ruby on Rails plugin for creating meta tags.

Installation

In your Gemfile:

gem 'metamagic'

Then run bundle install.

Examples

Basic usage

In your app/views/layouts/application.html.erb:

<head>
  <%= metamagic %>
  ...
</head>

Then, at the top of your view, e.g. app/views/posts/show.html.erb:

<%
meta :title => "My title",
     :description => "My description",
     :keywords => %w(keyword1 keyword2 keyword3)
%>

This will generate the following:

<head>
  <title>My title</title>
  <meta content="My description" name="description" />
  <meta content="keyword1, keyword2, keyword3" name="keywords" />
  ...
</head>

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:

<head>
  <%= metamagic :title => "My default title", :description => "My default description.", :keywords => %w(keyword1 keyword2 keyword3) %>
  ...
</head>

These values are then inserted if a view doesn't set others.

Specifying default meta tag values inserted into page specific values

It is possible to add the [defaults] keyword in a meta helper that will include the default value set in metamagic helper if exists.

<%
meta :title => "My page title - [defaults]",
     :description => "My page description - [defaults]",
     :keywords => %w(my page keywords [defaults])
%>

and

<head>
  <%= metamagic :title => "My app title", :description => "My app description", :keywords => %w(my app keywords) %>
  ...
</head>

This will generate the following:

<head>
  <title>My page title - My app title</title>
  <meta content="My page description - My app description" name="description" />
  <meta content="my, page, keywords, my, app, keywords" name="keywords" />
  ...
</head>

Custom meta tags

For custom meta tags, just call it like this in the top of your view:

<%
meta :my_custom_tag => "My custom value"
%>

This will generate the following:

<head>
  ...
  <meta content="My custom value" name="my_custom_tag" />
  ...
</head>

Custom properties (like Open Graph)

With custom properties:

<%
meta [:property => "og:image", :content => "http://mydomain.com/images/my_image.jpg"]
%>

This will generate the following:

<head>
  ...
  <meta content="http://mydomain.com/images/my_image.jpg" property="og:image" />
  ...
</head>

Requirements

  • Rails 3.0 or above
  • Ruby 1.9 or above

Versioning

Follows semantic versioning.

Contributing

  1. Fork the project
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add new feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new pull r equest

Contributors

Copyright (c) 2010-2013 Lasse Bunk, released under the MIT license

About

Simple Ruby on Rails plugin for creating meta tags.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 94.5%
  • JavaScript 2.9%
  • CSS 2.6%