pretty_param 1.0.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/.DS_Store +0 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +13 -0
- data/Rakefile +2 -0
- data/lib/pretty_param.rb +26 -0
- data/lib/pretty_param/version.rb +3 -0
- data/pretty_param.gemspec +19 -0
- data/spec/pretty_param_spec.rb +5 -0
- metadata +66 -0
data/.DS_Store
ADDED
Binary file
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Kyle Meyer
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Pretty Param
|
2
|
+
============
|
3
|
+
|
4
|
+
Easily make your resource-based routes more search engine friendly.
|
5
|
+
|
6
|
+
Usage
|
7
|
+
-----
|
8
|
+
|
9
|
+
class Person < ActiveRecord::Base
|
10
|
+
has_pretty_param :first_name, :last_name
|
11
|
+
end
|
12
|
+
|
13
|
+
# => "http://localhost:3000/people/1-ronald-mcdonald"
|
data/Rakefile
ADDED
data/lib/pretty_param.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module PrettyParam
|
2
|
+
class << self
|
3
|
+
# This method does the actual permalink escaping.
|
4
|
+
def escape(string)
|
5
|
+
result = string
|
6
|
+
result.gsub!(/[^\x00-\x7F]+/, '') # Remove anything non-ASCII entirely (e.g. diacritics).
|
7
|
+
result.gsub!(/[^\w_ \-]+/i, '') # Remove unwanted chars.
|
8
|
+
result.gsub!(/[ \-]+/i, '-') # No more than one of the separator in a row.
|
9
|
+
result.gsub!(/^\-|\-$/i, '') # Remove leading/trailing separator.
|
10
|
+
result.downcase
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
# Takes 1 or more symbols and stores them in class.pretty_params,
|
16
|
+
# and then overrides to_param
|
17
|
+
def has_pretty_param(*fields)
|
18
|
+
define_singleton_method :pretty_params, -> { fields }
|
19
|
+
define_method :to_param do
|
20
|
+
PrettyParam.escape("#{self.id}-#{self.class.pretty_params.map{|a| self.send(a.to_sym) }.join('-')}")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
ActiveRecord::Base.extend PrettyParam::ClassMethods
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/pretty_param/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Kyle Meyer"]
|
6
|
+
gem.email = ["kaiuhl@kittelson.com"]
|
7
|
+
gem.description = %q{Search-engine friendly URLs for your models}
|
8
|
+
gem.summary = %q{Search-engine friendly URLs for your models}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "pretty_param"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = PrettyParam::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency "rspec"
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pretty_param
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kyle Meyer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70345306791800 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70345306791800
|
25
|
+
description: Search-engine friendly URLs for your models
|
26
|
+
email:
|
27
|
+
- kaiuhl@kittelson.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .DS_Store
|
33
|
+
- Gemfile
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- lib/pretty_param.rb
|
38
|
+
- lib/pretty_param/version.rb
|
39
|
+
- pretty_param.gemspec
|
40
|
+
- spec/pretty_param_spec.rb
|
41
|
+
homepage: ''
|
42
|
+
licenses: []
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.8.17
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: Search-engine friendly URLs for your models
|
65
|
+
test_files:
|
66
|
+
- spec/pretty_param_spec.rb
|