public
Description: Some [hopefully] useful extensions to Ruby’s String class. It is made up of three libraries: ActsAsUrl [permalink solution with better character translation], Unidecoder [Unicode to Ascii transliteration], and StringExtensions [miscellaneous helper methods for the String class].
Clone URL: git://github.com/rsl/stringex.git
Search Repo:
more updating
rsl (author)
Sun Apr 06 11:02:23 -0700 2008
commit  f055ae84aa624c197b69403ca2380ed3c5d9f4a0
tree    a324c0aa1b2696c75a16b31ad4e4ef2426922c56
parent  7cf5714e857f429d474f485532fe80a92ed0b9c0
...
15
16
17
 
 
18
19
 
 
 
 
 
 
 
20
21
22
...
61
62
63
64
 
65
66
...
15
16
17
18
19
20
 
21
22
23
24
25
26
27
28
29
30
...
69
70
71
 
72
73
74
0
@@ -15,8 +15,16 @@ which will populate the <tt>url</tt> attribute on the object with the converted
0
 <tt>:scope</tt>:: The name of model attribute to scope unique urls to. There is no default here.
0
 <tt>:sync_url</tt>:: If set to true, the url field will be updated when changes are made to the
0
                      attribute it is based on. Default is false.
0
+
0
+In order to use the generated url attribute, you will probably want to override <tt>to_param</tt> like so, in your Model:
0
 
0
-<b>Note:</b> Unlike other permalink solutions, ActsAsUrl doesn't rely on Iconv (which is inconsistent across platforms and doesn't provide great transliteration as is) but instead uses a transliteration scheme (see the code for Unidecoder) which produces much better results for Unicode characters. It also mixes in some custom helpers to translate common characters into a more URI-friendly format rather than just dump them completely. Examples:
0
+ def to_param
0
+ url # or whatever you set :url_attribute to
0
+ end
0
+
0
+Routing called via named routes like <tt>foo_path(@foo)</tt> will automatically use the url. In your controllers you will need to call <tt>Foo.find_by_url(params[:id])</tt> instead of the regular find. Don't look for <tt>params[:url]</tt> unless you set it explicitly in the routing, <tt>to_param</tt> will generate <tt>params[:id]</tt>.
0
+
0
+Unlike other permalink solutions, ActsAsUrl doesn't rely on Iconv (which is inconsistent across platforms and doesn't provide great transliteration as is) but instead uses a transliteration scheme (see the code for Unidecoder) which produces much better results for Unicode characters. It also mixes in some custom helpers to translate common characters into a more URI-friendly format rather than just dump them completely. Examples:
0
 
0
    # A simple prelude
0
    "simple English".to_url => "simple-english"
0
@@ -61,6 +69,6 @@ A collection of extensions on Ruby's String class. Please see the documentation
0
 
0
 == Thanks & Acknowledgements
0
 
0
-If it's not obvious, some of the code for ActsAsUrl is based on Rick Olsen's permalink_fu[http://svn.techno-weenie.net/projects/plugins/permalink_fu/] plugin. Unidecoder is a Ruby port of Sean Burke's Text::Unidecode[http://interglacial.com/~sburke/tpj/as_html/tpj22.html] module for Perl. And, finally, the bulk of String#strip_html in StringExtensions was stolen from Tobias Lütke's Regex in Typo[http://typosphere.org/].
0
+If it's not obvious, some of the code for ActsAsUrl is based on Rick Olsen's permalink_fu[http://svn.techno-weenie.net/projects/plugins/permalink_fu/] plugin. Unidecoder is a Ruby port of Sean Burke's Text::Unidecode[http://interglacial.com/~sburke/tpj/as_html/tpj22.html] module for Perl. And, finally, the bulk of strip_html_tags[link:classes/LuckySneaks/StringExtensions.html#M000005] in StringExtensions was stolen from Tobias Lütke's Regex in Typo[http://typosphere.org/].
0
 
0
 copyright (c) 2008 Lucky Sneaks, released under the MIT license

Comments

    No one has commented yet.