~ubuntu-branches/ubuntu/vivid/ruby-stringex/vivid-proposed

« back to all changes in this revision

Viewing changes to README.rdoc

  • Committer: Package Import Robot
  • Author(s): Youhei SASAKI
  • Date: 2014-05-30 01:15:06 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20140530011506-gqmvsja16gwyevdv
Tags: 2.5.2-1
* Imported Upstream version 2.5.2
* Drop obsolete patches
* Update test path: follow upstream changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
  # Inside your model
14
14
  acts_as_url :title
15
15
 
16
 
which will populate the <tt>url</tt> attribute on the object with the converted contents of the <tt>title</tt> attribute. This behavior can be customized by adding the following options to the arguments of the <tt>acts_as_url</tt> method:
 
16
which will populate the <tt>url</tt> attribute on the object with the converted contents of the <tt>title</tt> attribute.
 
17
<tt>acts_as_url</tt> takes the following options:
17
18
 
18
19
<tt>:url_attribute</tt>:: The name of the attribute to use for storing the generated url string.
19
20
                          Default is <tt>:url</tt>
30
31
<tt>:limit</tt>:: If set, will limit length of url generated. Default is nil.
31
32
<tt>:truncate_words</tt>:: Used with :limit. If set to false, the url will be truncated to the last
32
33
                           whole word before the limit was reached. Default is true.
 
34
<tt>:blacklist</tt>:: List of urls that should not be allowed. Default is <tt>%w{new}</tt> [which avoids confusion
 
35
                      on urls like <tt>/documents/new</tt>].
 
36
<tt>:blacklist_policy</tt>:: Proc or lambda defining new naming behavior when blacklisted urls are encountered.
 
37
                             Default converts <tt>/documents/new</tt> to </tt>/documents/new-document</tt>.
 
38
 
33
39
 
34
40
In order to use the generated url attribute, you will probably want to override <tt>to_param</tt> like so, in your Model:
35
41
 
53
59
   "$12 worth of Ruby power".to_url => "12-dollars-worth-of-ruby-power"
54
60
   "10% off if you act now".to_url => "10-percent-off-if-you-act-now"
55
61
 
56
 
   # You don't even wanna trust Iconv for this next part
 
62
   # You dont EVEN wanna rely on Iconv for this next part
57
63
   "kick it en Français".to_url => "kick-it-en-francais"
58
64
   "rock it Español style".to_url => "rock-it-espanol-style"
59
65
   "tell your readers 你好".to_url => "tell-your-readers-ni-hao"
81
87
 
82
88
You probably won't ever need to run Unidecoder by itself. StringExtensions adds String#to_ascii which wraps all of Unidecoder's functionality. For anyone interested, details of the implementation can be read about in the original implementation of Text::Unidecode[http://interglacial.com/~sburke/tpj/as_html/tpj22.html]. Extensive examples can be found in the tests.
83
89
 
84
 
Unidecoder module also provides localization options for Stringex. You can use this functionality by loading either a YAML file or Hash like the following code snippets:
85
 
 
86
 
  # Using a Hash
87
 
  Stringex.localize_from :en => {"é" => "ee"}
88
 
 
89
 
  # Loading from a file. NOTE: The path to file should be absolute.
90
 
  Stringex.localize_from "/path/to/yaml_file"
91
 
 
92
 
In both the YAML and pure Hash implementation, the end result should be a Hash with keys representing the locale and values being another Hash with those keys being the UTF character and the values the transliterated ASCII values. (I hope that made sense.) You can check the documentation for the Unidecoder module for more information about setting locales.
93
 
 
94
90
== StringExtensions
95
91
 
96
92
A small collection of extensions on Ruby's String class. Please see the documentation for StringExtensions module for more information. There's not much to explain about them really.
107
103
 
108
104
  * English (en)
109
105
  * Danish (da)
 
106
  * Swedish (sv)
110
107
  * Dutch (nl)
111
108
  * German (de)
 
109
  * Polish (pl)
112
110
  * Portuguese Brazilian (pt-BR)
113
111
  * Russian (ru)
114
112
 
115
 
 
116
113
You can easily add your own or customize the built-in translations - read here[https://github.com/rsl/stringex/wiki/Localization-of-Stringex-conversions]. If you add a new language, please submit a pull request so we can make it available to other users also.
117
114
 
118
115
If you don't want to use the Stringex built-in translations, you can force Stringex to use English (or another language), regardless what is in your +I18n.locale+. In an initializer, e.g. +config/initializers/stringex.rb+:
131
128
 
132
129
GIANT thanks to the many contributors who have helped make Stringex better and better: http://github.com/rsl/stringex/contributors
133
130
 
134
 
copyright (c) 2008-2013 Lucky Sneaks, released under the MIT license
 
131
copyright (c) 2008-2014 Lucky Sneaks, released under the MIT license