MetaTagsSimpleBuilder

Gem allow you to simply create seo friendly custom meta tags, blocks of meta tags.

Dependency

rails >= 4.0.0

Installation

Add this line to your application's Gemfile:

gem 'meta_tags_simple_builder'

And then execute:

$ bundle

Or install it yourself as:

$ gem install meta_tags_simple_builder

Title

<%= title_meta_tag('MetaTagsSimpleBuilder gem page.')%>
# <title>MetaTagsSimpleBuilder gem page.</title>

Use title for layout helper if you want to set title for application from view and caption view name:

# application.html

<%= title_meta_tag(yield(:title))%>
# <title>Title for application from view.html</title>

# views.html

<h1>
  <%= title_for_layout('Title for application from view.html')%>
</h1>
# <h1>Title for application from view.html</h1>

Charset

<%= charset_meta_tag('utf-16')%>
# <meta charset="utf-16" />

Http equiv data

<%= http_equiv_meta_tag('X-UA-Compatible', 'IE=Edge')%>
# <meta http-equiv="X-UA-Compatible" content="IE=Edge" />

Author

<%= author_meta_tag('Marat Khusnetdinov')%>
# <meta content="Marat Khusnetdinov" name="author" />

Keywords

<%= keywords_meta_tag(['gem', 'rails'])%>
<%= keywords_meta_tag('gem, rails')%>
# <meta content="gem, rails" name="keywords" />

Description

<%= description_meta_tag('Gem for simply creating meta tags, blocks of meta tags')%>
# <meta content="Gem for simply creating meta tags, blocks of meta tags" name="description" />')

Viewport

<%= viewport_meta_tag('width=1')
# <meta content="width=1" name="viewport" />'

<%= viewport_meta_tag(['width=1', 'scale=1'])
# <meta content="width=1, scale=1" name="viewport" />'

Customs meta tag, robots, nofollow examples

This helper helps you to set meta tag with custom name:

<%= meta_tag_for :robots, 'noindex'>
# <meta content="noindex" name="robots" />

Use custom meta tags if you want more flexibility:

<%= custom_meta_tag_for(:custom_property, 'cutstom content', custom_options: 'custom content for options')%>
# <meta custom-property="cutstom content" custom-options="custom content for options" />

Notice: "_" underscore in attributes simbol names will be rendered to "-" dash

<%= link_tag_for :canonical, url: 'http://github.com', type: 'web')%>
# <link rel="canonical" url="http://github.com" type="web" />')

Blocks helpers are used than you need render collection meta tags. It takes a hash, which you can create in controller.rb:

# somewhere in controller we create and want to render this:
@meta = { title: 'Page title', charset: 'utf-16', author: 'John Doe', namespace: { title: 'content', attr_name: :property} }

# application.html

<%= meta_tags_block_for(@meta)%>
# <title>Page title</title>
# <meta charset="utf-16" />
# <meta content="John Doe" name="author" />
# <meta content="content" property="namespace:title" />

Notice: If you pass a pair key: :value with value as hash, key: will be the namespace of name attribute. For change 'name' attribute pass options :attr_name.

Links block have options:

@links = { prev: { href: 'http://github.com/prev', type: 'web' }, next: { href: 'http://github.com/next'} }

<%= link_tags_block_for(@links)%>
# <link href="http://github.com/prev" rel="prev" type="web" />
# <link href="http://github.com/next" rel="next" />

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request