friendly_id 2.0.4 → 2.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.tar.gz.sig +2 -1
- data/History.txt +6 -0
- data/README.rdoc +2 -19
- data/Rakefile +1 -1
- data/friendly_id.gemspec +5 -6
- data/lib/friendly_id.rb +12 -0
- data/lib/friendly_id/slug.rb +36 -15
- data/lib/friendly_id/version.rb +2 -2
- data/test/slug_test.rb +2 -2
- data/test/sti_test.rb +4 -4
- data/test/test_helper.rb +4 -1
- metadata +5 -5
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
��D��u�#&��;\��/�����P�P�vd����N���e��;gVk���9���0>�\�R��k�Z����tk���b����;.^Ň>d��]d�q%<Wc߽�-�xE��$]Dd���>��Rhx� P�=!�HWip7NO\�{4,��X'�XTV��!]�u�
|
2
|
+
�[�HFɗ#�i_�F* gqyĪ��8���v�ʽ�M�zٹlD�?�W��p����-��F�/�4�tٚd��6�do�§�2����]
|
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -219,30 +219,19 @@ While FriendlyId's slug generation options work for most people, you may need
|
|
219
219
|
something else. As of version 2.0.4 you can pass in your own custom slug
|
220
220
|
generation block:
|
221
221
|
|
222
|
-
require 'stringex'
|
223
222
|
class Post < ActiveRecord::Base
|
224
223
|
has_friendly_id :title, :use_slug => true do |text|
|
225
|
-
|
226
|
-
text.to_url
|
224
|
+
MySlugGeneratorClass::my_slug_method(text)
|
227
225
|
end
|
228
226
|
end
|
229
227
|
|
230
|
-
...
|
231
|
-
|
232
|
-
@post = Post.create(:title => "tell your readers 你好")
|
233
|
-
@post.friendly_id # "tell-your-readers-ni-hao"
|
234
|
-
|
235
228
|
FriendlyId will still respect your settings for max length and reserved words,
|
236
229
|
but will use your block rather than the baked-in methods to normalize the
|
237
230
|
friendly_id text.
|
238
231
|
|
239
|
-
(As an aside, the stringex[http://github.com/rsl/stringex/tree/master] library
|
240
|
-
provides some very cool slugging functionality and is a great option for
|
241
|
-
apps using FriendlyId in either English or Chinese. Definitely check it out.)
|
242
|
-
|
243
232
|
== Getting it
|
244
233
|
|
245
|
-
FriendlyId is installed as a Ruby Gem:
|
234
|
+
FriendlyId is best installed as a Ruby Gem:
|
246
235
|
|
247
236
|
gem install friendly_id
|
248
237
|
|
@@ -251,12 +240,6 @@ discouraged:
|
|
251
240
|
|
252
241
|
./script/plugin install git://github.com/norman/friendly_id.git
|
253
242
|
|
254
|
-
If you are installing as a plugin, make sure you have installed the unicode gem,
|
255
|
-
which FriendlyId depends on:
|
256
|
-
|
257
|
-
gem install unicode
|
258
|
-
|
259
|
-
|
260
243
|
== Setting it up
|
261
244
|
|
262
245
|
FriendlyId currently works with Rails 2.0.0 - 2.3.0. Here's how to set it up.
|
data/Rakefile
CHANGED
@@ -9,8 +9,8 @@ $hoe = Hoe.new("friendly_id", FriendlyId::Version::STRING) do |p|
|
|
9
9
|
p.description = 'A comprehensive slugging and pretty-URL plugin for ActiveRecord.'
|
10
10
|
p.url = 'http://friendly-id.rubyforge.org/'
|
11
11
|
p.test_globs = ['test/**/*_test.rb']
|
12
|
-
p.extra_deps << ['unicode', '>= 0.1']
|
13
12
|
p.extra_deps << ['activerecord', '>= 2.0.0']
|
13
|
+
p.extra_deps << ['activesupport', '>= 2.0.0']
|
14
14
|
p.extra_dev_deps << ['newgem', ">= #{::Newgem::VERSION}"]
|
15
15
|
p.extra_dev_deps << ['Shoulda', ">= 1.2.0"]
|
16
16
|
p.extra_dev_deps << ['sqlite3-ruby']
|
data/friendly_id.gemspec
CHANGED
@@ -2,11 +2,10 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{friendly_id}
|
5
|
-
s.version = "2.0
|
6
|
-
|
5
|
+
s.version = "2.1.0"
|
7
6
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
7
|
s.authors = ["Norman Clarke", "Adrian Mugnolo", "Emilio Tagua"]
|
9
|
-
s.date = %q{2009-
|
8
|
+
s.date = %q{2009-03-25}
|
10
9
|
s.description = %q{A comprehensive slugging and pretty-URL plugin for ActiveRecord.}
|
11
10
|
s.email = ["norman@randomba.org", "adrian@randomba.org", "miloops@gmail.com"]
|
12
11
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
|
@@ -25,23 +24,23 @@ Gem::Specification.new do |s|
|
|
25
24
|
s.specification_version = 2
|
26
25
|
|
27
26
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
-
s.add_runtime_dependency(%q<unicode>, [">= 0.1"])
|
29
27
|
s.add_runtime_dependency(%q<activerecord>, [">= 2.0.0"])
|
28
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 2.0.0"])
|
30
29
|
s.add_development_dependency(%q<newgem>, [">= 1.2.3"])
|
31
30
|
s.add_development_dependency(%q<Shoulda>, [">= 1.2.0"])
|
32
31
|
s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
|
33
32
|
s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
|
34
33
|
else
|
35
|
-
s.add_dependency(%q<unicode>, [">= 0.1"])
|
36
34
|
s.add_dependency(%q<activerecord>, [">= 2.0.0"])
|
35
|
+
s.add_dependency(%q<activesupport>, [">= 2.0.0"])
|
37
36
|
s.add_dependency(%q<newgem>, [">= 1.2.3"])
|
38
37
|
s.add_dependency(%q<Shoulda>, [">= 1.2.0"])
|
39
38
|
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
40
39
|
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
41
40
|
end
|
42
41
|
else
|
43
|
-
s.add_dependency(%q<unicode>, [">= 0.1"])
|
44
42
|
s.add_dependency(%q<activerecord>, [">= 2.0.0"])
|
43
|
+
s.add_dependency(%q<activesupport>, [">= 2.0.0"])
|
45
44
|
s.add_dependency(%q<newgem>, [">= 1.2.3"])
|
46
45
|
s.add_dependency(%q<Shoulda>, [">= 1.2.0"])
|
47
46
|
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
data/lib/friendly_id.rb
CHANGED
@@ -42,6 +42,18 @@ module FriendlyId
|
|
42
42
|
# * <tt>:strip_non_ascii</tt> - Defaults to false. If true, it will all non-ascii ([^a-z0-9]) characters.
|
43
43
|
# * <tt>:reserved</tt> - Array of words that are reserved and can't be used as friendly_id's. For sluggable models, if such a word is used, it will be treated the same as if that slug was already taken (numeric extension will be appended). Defaults to ["new", "index"].
|
44
44
|
# * <tt>:reserved_message</tt> - The validation message that will be shown when a reserved word is used as a frindly_id. Defaults to '"%s" is reserved'.
|
45
|
+
#
|
46
|
+
# You can also optionally pass a block if you want to use your own custom
|
47
|
+
# slugnormalization routines rather than the default ones that come with
|
48
|
+
# friendly_id:
|
49
|
+
#
|
50
|
+
# require 'stringex'
|
51
|
+
# class Post < ActiveRecord::Base
|
52
|
+
# has_friendly_id :title, :use_slug => true do |text|
|
53
|
+
# # Use stringex to generate the friendly_id rather than the baked-in methods
|
54
|
+
# text.to_url
|
55
|
+
# end
|
56
|
+
# end
|
45
57
|
def has_friendly_id(column, options = {}, &block)
|
46
58
|
options.assert_valid_keys VALID_FRIENDLY_ID_KEYS
|
47
59
|
options = DEFAULT_FRIENDLY_ID_OPTIONS.merge(options).merge(:column => column)
|
data/lib/friendly_id/slug.rb
CHANGED
@@ -1,9 +1,23 @@
|
|
1
|
-
|
1
|
+
#encoding: utf-8
|
2
|
+
|
2
3
|
# A Slug is a unique, human-friendly identifier for an ActiveRecord.
|
3
4
|
class Slug < ActiveRecord::Base
|
4
5
|
|
5
6
|
belongs_to :sluggable, :polymorphic => true
|
6
7
|
before_save :check_for_blank_name, :set_sequence
|
8
|
+
|
9
|
+
|
10
|
+
ASCII_APPROXIMATIONS = {
|
11
|
+
198 => "AE",
|
12
|
+
208 => "D",
|
13
|
+
216 => "O",
|
14
|
+
222 => "Th",
|
15
|
+
223 => "ss",
|
16
|
+
230 => "ae",
|
17
|
+
240 => "d",
|
18
|
+
248 => "o",
|
19
|
+
254 => "th"
|
20
|
+
}.freeze
|
7
21
|
|
8
22
|
class << self
|
9
23
|
|
@@ -13,20 +27,14 @@ class Slug < ActiveRecord::Base
|
|
13
27
|
#
|
14
28
|
# slug.normalize('This... is an example!') # => "this-is-an-example"
|
15
29
|
#
|
16
|
-
# Note that
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# for instance replacing Icelandic's "thorn" character with "y" rather
|
22
|
-
# than "d." This might be pedantic, but I don't want to piss off the
|
23
|
-
# Vikings. The last time anyone pissed them off, they uleashed a wave of
|
24
|
-
# terror in Europe unlike anything ever seen before or after. I'm not
|
25
|
-
# taking any chances.
|
30
|
+
# Note that the Unicode handling in ActiveSupport may fail to process some
|
31
|
+
# characters from Polish, Icelandic and other languages. If your
|
32
|
+
# application uses these languages, check {out this
|
33
|
+
# article}[http://link-coming-soon.com] for information on how to get
|
34
|
+
# better urls in your application.
|
26
35
|
def normalize(slug_text)
|
27
36
|
return "" if slug_text.nil? || slug_text == ""
|
28
|
-
|
29
|
-
send(chars_func).
|
37
|
+
ActiveSupport::Multibyte.proxy_class.new(slug_text).normalize(:kc).
|
30
38
|
# For some reason Spanish ¡ and ¿ are not detected as non-word
|
31
39
|
# characters. Bug in Ruby?
|
32
40
|
gsub(/[\W|¡|¿]/u, ' ').
|
@@ -36,6 +44,10 @@ class Slug < ActiveRecord::Base
|
|
36
44
|
downcase.
|
37
45
|
to_s
|
38
46
|
end
|
47
|
+
|
48
|
+
def postnormalize(string)
|
49
|
+
string.gs
|
50
|
+
end
|
39
51
|
|
40
52
|
def parse(friendly_id)
|
41
53
|
name, sequence = friendly_id.split('--')
|
@@ -46,8 +58,17 @@ class Slug < ActiveRecord::Base
|
|
46
58
|
# Remove diacritics (accents, umlauts, etc.) from the string. Borrowed
|
47
59
|
# from "The Ruby Way."
|
48
60
|
def strip_diacritics(string)
|
49
|
-
|
61
|
+
ActiveSupport::Multibyte.proxy_class.new(string).normalize(:kd).unpack('U*').inject([]) { |a, u|
|
62
|
+
if ASCII_APPROXIMATIONS[u]
|
63
|
+
a += ASCII_APPROXIMATIONS[u].unpack('U*')
|
64
|
+
elsif (u < 0x300 || u > 0x036F)
|
65
|
+
a << u
|
66
|
+
end
|
67
|
+
a
|
68
|
+
}.pack('U*')
|
50
69
|
end
|
70
|
+
|
71
|
+
|
51
72
|
|
52
73
|
# Remove non-ascii characters from the string.
|
53
74
|
def strip_non_ascii(string)
|
@@ -75,7 +96,7 @@ class Slug < ActiveRecord::Base
|
|
75
96
|
|
76
97
|
# Raise a FriendlyId::SlugGenerationError if the slug name is blank.
|
77
98
|
def check_for_blank_name #:nodoc:#
|
78
|
-
if name
|
99
|
+
if name.blank?
|
79
100
|
raise FriendlyId::SlugGenerationError.new("The slug text is blank.")
|
80
101
|
end
|
81
102
|
end
|
data/lib/friendly_id/version.rb
CHANGED
data/test/slug_test.rb
CHANGED
@@ -39,8 +39,8 @@ class SlugTest < Test::Unit::TestCase
|
|
39
39
|
input = "ÀÁÂÃÄÅÆÇÈÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ"
|
40
40
|
output = Slug::strip_diacritics(input).split(//)
|
41
41
|
expected = "AAAAAAAECEEEIIIIDNOOOOOOUUUUYThssaaaaaaaeceeeeiiiidnoooooouuuuythy".split(//)
|
42
|
-
output.
|
43
|
-
assert_equal
|
42
|
+
output.each_index do |i|
|
43
|
+
assert_equal expected[i], output[i]
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
data/test/sti_test.rb
CHANGED
@@ -17,9 +17,9 @@ class SluggedModelTest < Test::Unit::TestCase
|
|
17
17
|
should "have a slug" do
|
18
18
|
assert_not_nil @novel.slug
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
context "found by its friendly id" do
|
22
|
-
|
22
|
+
|
23
23
|
setup do
|
24
24
|
@novel = Novel.find(@novel.friendly_id)
|
25
25
|
end
|
@@ -29,10 +29,10 @@ class SluggedModelTest < Test::Unit::TestCase
|
|
29
29
|
end
|
30
30
|
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
|
34
34
|
context "found by its numeric id" do
|
35
|
-
|
35
|
+
|
36
36
|
setup do
|
37
37
|
@novel = Novel.find(@novel.id)
|
38
38
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
2
|
$:.unshift(File.dirname(__FILE__))
|
3
|
-
$
|
3
|
+
$KCODE = 'UTF8' if RUBY_VERSION < '1.9'
|
4
|
+
$VERBOSE = false
|
4
5
|
require 'rubygems'
|
5
6
|
require 'test/unit'
|
6
7
|
require 'shoulda'
|
@@ -8,8 +9,10 @@ require 'shoulda'
|
|
8
9
|
# The default is to use the latest installed ActiveRecord.
|
9
10
|
if ENV["AR_VERSION"]
|
10
11
|
gem 'activerecord', "#{ENV["AR_VERSION"]}"
|
12
|
+
gem 'activesupport', "#{ENV["AR_VERSION"]}"
|
11
13
|
end
|
12
14
|
require 'active_record'
|
15
|
+
require 'active_support'
|
13
16
|
|
14
17
|
require 'friendly_id'
|
15
18
|
require 'models/post'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: friendly_id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Norman Clarke
|
@@ -32,21 +32,21 @@ cert_chain:
|
|
32
32
|
h7fbBRfStxI=
|
33
33
|
-----END CERTIFICATE-----
|
34
34
|
|
35
|
-
date: 2009-
|
35
|
+
date: 2009-03-25 00:00:00 -03:00
|
36
36
|
default_executable:
|
37
37
|
dependencies:
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
|
-
name:
|
39
|
+
name: activerecord
|
40
40
|
type: :runtime
|
41
41
|
version_requirement:
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
46
|
+
version: 2.0.0
|
47
47
|
version:
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
|
-
name:
|
49
|
+
name: activesupport
|
50
50
|
type: :runtime
|
51
51
|
version_requirement:
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
metadata.gz.sig
CHANGED
Binary file
|