doesprettyurls 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +13 -0
- data/Gemfile.lock +16 -0
- data/README.rdoc +51 -0
- data/Rakefile +40 -0
- data/VERSION +1 -0
- data/doesprettyurls.gemspec +48 -0
- data/lib/doesprettyurls.rb +61 -0
- metadata +86 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
= DoesPrettyURLs
|
2
|
+
|
3
|
+
Uses ActiveRecord to_param to force your individual models to have attractive, slug-like, and more
|
4
|
+
SEO-friendly URLs.
|
5
|
+
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
Do the usual, of course:
|
10
|
+
|
11
|
+
gem install doesprettyurls
|
12
|
+
|
13
|
+
And add a gem dependency to your Gemfile:
|
14
|
+
|
15
|
+
gem "doesprettyurls", ">=0.1.0"
|
16
|
+
|
17
|
+
|
18
|
+
== Example Usage
|
19
|
+
|
20
|
+
To add pretty URL support for objects of a given model, declare your desire for fanciness within the
|
21
|
+
ActiveRecord model:
|
22
|
+
|
23
|
+
doesprettyurls
|
24
|
+
|
25
|
+
This will, by default, surgically attach a "slug"-ified version of your object's :name attribute to the
|
26
|
+
objects id in URLs and for finders. This means where you used to have this:
|
27
|
+
|
28
|
+
# tag = <Tag @id=5, @name="Beer and Brats", @title="Something Really Cool"...>
|
29
|
+
http://myrailsproject.com/tags/5
|
30
|
+
|
31
|
+
You would now have something a bit fancier and search engine friendly like this:
|
32
|
+
|
33
|
+
http://myrailsproject.com/tags/5-beer-and-brats
|
34
|
+
|
35
|
+
You can tell the doesprettyurls invocation to use a different field for slugification, too. Just pass it
|
36
|
+
along in your method call:
|
37
|
+
|
38
|
+
doesprettyurls :attribute=>:title
|
39
|
+
|
40
|
+
For the same object object, you'd now see this URL used in your site:
|
41
|
+
|
42
|
+
http://myrailsproject.com/tags/5-something-really-cool
|
43
|
+
|
44
|
+
Voila! Se Magnifique!
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
== Copyright
|
49
|
+
|
50
|
+
Copyright (c) 2011 Awexome Labs, LLC. http://awexomelabs.com/
|
51
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# AWEXOME LABS
|
2
|
+
# Rakefile
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'bundler'
|
6
|
+
begin
|
7
|
+
Bundler.setup(:default, :development)
|
8
|
+
rescue Bundler::BundlerError => e
|
9
|
+
$stderr.puts e.message
|
10
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
11
|
+
exit e.status_code
|
12
|
+
end
|
13
|
+
require 'rake'
|
14
|
+
|
15
|
+
require 'jeweler'
|
16
|
+
Jeweler::Tasks.new do |gem|
|
17
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
18
|
+
gem.name = "doesprettyurls"
|
19
|
+
gem.homepage = "http://github.com/awexome/doesprettyvalues"
|
20
|
+
gem.license = "MIT"
|
21
|
+
gem.summary = %Q{Uses ActiveRecord to_param to force your individual models to have attractive and more SEO-friendly URLs}
|
22
|
+
gem.description = %Q{Uses ActiveRecord to_param to force your individual models to have attractive and more SEO-friendly URLs}
|
23
|
+
gem.email = "gems@awexomelabs.com"
|
24
|
+
gem.authors = ["Awexome Labs"]
|
25
|
+
|
26
|
+
# Internal Gem Dependencies:
|
27
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
28
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
29
|
+
end
|
30
|
+
Jeweler::RubygemsDotOrgTasks.new
|
31
|
+
|
32
|
+
require 'rake/rdoctask'
|
33
|
+
Rake::RDocTask.new do |rdoc|
|
34
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
35
|
+
|
36
|
+
rdoc.rdoc_dir = 'rdoc'
|
37
|
+
rdoc.title = "doesprettyurls #{version}"
|
38
|
+
rdoc.rdoc_files.include('README*')
|
39
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
40
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{doesprettyurls}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Awexome Labs"]
|
12
|
+
s.date = %q{2011-02-17}
|
13
|
+
s.description = %q{Uses ActiveRecord to_param to force your individual models to have attractive and more SEO-friendly URLs}
|
14
|
+
s.email = %q{gems@awexomelabs.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"Gemfile",
|
20
|
+
"Gemfile.lock",
|
21
|
+
"README.rdoc",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"doesprettyurls.gemspec",
|
25
|
+
"lib/doesprettyurls.rb"
|
26
|
+
]
|
27
|
+
s.homepage = %q{http://github.com/awexome/doesprettyvalues}
|
28
|
+
s.licenses = ["MIT"]
|
29
|
+
s.require_paths = ["lib"]
|
30
|
+
s.rubygems_version = %q{1.5.2}
|
31
|
+
s.summary = %q{Uses ActiveRecord to_param to force your individual models to have attractive and more SEO-friendly URLs}
|
32
|
+
|
33
|
+
if s.respond_to? :specification_version then
|
34
|
+
s.specification_version = 3
|
35
|
+
|
36
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
37
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
38
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
39
|
+
else
|
40
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
41
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
42
|
+
end
|
43
|
+
else
|
44
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
45
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# AWEXOME LABS
|
2
|
+
# DoesPrettyUrls
|
3
|
+
|
4
|
+
require 'doesprettyurls'
|
5
|
+
require 'rails'
|
6
|
+
require 'active_record'
|
7
|
+
|
8
|
+
|
9
|
+
module DoesPrettyUrls
|
10
|
+
|
11
|
+
# Create a Rails Engine
|
12
|
+
class Engine < Rails::Engine
|
13
|
+
end
|
14
|
+
|
15
|
+
# Return the current working version from VERSION file:
|
16
|
+
def self.version
|
17
|
+
@@version ||= File.open(File.join(File.dirname(__FILE__), "..", "VERSION"), "r").read
|
18
|
+
end
|
19
|
+
|
20
|
+
end # DoesPrettyUrls
|
21
|
+
|
22
|
+
|
23
|
+
module ActiveRecord
|
24
|
+
class Base
|
25
|
+
|
26
|
+
# Call this method within your class to get fancy URLs
|
27
|
+
def self.doesprettyurls(opts={})
|
28
|
+
self.instance_eval do
|
29
|
+
cattr_accessor :pretty_param_attribute
|
30
|
+
cattr_accessor :pretty_param_proc
|
31
|
+
cattr_accessor :pretty_param_reverse_proc
|
32
|
+
|
33
|
+
# Typical use case is to send a column/attribute name:
|
34
|
+
@@pretty_param_attribute = opts[:attribute] || :name
|
35
|
+
|
36
|
+
# A Proc may also be sent for realtime URL beautification:
|
37
|
+
if opts[:proc]
|
38
|
+
@@pretty_param_proc = opts[:proc]
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Provide a mechanism to automagically "slugify" URL parameters
|
45
|
+
def to_param
|
46
|
+
slug_source = if pretty_param_proc
|
47
|
+
pretty_param_proc.call(self)
|
48
|
+
else
|
49
|
+
self.send(pretty_param_attribute)
|
50
|
+
end
|
51
|
+
"#{id}-#{slug_source.downcase.gsub("'", "").gsub(/[^a-z1-9]+/i, "-")}"
|
52
|
+
end
|
53
|
+
|
54
|
+
# We need to help ActiveRecord go back the other way:
|
55
|
+
def self.from_param(param)
|
56
|
+
find(param.to_i)
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
end # ActiveRecord::Base
|
61
|
+
end # ActiveRecord
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: doesprettyurls
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Awexome Labs
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-02-17 00:00:00 -05:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: bundler
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.0
|
24
|
+
type: :development
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jeweler
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.5.2
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
description: Uses ActiveRecord to_param to force your individual models to have attractive and more SEO-friendly URLs
|
39
|
+
email: gems@awexomelabs.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- README.rdoc
|
46
|
+
files:
|
47
|
+
- Gemfile
|
48
|
+
- Gemfile.lock
|
49
|
+
- README.rdoc
|
50
|
+
- Rakefile
|
51
|
+
- VERSION
|
52
|
+
- doesprettyurls.gemspec
|
53
|
+
- lib/doesprettyurls.rb
|
54
|
+
has_rdoc: true
|
55
|
+
homepage: http://github.com/awexome/doesprettyvalues
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3285598090168023541
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.5.2
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Uses ActiveRecord to_param to force your individual models to have attractive and more SEO-friendly URLs
|
85
|
+
test_files: []
|
86
|
+
|