norman-friendly_id 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ host: compay@rubyforge.org
2
+ remote_dir: /var/www/gforge-projects/friendly-id
data/friendly_id.gemspec CHANGED
@@ -2,14 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{friendly_id}
5
- s.version = "2.0.1"
5
+ s.version = "2.0.2"
6
+
6
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
7
8
  s.authors = ["Norman Clarke", "Adrian Mugnolo", "Emilio Tagua"]
8
- s.date = %q{2009-01-19}
9
+ s.date = %q{2009-02-07}
9
10
  s.description = %q{A comprehensive slugging and pretty-URL plugin for Ruby on Rails.}
10
11
  s.email = ["norman@randomba.org", "adrian@randomba.org", "miloops@gmail.com"]
11
12
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
12
- s.files = ["History.txt", "MIT-LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "friendly_id.gemspec", "generators/friendly_id/friendly_id_generator.rb", "generators/friendly_id/templates/create_slugs.rb", "generators/friendly_id_20_upgrade/friendly_id_20_upgrade_generator.rb", "generators/friendly_id_20_upgrade/templates/upgrade_friendly_id_to_20.rb", "init.rb", "lib/friendly_id.rb", "lib/friendly_id/helpers.rb", "lib/friendly_id/non_sluggable_class_methods.rb", "lib/friendly_id/non_sluggable_instance_methods.rb", "lib/friendly_id/shoulda_macros.rb", "lib/friendly_id/slug.rb", "lib/friendly_id/sluggable_class_methods.rb", "lib/friendly_id/sluggable_instance_methods.rb", "lib/friendly_id/version.rb", "lib/tasks/friendly_id.rake", "lib/tasks/friendly_id.rb", "test/database.yml", "test/fixtures/countries.yml", "test/fixtures/country.rb", "test/fixtures/people.yml", "test/fixtures/person.rb", "test/fixtures/post.rb", "test/fixtures/posts.yml", "test/fixtures/slugs.yml", "test/fixtures/user.rb", "test/fixtures/users.yml", "test/non_slugged_test.rb", "test/rails/2.x/app/controllers/application.rb", "test/rails/2.x/config/boot.rb", "test/rails/2.x/config/database.yml", "test/rails/2.x/config/environment.rb", "test/rails/2.x/config/environments/test.rb", "test/rails/2.x/config/routes.rb", "test/schema.rb", "test/scoped_model_test.rb", "test/slug_test.rb", "test/sluggable_test.rb", "test/test_helper.rb"]
13
+ s.files = ["History.txt", "MIT-LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "config/website.yml", "friendly_id.gemspec", "generators/friendly_id/friendly_id_generator.rb", "generators/friendly_id/templates/create_slugs.rb", "generators/friendly_id_20_upgrade/friendly_id_20_upgrade_generator.rb", "generators/friendly_id_20_upgrade/templates/upgrade_friendly_id_to_20.rb", "init.rb", "lib/friendly_id.rb", "lib/friendly_id/helpers.rb", "lib/friendly_id/non_sluggable_class_methods.rb", "lib/friendly_id/non_sluggable_instance_methods.rb", "lib/friendly_id/shoulda_macros.rb", "lib/friendly_id/slug.rb", "lib/friendly_id/sluggable_class_methods.rb", "lib/friendly_id/sluggable_instance_methods.rb", "lib/friendly_id/version.rb", "lib/tasks/friendly_id.rake", "lib/tasks/friendly_id.rb", "test/database.yml", "test/fixtures/countries.yml", "test/fixtures/country.rb", "test/fixtures/people.yml", "test/fixtures/person.rb", "test/fixtures/post.rb", "test/fixtures/posts.yml", "test/fixtures/slugs.yml", "test/fixtures/user.rb", "test/fixtures/users.yml", "test/non_slugged_test.rb", "test/rails/2.x/app/controllers/application.rb", "test/rails/2.x/config/boot.rb", "test/rails/2.x/config/database.yml", "test/rails/2.x/config/environment.rb", "test/rails/2.x/config/environments/test.rb", "test/rails/2.x/config/routes.rb", "test/schema.rb", "test/scoped_model_test.rb", "test/slug_test.rb", "test/sluggable_test.rb", "test/test_helper.rb"]
13
14
  s.has_rdoc = true
14
15
  s.homepage = %q{http://randomba.org}
15
16
  s.rdoc_options = ["--main", "README.rdoc"]
@@ -49,11 +49,16 @@ class Slug < ActiveRecord::Base
49
49
  cp < 0x300 || cp > 0x036F
50
50
  }.pack('U*')
51
51
  end
52
+
53
+ # Remove non-ascii characters from the string.
54
+ def strip_non_ascii(string)
55
+ strip_diacritics(string).gsub(/[^a-z0-9]+/i, ' ')
56
+ end
52
57
 
53
58
  private
54
59
 
55
60
  def chars_func
56
- Rails.version =~ /2.2.[\d]*/ ? :mb_chars : :chars
61
+ Rails.version >= "2.2" ? :mb_chars : :chars
57
62
  rescue NoMethodError
58
63
  :chars
59
64
  end
@@ -87,7 +87,7 @@ module FriendlyId::SluggableClassMethods
87
87
  ids = []
88
88
  ids_and_names.each do |id_or_name|
89
89
  name, sequence = Slug.parse id_or_name
90
- slug = Slug.find(:first, :readonly => true, :conditions => {
90
+ slug = Slug.find(:first, :conditions => {
91
91
  :name => name,
92
92
  :scope => scope,
93
93
  :sequence => sequence,
@@ -57,10 +57,13 @@ module FriendlyId::SluggableInstanceMethods
57
57
  def slug_text
58
58
  base = send friendly_id_options[:column]
59
59
  if self.friendly_id_options[:strip_diacritics]
60
- base = Slug::normalize(Slug::strip_diacritics(base))
61
- else
62
- base = Slug::normalize(base)
60
+ base = Slug::strip_diacritics(base)
63
61
  end
62
+ if self.friendly_id_options[:strip_non_ascii]
63
+ base = Slug::strip_non_ascii(base)
64
+ end
65
+ base = Slug::normalize(base)
66
+
64
67
  if base.length > friendly_id_options[:max_length]
65
68
  base = base[0...friendly_id_options[:max_length]]
66
69
  end
@@ -82,7 +85,7 @@ module FriendlyId::SluggableInstanceMethods
82
85
  def init_finder_slug
83
86
  return false if !@finder_slug_name
84
87
  name, sequence = Slug.parse(@finder_slug_name)
85
- slug = Slug.find(:first, :conditions => {:sluggable_id => id, :name => name, :sequence => sequence, :sluggable_type => self.class.name })
88
+ slug = Slug.find(:first, :conditions => {:sluggable_id => id, :name => name, :sequence => sequence, :sluggable_type => self.class.base_class.name })
86
89
  finder_slug = slug
87
90
  end
88
91
 
@@ -2,7 +2,7 @@ module FriendlyId #:nodoc:
2
2
  module Version #:nodoc:
3
3
  MAJOR = 2
4
4
  MINOR = 0
5
- TINY = 1
5
+ TINY = 2
6
6
  STRING = [MAJOR, MINOR, TINY].join('.')
7
7
  end
8
8
  end
data/lib/friendly_id.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'unicode'
2
1
  require 'friendly_id/helpers'
3
2
  require 'friendly_id/slug'
4
3
  require 'friendly_id/shoulda_macros'
@@ -13,8 +12,8 @@ module FriendlyId
13
12
  module ClassMethods
14
13
 
15
14
  # Default options for friendly_id.
16
- DEFAULT_FRIENDLY_ID_OPTIONS = {:method => nil, :use_slug => false, :max_length => 255, :reserved => [], :strip_diacritics => false, :scope => nil}.freeze
17
- VALID_FRIENDLY_ID_KEYS = [:use_slug, :max_length, :reserved, :strip_diacritics, :scope].freeze
15
+ DEFAULT_FRIENDLY_ID_OPTIONS = {:method => nil, :use_slug => false, :max_length => 255, :reserved => [], :strip_diacritics => false, :strip_non_ascii => false, :scope => nil}.freeze
16
+ VALID_FRIENDLY_ID_KEYS = [:use_slug, :max_length, :reserved, :strip_diacritics, :strip_non_ascii, :scope].freeze
18
17
 
19
18
  # Set up an ActiveRecord model to use a friendly_id.
20
19
  #
@@ -25,6 +24,7 @@ module FriendlyId
25
24
  # * <tt>:use_slug</tt> - Defaults to false. Use slugs when you want to use a non-unique text field for friendly ids.
26
25
  # * <tt>:max_length</tt> - Defaults to 255. The maximum allowed length for a slug.
27
26
  # * <tt>:strip_diacritics</tt> - Defaults to false. If true, it will remove accents, umlauts, etc. from western characters.
27
+ # * <tt>:strip_non_ascii</tt> - Defaults to false. If true, it will all non-ascii ([^a-z0-9]) characters.
28
28
  # * <tt>:reseved</tt> - Array of words that are reserved and can't be used as slugs. 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 [].
29
29
  def has_friendly_id(column, options = {})
30
30
  options.assert_valid_keys VALID_FRIENDLY_ID_KEYS
@@ -33,7 +33,7 @@ module FriendlyId
33
33
  class_inheritable_reader :friendly_id_options
34
34
 
35
35
  if options[:use_slug]
36
- has_many :slugs, :order => 'id DESC', :as => :sluggable, :dependent => :destroy, :readonly => true
36
+ has_many :slugs, :order => 'id DESC', :as => :sluggable, :dependent => :destroy
37
37
  require 'friendly_id/sluggable_class_methods'
38
38
  require 'friendly_id/sluggable_instance_methods'
39
39
  extend SluggableClassMethods
@@ -55,7 +55,15 @@ module FriendlyId
55
55
  def enable
56
56
  return if ActiveRecord::Base.methods.include? 'has_friendly_id'
57
57
  ActiveRecord::Base.class_eval { extend FriendlyId::ClassMethods }
58
- Test::Unit::TestCase.class_eval { include FriendlyId::ShouldaMacros }
58
+ begin
59
+ if Rails.version >= "2.3"
60
+ ActiveSupport::TestCase.class_eval { include FriendlyId::ShouldaMacros }
61
+ else
62
+ Test::Unit::TestCase.class_eval { include FriendlyId::ShouldaMacros }
63
+ end
64
+ rescue NoMethodError
65
+ Test::Unit::TestCase.class_eval { include FriendlyId::ShouldaMacros }
66
+ end
59
67
  end
60
68
 
61
69
  end
@@ -64,4 +72,4 @@ end
64
72
 
65
73
  if defined?(ActiveRecord)
66
74
  FriendlyId::enable
67
- end
75
+ end
@@ -6,6 +6,8 @@ class SluggableTest < Test::Unit::TestCase
6
6
 
7
7
  def setup
8
8
  Post.friendly_id_options[:max_length] = FriendlyId::ClassMethods::DEFAULT_FRIENDLY_ID_OPTIONS[:max_length]
9
+ Post.friendly_id_options[:strip_non_ascii] = false
10
+ Post.friendly_id_options[:strip_diacritics] = false
9
11
  end
10
12
 
11
13
  def test_should_allow_for_identical_slug_names_between_sluggable_types
@@ -100,11 +102,16 @@ class SluggableTest < Test::Unit::TestCase
100
102
  end
101
103
 
102
104
  def test_should_not_strip_diactics_from_slug_unless_configured_to_do_so
103
- Post.friendly_id_options[:strip_diacritics] = false
104
105
  @post = Post.new(:name => "¡FELIZ AÑO!")
105
106
  assert_equal "feliz-año", @post.slug_text
106
107
  end
107
108
 
109
+ def test_should_convert_to_ascii
110
+ Post.friendly_id_options[:strip_non_ascii] = true
111
+ @post = Post.new(:name => "17” cômpütér mõnitor")
112
+ assert_equal '17-computer-monitor', @post.slug_text
113
+ end
114
+
108
115
  def test_should_not_make_new_slug_unless_friendly_id_method_has_changed
109
116
  posts(:with_one_slug).content = "Edited content"
110
117
  posts(:with_one_slug).save!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: norman-friendly_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Norman Clarke
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-01-19 00:00:00 -08:00
14
+ date: 2009-02-07 00:00:00 -08:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -60,6 +60,7 @@ files:
60
60
  - Manifest.txt
61
61
  - README.rdoc
62
62
  - Rakefile
63
+ - config/website.yml
63
64
  - friendly_id.gemspec
64
65
  - generators/friendly_id/friendly_id_generator.rb
65
66
  - generators/friendly_id/templates/create_slugs.rb