slugity 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ Slugity::Matchers.add :json_string, false, {
2
+ /\\/ => '\\\\\\\\', # barf
3
+ /"/ => '\"'
4
+ }
@@ -25,4 +25,5 @@ module Slugity
25
25
  end
26
26
  end
27
27
 
28
-
28
+ # add additional matchers
29
+ require 'slugity/matchers/json_string'
@@ -1,3 +1,3 @@
1
1
  module Slugity
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
data/lib/slugity.rb CHANGED
@@ -9,14 +9,23 @@ module Slugity
9
9
  # @param matcher [Symbol] the matcher to use
10
10
  # @return [String] the slug version of the provided string
11
11
  def slugity string, matcher=:default
12
- string = Util.trim_string( string ).downcase
12
+ string = stringity(string, matcher).downcase
13
+ string.gsub!( /[^a-z0-9\-\_]/, '' )
14
+ return string
15
+ end
13
16
 
14
- Slugity::Matchers.use(matcher).each do |match,replacement|
17
+ # Converts the given string with the provided matcher
18
+ #
19
+ # @param string [String]
20
+ # @param matcher [Symbol] the matcher to use
21
+ # @return [String] the converted version of the provided string
22
+ def stringity string, matcher=:default
23
+ string = Util.trim_string( string )
24
+
25
+ Slugity::Matchers.use(matcher).each do |match, replacement|
15
26
  string.gsub!( match, replacement )
16
27
  end
17
28
 
18
- string.gsub!( /[^a-z0-9\-\_]/, '' )
19
-
20
29
  return string
21
30
  end
22
31
 
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'slugity'
5
+
6
+
7
+ describe ":json_string matcher" do
8
+ include Slugity
9
+
10
+ test_strings = {
11
+ %q{a "quote" \ or so} => %q{a \"quote\" \\\\ or so}
12
+ }
13
+
14
+ it "correctly escapes strings" do
15
+ test_strings.each do |input,output|
16
+ stringity( input, :json_string ).should == output
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'slugity'
5
+
6
+ describe Slugity do
7
+
8
+ include Slugity
9
+
10
+ describe "#stringity()" do
11
+ it "does not strip unrecognized characters" do
12
+ stringity( "a…‡†i".encode("UTF-8") ).should == "a…‡†i"
13
+ end
14
+ end
15
+
16
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slugity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-19 00:00:00.000000000 Z
12
+ date: 2013-05-22 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! ' Yet another slugging gem, convert a string to a slug with the option
15
15
  for custom mappings. '
@@ -20,16 +20,19 @@ extra_rdoc_files: []
20
20
  files:
21
21
  - lib/slugity/extend_string.rb
22
22
  - lib/slugity/matchers/default.rb
23
+ - lib/slugity/matchers/json_string.rb
23
24
  - lib/slugity/matchers.rb
24
25
  - lib/slugity/utilities.rb
25
26
  - lib/slugity/version.rb
26
27
  - lib/slugity.rb
27
28
  - spec/accented_character_spec.rb
29
+ - spec/matchers/json_string_spec.rb
28
30
  - spec/slugity/matchers_spec.rb
29
31
  - spec/slugity/trim_string_spec.rb
30
32
  - spec/slugity_spec.rb
31
33
  - spec/spec_helper.rb
32
34
  - spec/string_spec.rb
35
+ - spec/stringity_spec.rb
33
36
  homepage: http://github.com/stevenosloan/slugity
34
37
  licenses: []
35
38
  post_install_message:
@@ -56,9 +59,11 @@ specification_version: 3
56
59
  summary: Yet another slugging gem
57
60
  test_files:
58
61
  - spec/accented_character_spec.rb
62
+ - spec/matchers/json_string_spec.rb
59
63
  - spec/slugity/matchers_spec.rb
60
64
  - spec/slugity/trim_string_spec.rb
61
65
  - spec/slugity_spec.rb
62
66
  - spec/spec_helper.rb
63
67
  - spec/string_spec.rb
68
+ - spec/stringity_spec.rb
64
69
  has_rdoc: