Skip to content

Commit

Permalink
Clean up whitespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreisner committed Aug 19, 2010
1 parent 7c9d727 commit 535f16a
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions lib/handler.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module Handler

##
# Included hook: extend including class.
#
def self.included(base)
base.extend ClassMethods
end

##
# Transliterate a string: change accented Unicode characters to ASCII
# approximations. Tries several methods, attempting the best first:
#
#
# 1. unidecode, if installed (http://rubyforge.org/projects/unidecode)
# 2. iconv (included with Ruby, doesn't work with all Ruby versions)
# 3. normalize, then remove un-normalizable characters
Expand All @@ -21,7 +21,7 @@ def self.transliterate(string)
transliterate_with_normalization(string) or
string
end

##
# Transliterate a string with the unidecode library.
# Return nil if unsuccessful (eg, library not available).
Expand All @@ -34,7 +34,7 @@ def self.transliterate_with_unidecode(string)
nil
end
end

##
# Transliterate a string with the iconv library.
# Return nil if unsuccessful (eg, library not available).
Expand All @@ -46,7 +46,7 @@ def self.transliterate_with_iconv(string)
nil
end
end

##
# Generate a handle from a string.
#
Expand All @@ -60,9 +60,9 @@ def self.generate_handle(title, separator)
str = str.delete('.\'"') # no space
str = str.gsub(/\W/, ' ') # space
str = str.gsub(/ +/, separator)
str
str
end

##
# Get the next handle in the sequence (for avoiding duplicates).
#
Expand All @@ -73,7 +73,7 @@ def self.next_handle(handle, separator)
handle + separator + "2"
end
end

##
# Transliterate a string using multibyte normalization,
# then remove remaining non-ASCII characters. Taken from
Expand All @@ -82,13 +82,13 @@ def self.next_handle(handle, separator)
def self.transliterate_with_normalization(string)
string.mb_chars.normalize.gsub(/[^\x00-\x7F]+/, '').to_s
end
module ClassMethods

module ClassMethod

##
# Declare that a model generates a handle based on
# a given attribute or method. Options include:
#
#
# <tt>:separator</tt> - character to place between words
# <tt>:store</tt> - attribute in which to store handle
# <tt>:unique</tt> - generate a handle which is unique among all records
Expand All @@ -98,13 +98,13 @@ def handle_based_on(attribute, options = {})
options[:write_to] ||= :handle
options[:unique] = true if options[:unique].nil?

##
# Generate a URL-friendly name.
#
##
# Generate a URL-friendly name.
#
define_method :generate_handle do
h = Handler.generate_handle(send(attribute), options[:separator])
if options[:unique]

# generate a condition for finding an existing record with a
# given handle
find_dupe = lambda{ |h|
Expand All @@ -124,7 +124,7 @@ def handle_based_on(attribute, options = {})
end
h
end

##
# Assign the generated handle to the specified attribute.
#
Expand Down

0 comments on commit 535f16a

Please sign in to comment.