friendly_id 2.3.4 → 3.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +10 -0
- data/Contributors.md +1 -0
- data/Guide.md +48 -4
- data/README.md +6 -4
- data/Rakefile +1 -1
- data/extras/extras.rb +1 -1
- data/generators/friendly_id/friendly_id_generator.rb +1 -1
- data/lib/friendly_id.rb +4 -6
- data/lib/friendly_id/{active_record2 → acktive_record}/configuration.rb +2 -2
- data/lib/friendly_id/{active_record2 → acktive_record}/finders.rb +24 -10
- data/lib/friendly_id/{active_record2 → acktive_record}/simple_model.rb +12 -50
- data/lib/friendly_id/acktive_record/slug.rb +66 -0
- data/lib/friendly_id/{active_record2 → acktive_record}/slugged_model.rb +9 -85
- data/lib/friendly_id/{active_record2 → acktive_record}/tasks.rb +5 -2
- data/lib/friendly_id/{active_record2 → acktive_record}/tasks/friendly_id.rake +1 -1
- data/lib/friendly_id/{active_record2.rb → active_record.rb} +18 -13
- data/lib/friendly_id/configuration.rb +11 -26
- data/lib/friendly_id/finders.rb +5 -3
- data/lib/friendly_id/slug_string.rb +11 -10
- data/lib/friendly_id/slugged.rb +11 -4
- data/lib/friendly_id/test.rb +46 -5
- data/lib/friendly_id/version.rb +5 -4
- data/lib/generators/friendly_id_generator.rb +32 -0
- data/rails/init.rb +1 -1
- data/test/{active_record2 → acktive_record}/basic_slugged_model_test.rb +3 -3
- data/test/{active_record2 → acktive_record}/cached_slug_test.rb +3 -3
- data/test/{active_record2 → acktive_record}/core.rb +1 -1
- data/test/{active_record2 → acktive_record}/custom_normalizer_test.rb +3 -3
- data/test/{active_record2 → acktive_record}/custom_table_name_test.rb +3 -3
- data/test/{active_record2 → acktive_record}/scoped_model_test.rb +2 -2
- data/test/{active_record2 → acktive_record}/simple_test.rb +4 -1
- data/test/{active_record2 → acktive_record}/slug_test.rb +0 -0
- data/test/{active_record2 → acktive_record}/slugged.rb +1 -1
- data/test/{active_record2 → acktive_record}/slugged_status_test.rb +1 -1
- data/test/{active_record2 → acktive_record}/sti_test.rb +3 -3
- data/test/{active_record2 → acktive_record}/support/database.mysql.yml +0 -0
- data/test/{active_record2 → acktive_record}/support/database.postgres.yml +0 -0
- data/test/{active_record2 → acktive_record}/support/database.sqlite3.yml +0 -0
- data/test/{active_record2 → acktive_record}/support/models.rb +5 -6
- data/test/{active_record2 → acktive_record}/tasks_test.rb +1 -1
- data/test/acktive_record/temp_test.rb +32 -0
- data/test/{active_record2 → acktive_record}/test_helper.rb +4 -10
- data/test/slug_string_test.rb +5 -1
- data/test/test_helper.rb +9 -3
- metadata +48 -44
- data/lib/friendly_id/active_record2/slug.rb +0 -111
- data/test/active_record2/deprecated_test.rb +0 -23
data/lib/friendly_id/version.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
class FriendlyIdGenerator < Rails::Generators::Base
|
5
|
+
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
|
8
|
+
RAKE_FILE = File.join(File.dirname(__FILE__), "..", "friendly_id", "acktive_record", "tasks", "friendly_id.rake")
|
9
|
+
MIGRATIONS_FILE = File.join(File.dirname(__FILE__), "..", "..", "generators", "friendly_id", "templates", "create_slugs.rb")
|
10
|
+
|
11
|
+
class_option :"skip-migration", :type => :boolean, :desc => "Don't generate a migration for the slugs table"
|
12
|
+
class_option :"skip-tasks", :type => :boolean, :desc => "Don't add friendly_id Rake tasks to lib/tasks"
|
13
|
+
class_option :"skip-initializer", :type => :boolean, :desc => "Don't add friendly_id initializer to config/initializers"
|
14
|
+
|
15
|
+
def copy_files(*args)
|
16
|
+
migration_template MIGRATIONS_FILE, "db/migrate/create_slugs.rb" unless options["skip-migration"]
|
17
|
+
rakefile "friendly_id.rake", File.read(RAKE_FILE) unless options["skip-tasks"]
|
18
|
+
initializer "friendly_id.rb" do
|
19
|
+
'require "friendly_id/active_record"'
|
20
|
+
end unless options["skip-initializer"]
|
21
|
+
end
|
22
|
+
|
23
|
+
# Taken from ActiveRecord's migration generator
|
24
|
+
def self.next_migration_number(dirname) #:nodoc:
|
25
|
+
if ActiveRecord::Base.timestamped_migrations
|
26
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
27
|
+
else
|
28
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/rails/init.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
require "friendly_id"
|
2
|
-
require "friendly_id/
|
2
|
+
require "friendly_id/active_record"
|
@@ -2,12 +2,12 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
2
2
|
|
3
3
|
module FriendlyId
|
4
4
|
module Test
|
5
|
-
module
|
5
|
+
module AcktiveRecord
|
6
6
|
class BasicSluggedModelTest < ::Test::Unit::TestCase
|
7
7
|
include FriendlyId::Test::Generic
|
8
8
|
include FriendlyId::Test::Slugged
|
9
|
-
include FriendlyId::Test::
|
10
|
-
include FriendlyId::Test::
|
9
|
+
include FriendlyId::Test::AcktiveRecord::Slugged
|
10
|
+
include FriendlyId::Test::AcktiveRecord::Core
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -2,14 +2,14 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
2
2
|
|
3
3
|
module FriendlyId
|
4
4
|
module Test
|
5
|
-
module
|
5
|
+
module AcktiveRecord
|
6
6
|
|
7
7
|
class CachedSlugTest < ::Test::Unit::TestCase
|
8
8
|
|
9
9
|
include FriendlyId::Test::Generic
|
10
10
|
include FriendlyId::Test::Slugged
|
11
|
-
include FriendlyId::Test::
|
12
|
-
include FriendlyId::Test::
|
11
|
+
include FriendlyId::Test::AcktiveRecord::Slugged
|
12
|
+
include FriendlyId::Test::AcktiveRecord::Core
|
13
13
|
|
14
14
|
def klass
|
15
15
|
District
|
@@ -2,12 +2,12 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
2
2
|
|
3
3
|
module FriendlyId
|
4
4
|
module Test
|
5
|
-
module
|
5
|
+
module AcktiveRecord
|
6
6
|
|
7
7
|
class CustomNormalizerTest < ::Test::Unit::TestCase
|
8
8
|
|
9
|
-
include FriendlyId::Test::
|
10
|
-
include FriendlyId::Test::
|
9
|
+
include FriendlyId::Test::AcktiveRecord::Core
|
10
|
+
include FriendlyId::Test::AcktiveRecord::Slugged
|
11
11
|
include FriendlyId::Test::CustomNormalizer
|
12
12
|
|
13
13
|
def klass
|
@@ -2,14 +2,14 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
2
2
|
|
3
3
|
module FriendlyId
|
4
4
|
module Test
|
5
|
-
module
|
5
|
+
module AcktiveRecord
|
6
6
|
|
7
7
|
class CustomTableNameTest < ::Test::Unit::TestCase
|
8
8
|
|
9
9
|
include FriendlyId::Test::Generic
|
10
10
|
include FriendlyId::Test::Slugged
|
11
|
-
include FriendlyId::Test::
|
12
|
-
include FriendlyId::Test::
|
11
|
+
include FriendlyId::Test::AcktiveRecord::Slugged
|
12
|
+
include FriendlyId::Test::AcktiveRecord::Core
|
13
13
|
|
14
14
|
def klass
|
15
15
|
Place
|
@@ -7,8 +7,8 @@ module FriendlyId
|
|
7
7
|
|
8
8
|
include FriendlyId::Test::Generic
|
9
9
|
include FriendlyId::Test::Slugged
|
10
|
-
include FriendlyId::Test::
|
11
|
-
include FriendlyId::Test::
|
10
|
+
include FriendlyId::Test::AcktiveRecord::Slugged
|
11
|
+
include FriendlyId::Test::AcktiveRecord::Core
|
12
12
|
|
13
13
|
def setup
|
14
14
|
@user = User.create!(:name => "john")
|
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
2
2
|
|
3
3
|
module FriendlyId
|
4
4
|
module Test
|
5
|
-
module
|
5
|
+
module AcktiveRecord
|
6
6
|
module Simple
|
7
7
|
|
8
8
|
module SimpleTest
|
@@ -21,6 +21,9 @@ module FriendlyId
|
|
21
21
|
|
22
22
|
class StatusTest < ::Test::Unit::TestCase
|
23
23
|
|
24
|
+
include FriendlyId::Test::Generic
|
25
|
+
include FriendlyId::Test::Simple
|
26
|
+
include FriendlyId::Test::AcktiveRecord::Core
|
24
27
|
include SimpleTest
|
25
28
|
|
26
29
|
test "should default to not friendly" do
|
File without changes
|
@@ -2,14 +2,14 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
2
2
|
|
3
3
|
module FriendlyId
|
4
4
|
module Test
|
5
|
-
module
|
5
|
+
module AcktiveRecord
|
6
6
|
|
7
7
|
class StiTest < ::Test::Unit::TestCase
|
8
8
|
|
9
9
|
include FriendlyId::Test::Generic
|
10
10
|
include FriendlyId::Test::Slugged
|
11
|
-
include FriendlyId::Test::
|
12
|
-
include FriendlyId::Test::
|
11
|
+
include FriendlyId::Test::AcktiveRecord::Slugged
|
12
|
+
include FriendlyId::Test::AcktiveRecord::Core
|
13
13
|
|
14
14
|
def klass
|
15
15
|
Novel
|
File without changes
|
File without changes
|
File without changes
|
@@ -5,6 +5,11 @@ class CreateSupportModels < ActiveRecord::Migration
|
|
5
5
|
t.string :name
|
6
6
|
end
|
7
7
|
|
8
|
+
create_table :blocks do |t|
|
9
|
+
t.string :name
|
10
|
+
t.string :note
|
11
|
+
end
|
12
|
+
|
8
13
|
create_table :books do |t|
|
9
14
|
t.string :name
|
10
15
|
t.string :type
|
@@ -65,14 +70,8 @@ class CreateSupportModels < ActiveRecord::Migration
|
|
65
70
|
t.index :name, :unique => true
|
66
71
|
end
|
67
72
|
|
68
|
-
create_table :blocks do |t|
|
69
|
-
t.string :name
|
70
|
-
t.string :note
|
71
|
-
end
|
72
|
-
|
73
73
|
end
|
74
74
|
|
75
75
|
def self.down
|
76
76
|
end
|
77
77
|
end
|
78
|
-
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
|
4
|
+
# scope :hello, :conditions => {"books.name" => "hello world"}
|
5
|
+
# scope :friendly, lambda { |name| {:conditions => {"slugs.name" => name }, :include => :slugs}}
|
6
|
+
#
|
7
|
+
# def self.find(*args, &block)
|
8
|
+
# if FriendlyId::Finders::Base.friendly?(args.first)
|
9
|
+
# puts "doing friendly find with #{args.first}"
|
10
|
+
# self.friendly(args.shift).first(*args)
|
11
|
+
# else
|
12
|
+
# super
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# end
|
17
|
+
|
18
|
+
module FriendlyId
|
19
|
+
module Test
|
20
|
+
module AcktiveRecord
|
21
|
+
|
22
|
+
class StiTest < ::Test::Unit::TestCase
|
23
|
+
|
24
|
+
# def test_temp
|
25
|
+
# instance = Post.create(:name => "hello world")
|
26
|
+
# p instance.class.find(instance.friendly_id)
|
27
|
+
# end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -2,7 +2,8 @@ require File.dirname(__FILE__) + "/../test_helper"
|
|
2
2
|
|
3
3
|
require "active_record"
|
4
4
|
require "active_support"
|
5
|
-
|
5
|
+
|
6
|
+
require File.dirname(__FILE__) + "/../../lib/friendly_id/active_record.rb"
|
6
7
|
require File.dirname(__FILE__) + "/../../generators/friendly_id/templates/create_slugs"
|
7
8
|
require File.dirname(__FILE__) + "/support/models"
|
8
9
|
require File.dirname(__FILE__) + '/core'
|
@@ -79,7 +80,7 @@ end
|
|
79
80
|
# A model that uses default slug settings and has a named scope
|
80
81
|
class Post < ActiveRecord::Base
|
81
82
|
has_friendly_id :name, :use_slug => true
|
82
|
-
|
83
|
+
send FriendlyId::AcktiveRecord::Compat.scope_method, :published, :conditions => { :published => true }
|
83
84
|
end
|
84
85
|
|
85
86
|
# Model that uses a custom table name
|
@@ -104,11 +105,4 @@ end
|
|
104
105
|
# A model with no table
|
105
106
|
class Question < ActiveRecord::Base
|
106
107
|
has_friendly_id :name, :use_slug => true
|
107
|
-
end
|
108
|
-
|
109
|
-
# A model using the deprecated block syntax
|
110
|
-
class Block < ActiveRecord::Base
|
111
|
-
has_friendly_id :name, :use_slug => true do |text|
|
112
|
-
FriendlyId::SlugString.new(text).clean.with_dashes
|
113
|
-
end
|
114
|
-
end
|
108
|
+
end
|
data/test/slug_string_test.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
$KCODE = "UTF8" if RUBY_VERSION < "1.9"
|
2
2
|
$VERBOSE = false
|
3
|
-
|
4
|
-
require
|
3
|
+
begin
|
4
|
+
require File.join(File.dirname(__FILE__), '../.bundle/environment')
|
5
|
+
rescue LoadError
|
6
|
+
# Fall back on doing an unlocked resolve at runtime.
|
7
|
+
require "rubygems"
|
8
|
+
require "bundler"
|
9
|
+
Bundler.setup
|
10
|
+
end
|
5
11
|
require "test/unit"
|
6
12
|
require "mocha"
|
7
13
|
require "active_support"
|
8
14
|
require File.dirname(__FILE__) + "/../lib/friendly_id"
|
9
|
-
require File.dirname(__FILE__) + "/../lib/friendly_id/test"
|
15
|
+
require File.dirname(__FILE__) + "/../lib/friendly_id/test"
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: friendly_id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
4
|
+
prerelease: true
|
5
5
|
segments:
|
6
|
-
- 2
|
7
6
|
- 3
|
8
|
-
-
|
9
|
-
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- beta1
|
10
|
+
version: 3.0.0.beta1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Norman Clarke
|
@@ -16,7 +17,7 @@ autorequire:
|
|
16
17
|
bindir: bin
|
17
18
|
cert_chain: []
|
18
19
|
|
19
|
-
date: 2010-03-
|
20
|
+
date: 2010-03-26 00:00:00 -03:00
|
20
21
|
default_executable:
|
21
22
|
dependencies:
|
22
23
|
- !ruby/object:Gem::Dependency
|
@@ -57,13 +58,13 @@ extensions: []
|
|
57
58
|
extra_rdoc_files: []
|
58
59
|
|
59
60
|
files:
|
60
|
-
- lib/friendly_id/
|
61
|
-
- lib/friendly_id/
|
62
|
-
- lib/friendly_id/
|
63
|
-
- lib/friendly_id/
|
64
|
-
- lib/friendly_id/
|
65
|
-
- lib/friendly_id/
|
66
|
-
- lib/friendly_id/
|
61
|
+
- lib/friendly_id/acktive_record/configuration.rb
|
62
|
+
- lib/friendly_id/acktive_record/finders.rb
|
63
|
+
- lib/friendly_id/acktive_record/simple_model.rb
|
64
|
+
- lib/friendly_id/acktive_record/slug.rb
|
65
|
+
- lib/friendly_id/acktive_record/slugged_model.rb
|
66
|
+
- lib/friendly_id/acktive_record/tasks.rb
|
67
|
+
- lib/friendly_id/active_record.rb
|
67
68
|
- lib/friendly_id/configuration.rb
|
68
69
|
- lib/friendly_id/finders.rb
|
69
70
|
- lib/friendly_id/slug_string.rb
|
@@ -72,7 +73,8 @@ files:
|
|
72
73
|
- lib/friendly_id/test.rb
|
73
74
|
- lib/friendly_id/version.rb
|
74
75
|
- lib/friendly_id.rb
|
75
|
-
- lib/
|
76
|
+
- lib/generators/friendly_id_generator.rb
|
77
|
+
- lib/friendly_id/acktive_record/tasks/friendly_id.rake
|
76
78
|
- Changelog.md
|
77
79
|
- Contributors.md
|
78
80
|
- Guide.md
|
@@ -82,24 +84,24 @@ files:
|
|
82
84
|
- rails/init.rb
|
83
85
|
- generators/friendly_id/friendly_id_generator.rb
|
84
86
|
- generators/friendly_id/templates/create_slugs.rb
|
85
|
-
- test/
|
86
|
-
- test/
|
87
|
-
- test/
|
88
|
-
- test/
|
89
|
-
- test/
|
90
|
-
- test/
|
91
|
-
- test/
|
92
|
-
- test/
|
93
|
-
- test/
|
94
|
-
- test/
|
95
|
-
- test/
|
96
|
-
- test/
|
97
|
-
- test/
|
98
|
-
- test/
|
99
|
-
- test/
|
100
|
-
- test/
|
101
|
-
- test/
|
102
|
-
- test/
|
87
|
+
- test/acktive_record/basic_slugged_model_test.rb
|
88
|
+
- test/acktive_record/cached_slug_test.rb
|
89
|
+
- test/acktive_record/core.rb
|
90
|
+
- test/acktive_record/custom_normalizer_test.rb
|
91
|
+
- test/acktive_record/custom_table_name_test.rb
|
92
|
+
- test/acktive_record/scoped_model_test.rb
|
93
|
+
- test/acktive_record/simple_test.rb
|
94
|
+
- test/acktive_record/slug_test.rb
|
95
|
+
- test/acktive_record/slugged.rb
|
96
|
+
- test/acktive_record/slugged_status_test.rb
|
97
|
+
- test/acktive_record/sti_test.rb
|
98
|
+
- test/acktive_record/support/database.mysql.yml
|
99
|
+
- test/acktive_record/support/database.postgres.yml
|
100
|
+
- test/acktive_record/support/database.sqlite3.yml
|
101
|
+
- test/acktive_record/support/models.rb
|
102
|
+
- test/acktive_record/tasks_test.rb
|
103
|
+
- test/acktive_record/temp_test.rb
|
104
|
+
- test/acktive_record/test_helper.rb
|
103
105
|
- test/friendly_id_test.rb
|
104
106
|
- test/slug_string_test.rb
|
105
107
|
- test/test_helper.rb
|
@@ -142,8 +144,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
144
|
- - ">="
|
143
145
|
- !ruby/object:Gem::Version
|
144
146
|
segments:
|
145
|
-
-
|
146
|
-
|
147
|
+
- 1
|
148
|
+
- 3
|
149
|
+
- 6
|
150
|
+
version: 1.3.6
|
147
151
|
requirements: []
|
148
152
|
|
149
153
|
rubyforge_project: friendly-id
|
@@ -152,16 +156,16 @@ signing_key:
|
|
152
156
|
specification_version: 3
|
153
157
|
summary: A comprehensive slugging and pretty-URL plugin.
|
154
158
|
test_files:
|
155
|
-
- test/
|
156
|
-
- test/
|
157
|
-
- test/
|
158
|
-
- test/
|
159
|
-
- test/
|
160
|
-
- test/
|
161
|
-
- test/
|
162
|
-
- test/
|
163
|
-
- test/
|
164
|
-
- test/
|
165
|
-
- test/
|
159
|
+
- test/acktive_record/basic_slugged_model_test.rb
|
160
|
+
- test/acktive_record/cached_slug_test.rb
|
161
|
+
- test/acktive_record/custom_normalizer_test.rb
|
162
|
+
- test/acktive_record/custom_table_name_test.rb
|
163
|
+
- test/acktive_record/scoped_model_test.rb
|
164
|
+
- test/acktive_record/simple_test.rb
|
165
|
+
- test/acktive_record/slug_test.rb
|
166
|
+
- test/acktive_record/slugged_status_test.rb
|
167
|
+
- test/acktive_record/sti_test.rb
|
168
|
+
- test/acktive_record/tasks_test.rb
|
169
|
+
- test/acktive_record/temp_test.rb
|
166
170
|
- test/friendly_id_test.rb
|
167
171
|
- test/slug_string_test.rb
|