typogrowth 0.9.3 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/features/step_definitions/typogrowth_steps.rb +8 -0
- data/features/typogrowth.feature +19 -0
- data/lib/typogrowth/string.rb +6 -2
- data/lib/typogrowth/version.rb +1 -1
- data/lib/typogrowth.rb +21 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2fec1cd3faf12f3d9572b3ce6212e656426276c
|
4
|
+
data.tar.gz: ecc1a510f6fda9e9f40b71a93c61a2c03ecae9e7
|
5
5
|
!binary "U0hBNTEy":
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 421b2b311fe83738d9be9498334abf69005be6085ba30d47be3f41afece162d850f71340c88857c4a0b8ba998cb5c4261192d3013cd69c8b05b354fb570dd758
|
7
|
+
data.tar.gz: c4dd0579e140938e3b63177998ad6bdb5b5e3ea2ac821207c023a4bc90aa5f4eecbf06c0f22d93ba05eda6b36c7ce9870b6068b06d8c77229a3035a39d065fbc
|
@@ -19,6 +19,10 @@ When(/^input string is modified inplace with typo!$/) do
|
|
19
19
|
@typoed.typo!
|
20
20
|
end
|
21
21
|
|
22
|
+
When(/^input string language is determined$/) do
|
23
|
+
@lang = @content.is_ru? ? "ru" : "us"
|
24
|
+
end
|
25
|
+
|
22
26
|
Then(/^neither single nor double quotes are left in the string$/) do
|
23
27
|
@typo.scan(/"|'/).count.should == 0
|
24
28
|
end
|
@@ -38,3 +42,7 @@ end
|
|
38
42
|
Then(/^typoed result should equal to "(.*?)"$/) do |str|
|
39
43
|
@typoed.should == str
|
40
44
|
end
|
45
|
+
|
46
|
+
Then(/^the language should equal to "(.*?)"$/) do |lang|
|
47
|
+
@lang.should == lang
|
48
|
+
end
|
data/features/typogrowth.feature
CHANGED
@@ -67,3 +67,22 @@ Feature: Text is to be typographed (spacing and pubctuation are to be sanitized)
|
|
67
67
|
| input | output |
|
68
68
|
| "This is a cat." | "This is a cat." |
|
69
69
|
|
70
|
+
Scenario Outline: Shadows handling
|
71
|
+
Given the input string is <input>
|
72
|
+
When input string is processed with Typogrowl’s typography parser
|
73
|
+
Then the typoed result should equal to <output>
|
74
|
+
And the call to string’s typo should equal to <output>
|
75
|
+
|
76
|
+
Examples:
|
77
|
+
| input | output |
|
78
|
+
| "<p><img src="http://mudasobwa.ru/i/self.jpg">Here: http://wikipedia.ru</p>" | "<p><img src="http://mudasobwa.ru/i/self.jpg">Here: http://wikipedia.ru</p>" |
|
79
|
+
|
80
|
+
Scenario Outline: Language determining
|
81
|
+
Given the input string is <input>
|
82
|
+
When input string language is determined
|
83
|
+
Then the language should equal to <output>
|
84
|
+
|
85
|
+
Examples:
|
86
|
+
| input | output |
|
87
|
+
| "<p><img src="http://mudasobwa.ru/i/self.jpg">Here: http://wikipedia.ru</p>" | "us" |
|
88
|
+
| "<p><img src="http://mudasobwa.ru/i/self.jpg">Здесь: http://wikipedia.ru</p>" | "ru" |
|
data/lib/typogrowth/string.rb
CHANGED
@@ -7,11 +7,15 @@ class String
|
|
7
7
|
# Typographyes the string and returns a result
|
8
8
|
# See Typogrowth::Parser#parse
|
9
9
|
def typo lang = nil
|
10
|
-
Typogrowth
|
10
|
+
Typogrowth.parse(self, lang: lang ? lang : I18n.locale)
|
11
11
|
end
|
12
12
|
# Typographyes the string inplace
|
13
13
|
# See Typogrowth::Parser#parse!
|
14
14
|
def typo! lang = nil
|
15
|
-
Typogrowth
|
15
|
+
Typogrowth.parse!(self, lang: lang ? lang : I18n.locale)
|
16
|
+
end
|
17
|
+
|
18
|
+
def is_ru? shadows = []
|
19
|
+
Typogrowth.is_ru? self, shadows: shadows
|
16
20
|
end
|
17
21
|
end
|
data/lib/typogrowth/version.rb
CHANGED
data/lib/typogrowth.rb
CHANGED
@@ -122,7 +122,16 @@ module Typogrowth
|
|
122
122
|
}.join(%Q(
|
123
123
|
|
124
124
|
))
|
125
|
-
.gsub(/#{delims.first}(
|
125
|
+
.gsub(/#{delims.first}(.*?)#{delims.last}/m) { |m|
|
126
|
+
Base64.decode64(m).force_encoding('UTF-8')
|
127
|
+
}
|
128
|
+
end
|
129
|
+
|
130
|
+
def is_ru? str, shadows: []
|
131
|
+
clean = @shadows.concat([*shadows]).uniq.inject(str) { |memo, re|
|
132
|
+
memo.gsub(re, '')
|
133
|
+
}
|
134
|
+
clean.scan(/[А-Яа-я]/).size > clean.length / 3
|
126
135
|
end
|
127
136
|
|
128
137
|
def add_shadows re
|
@@ -143,14 +152,19 @@ module Typogrowth
|
|
143
152
|
str.replace self.parse str, lang: lang, shadows: shadows
|
144
153
|
end
|
145
154
|
|
155
|
+
# Out-of-place version of `String` typographing. See #parse!
|
156
|
+
def self.is_ru? str, shadows: []
|
157
|
+
Parser.new.is_ru? str, shadows: shadows
|
158
|
+
end
|
159
|
+
|
146
160
|
DEFAULT_SET = 'typogrowth'
|
147
|
-
HTML_TAG_RE = /<[
|
161
|
+
HTML_TAG_RE = /<[^>]*>/
|
148
162
|
|
149
163
|
def initialize file = nil
|
150
164
|
file = DEFAULT_SET unless file
|
151
165
|
@yaml = YAML.load_file "#{File.dirname(__FILE__)}/config/#{file}.yaml"
|
152
166
|
@yaml.delete(:placeholder)
|
153
|
-
@shadows = [URI.regexp,
|
167
|
+
@shadows = [HTML_TAG_RE, URI.regexp(['ftp', 'http', 'https', 'mailto'])]
|
154
168
|
end
|
155
169
|
|
156
170
|
end
|
@@ -162,5 +176,9 @@ module Typogrowth
|
|
162
176
|
def self.parse! str, lang: :default, shadows: []
|
163
177
|
Parser.parse! str, lang: lang, shadows: shadows
|
164
178
|
end
|
179
|
+
|
180
|
+
def self.is_ru? str, shadows: []
|
181
|
+
Parser.is_ru? str, shadows: shadows
|
182
|
+
end
|
165
183
|
end
|
166
184
|
|