No commit activity in last 3 years
No release in over 3 years
DataMapper plugin that generates unique permalinks / slugs
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.8.2

Runtime

~> 0.9
 Project Readme

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

Finding objects by slug¶ ↑

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