Permalink
Browse files

Fixed some spelling mistakes, restructured specs added utf-16 for exp…

…erimentation
  • Loading branch information...
1 parent 5c3509a commit b2dc0781a2d63df2506856f8527c9499a75ce94d rrevans committed May 12, 2008
Showing with 52 additions and 66 deletions.
  1. +5 −3 README
  2. +0 −4 TODO
  3. +17 −12 lib/permalizer/permalink.rb
  4. +30 −47 spec/permalizer_spec.rb
View
@@ -1,10 +1,12 @@
Permalizer
=================
-Permalizer is a way to create clean URLs from strings. It is framework agnostic, meaning it’s simply just a gem that can be used in Rails, Merb, Sinatra, Camping, etc. It has two ways to use it, with the bang and without it:
+Permalizer adds functionality to the String Object so that clean URLs creation is made simple
+
+It extend the string with permalize and permalize! which return permalized strings but
+doesn't add the permalization process inside the string class, that process remains
+in the Permalink::Permalizer class.
-“permalizer rocks!”.permalize # => “permalizer-rocks”
-“permalizer rocks # => “permalizer-rocks”
Contributors
------------
View
@@ -3,7 +3,3 @@ Add in Support for more languages that iconv doesn't support.
Add Ruby 1.9 string encoding support for fun.
Remove ActiveSupport decompose string dependency
-
-Add documentation to the gem in RDoc format
-
-Clean specs to reflect the changes in the destructive permalize! method
@@ -3,11 +3,11 @@ module Permalink # :nodo:
# Permalizer adds functionality to the String Object so that clean URLs creation is made simple
#
# It extend the string with <tt>permalize</tt> and <tt>permalize!</tt> which return permalized strings but
- # don't add the permalization process inside the string class, that process remains
+ # doesn't add the permalization process inside the string class, that process remains
# in the Permalink::Permalizer class.
#
module InstanceMethods
- # Transform the receiving string in a permalized string. Since this method is destructive,
+ # Transform the receiving string to a permalized string. Since this method is destructive,
# it should be used cautiously and only for things like clean user input:
#
# post.permalink = "something UNTRUSTFUL that should be a permalink!"
@@ -27,21 +27,21 @@ def permalize
end
end
- # Permalizer makes the permalization and holds configurations through fix methods
+ # Permalizer makes the permalization and holds configurations through translation methods
#
# === Configuration
#
# Permalizer has two class variables that makes configuration possible
#
# <tt>Permalizer.translate_to</tt>
#
- # The vale of this variable determines which translation will be used in String.permalize. The default is <tt>:us_ascii</tt>.
- # Possible values are <tt>:iso_8859_1</tt> and <tt>:utf_8</tt>. *The class can be easily extendable to add more fix methods*
+ # The value of this variable determines which translation will be used in String.permalize. The default is <tt>:us_ascii</tt>.
+ # Possible values are <tt>:iso_8859_1</tt> and <tt>:utf_8</tt>. *The class can be easily extendable by adding more translation methods*
#
# module Permalink
# class Permalizer
# def my_custom_translate_to
- # Iconv.(from, to).iconv @word
+ # Iconv.new(from, to).iconv @word
# end
# end
# end
@@ -51,8 +51,8 @@ def permalize
# <tt>Permalizer.decompose_string</tt>
#
# Determines if the permalization must perform the special ActiveSupport method chars.decompose to fix some
- # misunderstand of utf-8 characters in some machines. In these machines, a utf-8 string is scaped
- # automatically before is stored and Iconv strips out these scaped characters
+ # misunderstanding of utf-8 characters in some machines. In these machines, a utf-8 string is escaped
+ # automatically before it is stored and Iconv strips out these escaped characters.
#
# "españa".permalize # => "espaa" [ugly permalization]
# Permalize.decompose_string = true
@@ -62,7 +62,7 @@ def permalize
#
class Permalizer
- # = Class variable which determines the Iconv fix method
+ # = Class variable which determines the Iconv translation method
# us_ascii is the default
@@translate_to = :us_ascii
@@ -88,14 +88,19 @@ def us_ascii
Iconv.new('US-ASCII//TRANSLIT', 'UTF-8').iconv @word
end
+ # Uses the ISO-8859-1 encoding in the iconv conversion
+ def iso_8859_1
+ Iconv.new('ISO-8859-1//TRANSLIT//IGNORE', 'UTF-8').iconv @word
+ end
+
# Uses the UTF-8 encoding in the iconv conversion
def utf_8
Iconv.new('UTF-8//TRANSLIT//IGNORE', 'UTF-8').iconv @word
end
- # Uses the ISO-8859-1 encoding in the iconv conversion
- def iso_8859_1
- Iconv.new('ISO-8859-1//TRANSLIT//IGNORE', 'UTF-8').iconv @word
+ # Uses the UTF-16 encoding in the iconv conversion
+ def utf_16
+ Iconv.new('UTF-16//TRANSLIT//IGNORE', 'UTF-8').iconv @word
end
# Calls the translate_to and transforms the string passed in the constructor in a url valid string
@@ -1,91 +1,74 @@
require File.dirname(__FILE__) + '/spec_helper'
require File.dirname(__FILE__) + "/../lib/permalizer.rb"
-describe "permalizer" do
-
+describe Permalink::Permalizer, 'testing simple string conversions' do
it "should create a simple permalink" do
"testing one two three".permalize.should eql("testing-one-two-three")
- "testing one two bang".permalize!.should eql("testing-one-two-bang")
+ "Give me some dashes-in-here to dasherize".permalize.should eql("give-me-some-dashes-in-here-to-dasherize")
+ "Show me a 1 2 3".permalize.should eql("show-me-a-1-2-3")
end
it "should return a valid permalink with apostrophes" do
"test's".permalize.should eql("tests")
- "test's".permalize!.should eql("tests")
-
- "I've been".permalize.should eql("ive-been")
- "I've been banged".permalize!.should eql("ive-been-banged")
- end
-
- it "should ovewrite string original value when permalize! is called" do
- string = "i'll be overriden soon"
- string.permalize!
- string.should eql("ill-be-overriden-soon")
+ "I've been here today".permalize.should eql("ive-been-here-today")
end
it "should correctly handle single and double quotes" do
"\'here are some single quotes\'".permalize.should eql("here-are-some-single-quotes")
- "\'here are some single quotes\'".permalize!.should eql("here-are-some-single-quotes")
-
"\"and double quotes\"".permalize.should eql("and-double-quotes")
- "\"and double quotes\"".permalize!.should eql("and-double-quotes")
end
+ it "should return lower case characters" do
+ "Should HanDle UPPER case LeTtErS".permalize.should eql("should-handle-upper-case-letters")
+ end
+end
+
+describe Permalink::Permalizer, "testing special characters" do
it "should correctly handle special characters" do
"testing_underscores".permalize.should eql("testing-underscores")
- "testing_underscores".permalize!.should eql("testing-underscores")
-
"more _ underscores".permalize.should eql("more-underscores")
- "more _ underscores".permalize!.should eql("more-underscores")
-
"unicode chåråcter".permalize.should eql("unicode-character")
- "unicode chåråcter".permalize!.should eql("unicode-character")
-
"colon: and : ; semicolon".permalize.should eql("colon-and-semicolon")
- "colon: and : ; semicolon".permalize!.should eql("colon-and-semicolon")
-
"ampersand & here".permalize.should eql("ampersand-here")
- "ampersand & here".permalize!.should eql("ampersand-here")
-
"explanation point!".permalize.should eql("explanation-point")
- "explanation point!".permalize!.should eql("explanation-point")
-
"how are you?".permalize.should eql("how-are-you")
- "how are you?".permalize!.should eql("how-are-you")
end
it "should handle various types of characters" do
"several characters *& all ' together and () such".permalize.should eql("several-characters-all-together-and-such")
-
- "several characters *& all ' together and () such".permalize!.should eql("several-characters-all-together-and-such")
end
it "should keep dashes intact and handle multiple dashes" do
"keep-this dash".permalize.should eql("keep-this-dash")
- "keep-this dash".permalize!.should eql("keep-this-dash")
-
- "remove -- multiple---dashes".permalize.should eql("remove-multiple-dashes")
- "remove -- multiple---dashes".permalize!.should eql("remove-multiple-dashes")
-
+ "remove -- multiple---dashes ---".permalize.should eql("remove-multiple-dashes")
end
it "should correctly handle hyphens" do
- "here is a–hyphen test–this".permalize.should eql("here-is-a-hyphen-test-this")
- "here is a–hyphen".permalize!.should eql("here-is-a-hyphen")
- end
-
- it "should return lower case characters" do
- "Should HanDle UPPER case LeTtErS".permalize.should eql("should-handle-upper-case-letters")
-
- "Should HanDle UPPER case LeTtErS".permalize!.should eql("should-handle-upper-case-letters")
+ "here is a–hyphen check–this out".permalize.should eql("here-is-a-hyphen-check-this-out")
end
-
- it "should perform permalization even with a misspelled fix_method" do
- Permalink::Permalizer.translate_to = :undefined_fix_method
+end
+
+describe Permalink::Permalizer, 'testing various translation methods' do
+ it "should perform permalization even with a misspelled tranlate_to" do
+ Permalink::Permalizer.translate_to = :undefined_translation_method
"This will be permalized".permalize.should eql("this-will-be-permalized")
end
it "should perform an utf-8 transformation" do
Permalink::Permalizer.translate_to = :utf_8
"This string contains utf-8 characters: esdrújula. €100".permalize.should eql("this-string-contains-utf-8-characters-esdrujula-eur100")
end
+end
+
+describe Permalink::Permalizer, 'testing string decomposing' do
+ Permalink::Permalizer.decompose_string = true
+ "españa".permalize.should == "espana"
+end
+
+describe Permalink::Permalizer, 'testing the destructive permalize! method' do
+ it "should pummel a string to destruction" do
+ title = "12 monkeys gone crazy"
+ title.permalize!
+ title.should eql("12-monkeys-gone-crazy")
+ end
end

1 comment on commit b2dc078

@mapmarkus
Collaborator

Sorry for those spelling mistakes. I did my best (remember that I’m from Spain).

Please sign in to comment.