Commit f6d56ce35e31286158c0c751a069800832d214dc

Authored by AntonioTerceiro
1 parent ea760cb1

ActionItem41: moving to_slug logic outside of lib/acts_as_filesystem.rb


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1271 3f533792-8f58-4932-b0fe-aaf55b0a4547
config/environment.rb
... ... @@ -75,8 +75,8 @@ Localist.callback = lambda { |l| GetText.locale= l }
75 75  
76 76 Tag.hierarchical = true
77 77  
78   -# string transliteration
79   -require 'noosfero/transliterations'
  78 +# several local libraries
  79 +require 'noosfero'
80 80  
81 81 require 'acts_as_filesystem'
82 82 require 'acts_as_searchable'
... ...
lib/acts_as_filesystem.rb
... ... @@ -104,9 +104,7 @@ module ActsAsFileSystem
104 104  
105 105 self[:name] = value
106 106 unless self.name.blank?
107   - # FIXME encapsulate this pattern (transliterate -> downcase -> gsub
108   - # ...) in a String method, say, to_slug
109   - self.slug = self.name.transliterate.downcase.gsub( /[^-a-z0-9~\s\.:;+=_]/, '').gsub(/[\s:;=_+]+/, '-').gsub(/[\-]{2,}/, '-').to_s
  107 + self.slug = self.name.to_slug
110 108 end
111 109 end
112 110  
... ...
lib/noosfero.rb
... ... @@ -28,3 +28,4 @@ module Noosfero
28 28 end
29 29  
30 30 require 'noosfero/constants'
  31 +require 'noosfero/core_ext'
... ...
lib/noosfero/core_ext.rb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +require 'noosfero/core_ext/string'
... ...
lib/noosfero/core_ext/string.rb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +require 'noosfero/transliterations'
  2 +
  3 +class String
  4 + def to_slug
  5 + transliterate.downcase.gsub( /[^-a-z0-9~\s\.:;+=_]/, '').gsub(/[\s:;=_+]+/, '-').gsub(/[\-]{2,}/, '-').to_s
  6 + end
  7 +end
... ...