GithubHelp home page GithubHelp logo

ktopping / metamagic Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lassebunk/metamagic

0.0 1.0 0.0 126 KB

Simple Ruby on Rails plugin for creating meta tags.

License: MIT License

Ruby 93.92% JavaScript 3.18% CSS 2.90%

metamagic's Introduction

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.

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

metamagic's People

Contributors

lassebunk avatar ktopping avatar ptcodes avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.