mongomapper_ext 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -16,17 +16,19 @@ module MongoMapperExt
16
16
  end
17
17
 
18
18
  protected
19
+
19
20
  def generate_slug
20
- if self.slug.blank?
21
- unless self[self.class.slug_key].blank?
22
- slug = self[self.class.slug_key].gsub(/[^A-Za-z0-9\s\-]/, "")[0,20].strip.gsub(/\s+/, "-").downcase
23
- if !self.class.slug_options[:unique]
24
- key = UUIDTools::UUID.random_create.hexdigest[0,4] #optimize
25
- self.slug = key+"-"+slug
26
- else
27
- self.slug = slug
28
- end
29
- end
21
+ return false if self[self.class.slug_key].blank?
22
+ max_length = self.class.slug_options[:max_length]
23
+
24
+ slug = self[self.class.slug_key].parameterize.to_s
25
+ slug = slug[0, max_length] if max_length
26
+
27
+ if !self.class.slug_options[:unique]
28
+ key = UUIDTools::UUID.random_create.hexdigest[0,4] #optimize
29
+ self.slug = key+"-"+slug
30
+ else
31
+ self.slug = slug
30
32
  end
31
33
  end
32
34
 
@@ -1,8 +1,11 @@
1
1
  $:.unshift File.dirname(__FILE__)
2
2
 
3
- require 'mongo/gridfs'
3
+ $KCODE = 'u'
4
+
4
5
  require 'mongo_mapper'
6
+ require 'mongo/gridfs'
5
7
  require 'uuidtools'
8
+ require 'active_support/inflector'
6
9
 
7
10
  # types
8
11
  require 'mongomapper_ext/types/open_struct'
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongomapper_ext}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David A. Cuadrado"]
12
- s.date = %q{2010-03-04}
12
+ s.date = %q{2010-03-08}
13
13
  s.description = %q{MongoMapper extensions}
14
14
  s.email = %q{krawek@gmail.com}
15
15
  s.extra_rdoc_files = [
data/test/models.rb CHANGED
@@ -39,7 +39,7 @@ class BlogPost # for Slug and Filter
39
39
  include MongoMapperExt::Tags
40
40
 
41
41
  filterable_keys :title, :body, :tags, :date
42
- slug_key :title
42
+ slug_key :title, :max_length => 18
43
43
  language :find_language
44
44
 
45
45
  key :title, String
@@ -25,6 +25,12 @@ class TestSlugizer < Test::Unit::TestCase
25
25
  @blogpost.slug = nil
26
26
  @blogpost.to_param.should == @blogpost.id
27
27
  end
28
+
29
+ should "respect the max length option" do
30
+ @blogpost = BlogPost.create(:title => "ultimo video/cancion en youtube?",
31
+ :body => "HeRe is tHe Body of the bLog pOsT")
32
+ @blogpost.slug.should =~ /\w+-ultimo-video-canci/
33
+ end
28
34
  end
29
35
 
30
36
  context "finding objects" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - David A. Cuadrado
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-04 00:00:00 -05:00
17
+ date: 2010-03-08 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency