threedaymonk-l10nizer 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/l10nizer/keygen.rb +7 -1
- data/lib/l10nizer/version.rb +1 -1
- data/test/test_key_generator.rb +10 -2
- metadata +1 -1
data/lib/l10nizer/keygen.rb
CHANGED
@@ -27,7 +27,13 @@ module L10nizer
|
|
27
27
|
|
28
28
|
def make_safe(string)
|
29
29
|
return nil if string.nil?
|
30
|
-
safe = string.
|
30
|
+
safe = string.
|
31
|
+
downcase.
|
32
|
+
gsub(/&[a-z0-9]{1,20};/, ""). # entities
|
33
|
+
gsub(/<[^>]*>/, ""). # html
|
34
|
+
gsub(/[^a-z0-9]+/, "_"). # non alphanumeric
|
35
|
+
slice(0, 40).
|
36
|
+
gsub(/^_|_$/, "") # leading/trailing _
|
31
37
|
safe = "unknown" if safe.empty?
|
32
38
|
safe
|
33
39
|
end
|
data/lib/l10nizer/version.rb
CHANGED
data/test/test_key_generator.rb
CHANGED
@@ -17,7 +17,7 @@ class KeyGeneratorTest < Test::Unit::TestCase
|
|
17
17
|
|
18
18
|
should "truncate exceptionally long keys" do
|
19
19
|
long = "blah_" * 20
|
20
|
-
short =
|
20
|
+
short = "blah_blah_blah_blah_blah_blah_blah_blah"
|
21
21
|
assert_equal short, @keygen.call(long)
|
22
22
|
end
|
23
23
|
|
@@ -31,9 +31,17 @@ class KeyGeneratorTest < Test::Unit::TestCase
|
|
31
31
|
assert_equal "a_thing_2", @keygen.call("A Thing")
|
32
32
|
end
|
33
33
|
|
34
|
-
should "
|
34
|
+
should "generate non empty keys for punctuation" do
|
35
35
|
assert_not_equal "", @keygen.call("<>!@#%#.,")
|
36
36
|
end
|
37
|
+
|
38
|
+
should "skip entities in keys" do
|
39
|
+
assert_equal "foo_bar", @keygen.call("foo ' bar")
|
40
|
+
end
|
41
|
+
|
42
|
+
should "skip inline markup in keys" do
|
43
|
+
assert_equal "foo_bar", @keygen.call("foo <strong>bar</strong>")
|
44
|
+
end
|
37
45
|
end
|
38
46
|
|
39
47
|
context "with namespacing" do
|