sterile 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,9 +1,10 @@
1
1
  source "http://rubygems.org"
2
2
  gemspec
3
3
 
4
- # group :test do
5
- # gem "autotest"
6
- # gem "mynyml-redgreen"
7
- # gem "awesome_print"
8
- # gem "rake"
9
- # end
4
+ group :test do
5
+ gem "minitest"
6
+ gem "purdytest"
7
+ gem "autotest"
8
+ gem "awesome_print"
9
+ gem "rake", "0.8.7"
10
+ end
data/Gemfile.lock CHANGED
@@ -1,14 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sterile (1.0.2)
4
+ sterile (1.0.3)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
+ ZenTest (4.5.0)
10
+ autotest (4.4.6)
11
+ ZenTest (>= 4.4.1)
12
+ awesome_print (0.4.0)
13
+ minitest (2.2.2)
14
+ purdytest (1.0.0)
15
+ minitest (~> 2.2)
16
+ rake (0.8.7)
9
17
 
10
18
  PLATFORMS
11
19
  ruby
12
20
 
13
21
  DEPENDENCIES
22
+ autotest
23
+ awesome_print
24
+ minitest
25
+ purdytest
26
+ rake (= 0.8.7)
14
27
  sterile!
data/README.markdown CHANGED
@@ -3,10 +3,98 @@ Sterile
3
3
 
4
4
  Sterilize your strings! Transliterate, generate slugs, smart format, strip tags, encode/decode entities and more.
5
5
 
6
- Examples
6
+ Usage
7
+ -----
8
+
9
+ Sterile provides functionality both as class methods on the Sterile module and as extensions to the String class. Each function also has a "bang" version to replace the string in place.
10
+
11
+ Sterile.transliterate("šţɽĩɳģ") # => "string"
12
+
13
+ "šţɽĩɳģ".transliterate # => "string"
14
+
15
+ str = "šţɽĩɳģ"
16
+ str.transliterate!
17
+ str == "string" # => true
18
+
19
+ Transliterate
20
+ -------------
21
+
22
+ Transliterate Unicode [and accented ASCII] characters to their plain-text ASCII equivalents. This is based on data from the stringex gem (https://github.com/rsl/stringex) which is in turn a port of Perl's Unidecode and ostensibly provides superior results to iconv. The optical conversion data is based on work by Eric Boehs at https://github.com/ericboehs/to_slug
23
+
24
+ "šţɽĩɳģ".transliterate # => "string"
25
+
26
+ Passing an option of :optical => true will prefer optical mapping instead of more pedantic matches. The optical dataset is incomplete, but will fall back to the pedantic match if missing.
27
+
28
+ Smart Format
29
+ ------------
30
+
31
+ Format text with proper "curly" quotes, m-dashes, copyright, trademark, etc.
32
+
33
+ q{"He said, 'Away with you, Drake!'"}.smart_format
34
+ # => “He said, ‘Away with you, Drake!’”
35
+
36
+ You can also use smart formatting with HTML:
37
+
38
+ %q{"He said, <b>'Away with you, Drake!'</b>"}.smart_format_tags
39
+ # => "&ldquo;He said, <b>&lsquo;Away with you, Drake!&rsquo;</b>&ldquo;"
40
+
41
+ Entities
7
42
  --------
8
43
 
9
- TODO
44
+ Turn Unicode characters into their HTML equivilents. If a valid HTML entity is not possible, it will create a numeric entity.
45
+
46
+ q{“Economy Hits Bottom,” ran the headline}.encode_entities # => "&ldquo;Economy Hits Bottom,&rdquo; ran the headline"
47
+
48
+ Turn HTML entities into unicode characters:
49
+
50
+ "&ldquo;Economy Hits Bottom,&rdquo; ran the headline".decode_entities # => "“Economy Hits Bottom,” ran the headline"
51
+
52
+ Titlecase
53
+ ---------
54
+
55
+ Format text appropriately for titles. This method is much smarter than ActiveSupport's titlecase. The algorithm is based on work done by John Gruber et al (http://daringfireball.net/2008/08/title_case_update). It gets closer to the AP standard for title capitalization, including proper support for small words and handles a variety of edge cases.
56
+
57
+ "Q&A with Steve Jobs: 'That's what happens in technology'".titlecase
58
+ # => "Q&A With Steve Jobs: 'That's What Happens in Technology'"
59
+
60
+ "Small word at end is nothing to be afraid of".titleize # alias for titlecase
61
+ # => "Small Word at End Is Nothing to Be Afraid Of"
62
+
63
+ Strip Tags
64
+ ----------
65
+
66
+ Remove HTML/XML tags from text. Also strips out comments, PHP and ERB style tags.
67
+
68
+ 'Visit our <a href="http://example.com">website!</a>'.strip_tags # => "Visit our website!"
69
+
70
+ Miscellaneous
71
+ -------------
72
+
73
+ Transliterate to ASCII, downcase and format for URL permalink/slug by stripping out all non-alphanumeric characters and replacing spaces with a delimiter (defaults to '-', configured by :delimiter option).
74
+
75
+ "Hello World!".sluggerize # => "hello-world"
76
+ "Hello World!".to_slug # => "hello-world"
77
+
78
+ Transliterate to ASCII and strip out any HTML/XML tags.
79
+
80
+ "<b>nåsty</b>".sterilize # => "nasty"
81
+
82
+ Trim whitespace from start and end of string and remove any redundant whitespace in between.
83
+
84
+ " Hello world! ".transliterate # => "Hello world!"
85
+
86
+ Iterate over all text in between HTML/XML tags and yield text to a block, replace by what the block returns.
87
+
88
+ "Only <i>uppercase</i> the <b>text</b> in this".gsub_tags { |t| t.upcase }
89
+
90
+ Iterate over all text in between HTML/XML tags and yield to a block.
91
+
92
+ "Only <i>output</i> the <b>text</b> in this".scan_tags { |t| puts t }
93
+
94
+ Warning / To Do
95
+ ---------------
96
+
97
+ All the *_tags functions are based on a regular expressions. Yes, I know this is [wrong](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454) and I plan to using a proper parser for it in the future.
10
98
 
11
99
  Installation
12
100
  ------------
@@ -18,5 +106,5 @@ Install with RubyGems:
18
106
  License
19
107
  -------
20
108
 
21
- Copyright (c) 2011 Patrick Hogan, released under the MIT License.
109
+ Copyright (c) 2011 Patrick Hogan, released under the MIT License.
22
110
  http://www.opensource.org/licenses/mit-license
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Sterile
4
- VERSION = "1.0.2"
4
+ VERSION = "1.0.3"
5
5
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: sterile
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.2
5
+ version: 1.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Patrick Hogan
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-03 00:00:00 -05:00
13
+ date: 2011-07-05 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -59,12 +59,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
+ hash: -2175326715417753409
63
+ segments:
64
+ - 0
62
65
  version: "0"
63
66
  required_rubygems_version: !ruby/object:Gem::Requirement
64
67
  none: false
65
68
  requirements:
66
69
  - - ">="
67
70
  - !ruby/object:Gem::Version
71
+ hash: -2175326715417753409
72
+ segments:
73
+ - 0
68
74
  version: "0"
69
75
  requirements: []
70
76