Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
makes permalinks easy for datamapper objects
Ruby
Branch: master
Pull request Compare This branch is 3 commits ahead, 20 commits behind aq1018:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib Recalc slug on scope change
spec Updated dependencies to use DataMapper 1.2.0
tasks DM 1.0
.gitignore Updated gitignore files.
Gemfile
LICENSE added my name in Licence, changed specs, now 100% rcov
README.rdoc Scoped slugs
Rakefile Scoped slugs
TODO
VERSION
dm-is-slug.gemspec Updated dependencies to use DataMapper 1.2.0

README.rdoc

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
Something went wrong with that request. Please try again.