Giter VIP home page Giter VIP logo

dm-is-slug's Introduction

dm-is-slug

DataMapper plugin for creating and slugs(permalinks).

Installation

> gem install dm-is-slug

Usage

Creating a slug from property

class Post
  include DataMapper::Resource

  property :id, Serial
  property :title, String
  property :content, String

  # here we define that it should have a slug that uses title as the permalink
  # it will generate an extra slug property of String type, with the same size as title
  is :slug, :source => :title
end

Creating a slug from arbitrary methods

class User
  include DataMapper::Resource

  property :id, Serial
  property :email, String
  property :password, String

  # we only want to strip out the domain name
  # and use only the email account name as the permalink
  def slug_for_email
    email.split("@").first
  end

  # here we define that it should have a slug that uses title as the permalink
  # it will generate an extra slug property of String type, with the same size as title
  is :slug, :source => :slug_for_email, :size => 255
end

Scoped slugs

class Post
  include DataMapper::Resource

  property :id, Serial
  property :title, String
  property :content, String
  property :category, String

  # Same as above but slugs will be unique only within their category.
  is :slug, :source => :title, :slug => :category
end

Finding objects by slug

post = Post.first(:slug => "your_slug")

Development

It’s recommended to use bundler in development.

gem install bundler
ADAPTERS='in_memory yaml sqlite postgres mysql' bundle install --without quality

This will install all dependencies so that you could run specs.

bundle exec rake spec ADAPTER=sqlite

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.