GithubHelp home page GithubHelp logo

estum / seorel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dalpo/seorel

0.0 2.0 0.0 167 KB

Ruby on Rails SEO Metatags engine for ActiveRecord models

License: MIT License

Ruby 95.58% JavaScript 2.39% CSS 2.03%

seorel's Introduction

Seorel

Ruby on Rails SEO Metatags plugins for ActiveRecord models

Gem Version Code Climate

Rails Setup

Gemfile.rb:

gem 'seorel', '~> 0.0.3'

# the edge version can be had using:
# gem 'seorel', github: 'dalpo/seorel'

Console:

% bundle install
% bundle exec rake seorel:install:migrations
% bundle exec rake db:migrate

Default configuration options

% rails generate seorel:config

Will generate the seorel_config.rb initializer to customize the default values:

Seorel.configure do |config|
  # config.default_title = nil
  # config.default_description = nil
  # config.default_image = nil
  # config.prepend_title = nil
  # config.append_title  = nil
  # config.store_seorel_if = :empty # Available values :empty | :changed
end

Usage

Model

For instance generate a post model:

rails generate model post title:string description:text, publish_date:date

Edit app/models/post.rb:

class Post < ActiveRecord::Base

  extend Seorelify
  seorelify title: :customized_title, description: :description

  def customized_title
    "THE BLOG: #{self.title}"
  end

end

This will use the customized_title and the description methods as references to generate automatically the related metatags. Note that the title and description will be sanitized from HTML and truncated to 255 characters.

Controllers

In your controllers you may add_metatags either like a before_filter or within a method.

class PostsController < ApplicationController

  def index
    ###
    # Custom meta tags
    add_metatags({
      title: 'My custom meta title',
      description: 'My custom meta description'
    })

    ...
  end

  def show
    @post = Post.find(params[:id])
    ###
    # Extract meta tags info from your Seorelified Model
    add_metatags(@post)

    ...
  end

  def history
    ...
  end
end

In case of missing add_metatags for controller actions, you can define metatags through rails L10n library by defining your locale strings for seorel.

For instance seorel.en.yml:

# encoding: utf-8
en:
  seorel:
    posts:
      history:
        title: "Posts history metatitle"
        description: "Posts history metadescriprion"

    tags:
      index:
        title: "Tag list"
        description: "Tag list metadescription"

Where posts and tags are controller names, while history and index are their actions.

Views

In your layout <head></head> section just call the render_meta_tags helper:

<%=render_meta_tags %>

Contributing

Submitting a Pull Request:

  1. Fork the repository.
  2. Create a topic branch.
  3. Implement your feature or bug fix.
  4. Add, commit, and push your changes.
  5. Submit a pull request.

This project rocks and uses MIT-LICENSE.

Copyright 2013 Andrea Dal Ponte

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

seorel's People

Contributors

dalpo avatar estum avatar

Watchers

James Cloos avatar  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.