mirror of
https://github.com/danbee/slugtastic
synced 2025-03-04 08:49:05 +00:00
Initial commit.
This commit is contained in:
commit
faca6e4309
14
Rakefile
Normal file
14
Rakefile
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
require 'rubygems'
|
||||||
|
require 'rake'
|
||||||
|
require 'echoe'
|
||||||
|
|
||||||
|
Echoe.new('slugtastic', '0.1.0') do |p|
|
||||||
|
p.description = "Generate a slug string from another field."
|
||||||
|
p.url = "http://github.com/danbee/slugtastic"
|
||||||
|
p.author = "Dan Barber"
|
||||||
|
p.email = "danbee@gmail.com"
|
||||||
|
p.ignore_pattern = ["tmp/*", "script/*"]
|
||||||
|
p.development_dependencies = []
|
||||||
|
end
|
||||||
|
|
||||||
|
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
||||||
23
lib/slugtastic.rb
Normal file
23
lib/slugtastic.rb
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
module Slugtastic
|
||||||
|
def self.included(base)
|
||||||
|
base.extend ClassMethods
|
||||||
|
end
|
||||||
|
|
||||||
|
def generate_slug(string)
|
||||||
|
string.downcase.gsub(/ /, '_').gsub(/[^a-z0-9\-_]/, '')
|
||||||
|
end
|
||||||
|
|
||||||
|
module ClassMethods
|
||||||
|
|
||||||
|
def has_slug(name, options = { :from => :title })
|
||||||
|
before_validation do |record|
|
||||||
|
self[name] = generate_slug(self[options[:from]]) if self[name].nil? or self[name].empty?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class ActiveRecord::Base
|
||||||
|
include Slugtastic
|
||||||
|
end
|
||||||
29
slugtastic.gemspec
Normal file
29
slugtastic.gemspec
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
|
Gem::Specification.new do |s|
|
||||||
|
s.name = %q{slugtastic}
|
||||||
|
s.version = "0.1.0"
|
||||||
|
|
||||||
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
||||||
|
s.authors = [%q{Dan Barber}]
|
||||||
|
s.date = %q{2011-10-04}
|
||||||
|
s.description = %q{Generate a slug string from another field.}
|
||||||
|
s.email = %q{danbee@gmail.com}
|
||||||
|
s.extra_rdoc_files = [%q{README.md}, %q{lib/slugtastic.rb}]
|
||||||
|
s.files = [%q{README.md}, %q{Rakefile}, %q{lib/slugtastic.rb}, %q{Manifest}, %q{slugtastic.gemspec}]
|
||||||
|
s.homepage = %q{http://github.com/danbee/slugtastic}
|
||||||
|
s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Slugtastic}, %q{--main}, %q{README.md}]
|
||||||
|
s.require_paths = [%q{lib}]
|
||||||
|
s.rubyforge_project = %q{slugtastic}
|
||||||
|
s.rubygems_version = %q{1.8.6}
|
||||||
|
s.summary = %q{Generate a slug string from another field.}
|
||||||
|
|
||||||
|
if s.respond_to? :specification_version then
|
||||||
|
s.specification_version = 3
|
||||||
|
|
||||||
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
||||||
|
else
|
||||||
|
end
|
||||||
|
else
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in New Issue
Block a user