friendly_id 4.0.0.rc1 → 4.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/friendly_id.rb +6 -6
- data/lib/friendly_id/base.rb +1 -1
- data/lib/friendly_id/configuration.rb +1 -1
- data/lib/friendly_id/{i18n.rb → simple_i18n.rb} +8 -7
- data/test/i18n_test.rb +2 -4
- metadata +23 -23
data/Rakefile
CHANGED
@@ -39,7 +39,7 @@ task :guide do
|
|
39
39
|
buffer << read_comments("lib/friendly_id/slugged.rb")
|
40
40
|
buffer << read_comments("lib/friendly_id/history.rb")
|
41
41
|
buffer << read_comments("lib/friendly_id/scoped.rb")
|
42
|
-
buffer << read_comments("lib/friendly_id/
|
42
|
+
buffer << read_comments("lib/friendly_id/simple_i18n.rb")
|
43
43
|
buffer << read_comments("lib/friendly_id/reserved.rb")
|
44
44
|
|
45
45
|
File.open("Guide.rdoc", "w") do |file|
|
data/lib/friendly_id.rb
CHANGED
@@ -45,15 +45,15 @@ with numeric ids:
|
|
45
45
|
module FriendlyId
|
46
46
|
|
47
47
|
# The current version.
|
48
|
-
VERSION = "4.0.0.
|
48
|
+
VERSION = "4.0.0.rc2"
|
49
49
|
|
50
50
|
@mutex = Mutex.new
|
51
51
|
|
52
|
-
autoload :History,
|
53
|
-
autoload :
|
54
|
-
autoload :Reserved,
|
55
|
-
autoload :Scoped,
|
56
|
-
autoload :Slugged,
|
52
|
+
autoload :History, "friendly_id/history"
|
53
|
+
autoload :SimpleI18n, "friendly_id/simple_i18n"
|
54
|
+
autoload :Reserved, "friendly_id/reserved"
|
55
|
+
autoload :Scoped, "friendly_id/scoped"
|
56
|
+
autoload :Slugged, "friendly_id/slugged"
|
57
57
|
|
58
58
|
# FriendlyId takes advantage of `extended` to do basic model setup, primarily
|
59
59
|
# extending {FriendlyId::Base} to add {FriendlyId::Base#friendly_id
|
data/lib/friendly_id/base.rb
CHANGED
@@ -9,7 +9,7 @@ method to configure your desired options:
|
|
9
9
|
|
10
10
|
class Foo < ActiveRecord::Base
|
11
11
|
extend FriendlyId
|
12
|
-
friendly_id bar, :use => [:slugged, :
|
12
|
+
friendly_id bar, :use => [:slugged, :simple_i18n]
|
13
13
|
end
|
14
14
|
|
15
15
|
The most important option is `:use`, which you use to tell FriendlyId which
|
@@ -53,7 +53,7 @@ module FriendlyId
|
|
53
53
|
# end
|
54
54
|
# @param [#to_s] *modules Arguments should be a symbols or strings that
|
55
55
|
# correspond with the name of a module inside the FriendlyId namespace. By
|
56
|
-
# default FriendlyId provides +:slugged+, +:history+, +:
|
56
|
+
# default FriendlyId provides +:slugged+, +:history+, +:simple_i18n+ and +:scoped+.
|
57
57
|
def use(*modules)
|
58
58
|
modules.to_a.flatten.compact.map do |name|
|
59
59
|
mod = FriendlyId.const_get(name.to_s.classify)
|
@@ -6,7 +6,8 @@ module FriendlyId
|
|
6
6
|
|
7
7
|
== Basic I18n
|
8
8
|
|
9
|
-
|
9
|
+
The {FriendlyId::SimpleI18n SimpleI18n} module adds very basic i18n support to
|
10
|
+
FriendlyId.
|
10
11
|
|
11
12
|
In order to use this module, your model must have a slug column for each locale.
|
12
13
|
By default FriendlyId looks for columns named, for example, "slug_en",
|
@@ -50,20 +51,20 @@ When new records are created, the slug is generated for the current locale only.
|
|
50
51
|
=== Translating Slugs
|
51
52
|
|
52
53
|
To translate an existing record's friendly_id, use
|
53
|
-
{FriendlyId::
|
54
|
-
add is properly escaped, transliterated and sequenced:
|
54
|
+
{FriendlyId::SimpleI18n::Model#set_friendly_id}. This will ensure that the slug
|
55
|
+
you add is properly escaped, transliterated and sequenced:
|
55
56
|
|
56
57
|
post = Post.create :name => "Star Wars"
|
57
58
|
post.set_friendly_id("La guerra de las galaxas", :es)
|
58
59
|
|
59
|
-
If you don't pass in a locale argument, FriendlyId::
|
60
|
+
If you don't pass in a locale argument, FriendlyId::SimpleI18n will just use the
|
60
61
|
current locale:
|
61
62
|
|
62
63
|
I18n.with_locale(:es) do
|
63
64
|
post.set_friendly_id("la-guerra-de-las-galaxas")
|
64
65
|
end
|
65
66
|
=end
|
66
|
-
module
|
67
|
+
module SimpleI18n
|
67
68
|
|
68
69
|
def self.included(model_class)
|
69
70
|
model_class.instance_eval do
|
@@ -75,7 +76,7 @@ current locale:
|
|
75
76
|
|
76
77
|
module Model
|
77
78
|
def set_friendly_id(text, locale = nil)
|
78
|
-
|
79
|
+
I18n.with_locale(locale || I18n.current_locale) do
|
79
80
|
set_slug(normalize_friendly_id(text))
|
80
81
|
end
|
81
82
|
end
|
@@ -83,7 +84,7 @@ current locale:
|
|
83
84
|
|
84
85
|
module Configuration
|
85
86
|
def slug_column
|
86
|
-
"#{super}_#{
|
87
|
+
"#{super}_#{I18n.locale}"
|
87
88
|
end
|
88
89
|
end
|
89
90
|
end
|
data/test/i18n_test.rb
CHANGED
@@ -3,11 +3,9 @@ require File.expand_path("../helper.rb", __FILE__)
|
|
3
3
|
class I18nTest < MiniTest::Unit::TestCase
|
4
4
|
include FriendlyId::Test
|
5
5
|
|
6
|
-
I18n = ::I18n
|
7
|
-
|
8
6
|
class Journalist < ActiveRecord::Base
|
9
7
|
extend FriendlyId
|
10
|
-
friendly_id :name, :use => :
|
8
|
+
friendly_id :name, :use => :simple_i18n
|
11
9
|
end
|
12
10
|
|
13
11
|
test "friendly_id should return a the current locale's slug" do
|
@@ -103,7 +101,7 @@ class I18nTest < MiniTest::Unit::TestCase
|
|
103
101
|
test "should add locale to non-default slug column and non-default locale" do
|
104
102
|
model_class = Class.new(ActiveRecord::Base) do
|
105
103
|
extend FriendlyId
|
106
|
-
friendly_id :name, :use => :
|
104
|
+
friendly_id :name, :use => :simple_i18n, :slug_column => :foo
|
107
105
|
end
|
108
106
|
I18n.with_locale :es do
|
109
107
|
assert_equal "foo_es", model_class.friendly_id_config.slug_column
|
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: 4.0.0.
|
4
|
+
version: 4.0.0.rc2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
16
|
-
requirement: &
|
16
|
+
requirement: &70113010960640 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.1.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70113010960640
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activerecord
|
27
|
-
requirement: &
|
27
|
+
requirement: &70113010958920 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 3.1.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70113010958920
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sqlite3
|
38
|
-
requirement: &
|
38
|
+
requirement: &70113010957760 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.3.4
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70113010957760
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: minitest
|
49
|
-
requirement: &
|
49
|
+
requirement: &70113010956880 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 2.4.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70113010956880
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: mocha
|
60
|
-
requirement: &
|
60
|
+
requirement: &70113010955680 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 0.9.12
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70113010955680
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: ffaker
|
71
|
-
requirement: &
|
71
|
+
requirement: &70113010954720 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 1.8.0
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70113010954720
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: maruku
|
82
|
-
requirement: &
|
82
|
+
requirement: &70113010953400 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 0.6.0
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70113010953400
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: yard
|
93
|
-
requirement: &
|
93
|
+
requirement: &70113010952800 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: 0.7.2
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70113010952800
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: i18n
|
104
|
-
requirement: &
|
104
|
+
requirement: &70113010952100 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ~>
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: 0.6.0
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70113010952100
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: simplecov
|
115
|
-
requirement: &
|
115
|
+
requirement: &70113010951100 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,7 +120,7 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70113010951100
|
124
124
|
description: ! 'FriendlyId is the "Swiss Army bulldozer" of slugging and permalink
|
125
125
|
plugins for
|
126
126
|
|
@@ -155,11 +155,11 @@ files:
|
|
155
155
|
- lib/friendly_id/configuration.rb
|
156
156
|
- lib/friendly_id/finder_methods.rb
|
157
157
|
- lib/friendly_id/history.rb
|
158
|
-
- lib/friendly_id/i18n.rb
|
159
158
|
- lib/friendly_id/migration.rb
|
160
159
|
- lib/friendly_id/object_utils.rb
|
161
160
|
- lib/friendly_id/reserved.rb
|
162
161
|
- lib/friendly_id/scoped.rb
|
162
|
+
- lib/friendly_id/simple_i18n.rb
|
163
163
|
- lib/friendly_id/slug.rb
|
164
164
|
- lib/friendly_id/slug_generator.rb
|
165
165
|
- lib/friendly_id/slugged.rb
|