aq1018 / dm-is-slug

makes permalinks easy for datamapper objects

This URL has Read+Write access

name age message
file .gitignore Wed Dec 24 17:48:37 -0800 2008 Add a gitignore file [jherdman]
file History.txt Thu Aug 28 21:47:23 -0700 2008 first commit [aq1018]
file LICENSE Sun Jan 11 23:40:12 -0800 2009 added my name in Licence, changed specs, now 10... [aq1018]
file Manifest.txt Thu Aug 28 21:47:23 -0700 2008 first commit [aq1018]
file README.txt Fri Nov 14 05:45:39 -0800 2008 Updated README.txt [Nik Radford]
file Rakefile Mon Jan 12 00:14:46 -0800 2009 modified gemspec to proper versioning added todo [aq1018]
file TODO Mon Jan 12 00:14:46 -0800 2009 modified gemspec to proper versioning added todo [aq1018]
file dm-is-slug.gemspec Mon Jan 12 00:14:46 -0800 2009 modified gemspec to proper versioning added todo [aq1018]
directory lib/ Mon Jan 12 02:54:55 -0800 2009 made it shorter [aq1018]
directory spec/ Mon Jan 12 02:54:55 -0800 2009 made it shorter [aq1018]
directory tasks/ Sun Jan 11 19:24:37 -0800 2009 merged [paul]
README.txt
= dm-is-slug

DataMapper plugin for creating and slugs(permalinks).

== Installation

NOTE: You no longer need to download dm-more source code in order to install
this.

All you need to do is:

$ sudo rake install

Remember to require it in your app's init.rb

dependency 'dm-is-slug'

== Getting started

Lets say we have a post-class, and we want to generate permalinks or slugs for all posts.

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

Let's Say we need to define a permalink based on a method instead of a property.

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

You can now find objects by slug like this:

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