typogrowth 0.9.3 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
- metadata.gz: d96c37d2c10f0fc9f73caaeda6be11910a725c7d
4
- data.tar.gz: abc183314746913a04adca10b88e380e75981a61
3
+ metadata.gz: b2fec1cd3faf12f3d9572b3ce6212e656426276c
4
+ data.tar.gz: ecc1a510f6fda9e9f40b71a93c61a2c03ecae9e7
5
5
  !binary "U0hBNTEy":
6
- metadata.gz: 9277400dec9a0f43219676988fdac4dfc6e1b257537a9bdf8ba2218abcdf35c473d223f9ed9a07c02b14838687ca9aee923bf380bf3f5047e50534809ef016b2
7
- data.tar.gz: 5fd258973bb34862e20c77a0ec8a6b203bb5d60be67ee9736e3a5b90107b21d63625507b5dfd8bac2bb9c7acd9cc40d944c57895de06b533fa9caba2cdba613b
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
@@ -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" |
@@ -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::Parser.parse(self, lang: lang ? lang : I18n.locale)
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::Parser.parse!(self, lang: lang ? lang : I18n.locale)
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
@@ -1,3 +1,3 @@
1
1
  module Typogrowth
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.5"
3
3
  end
data/lib/typogrowth.rb CHANGED
@@ -122,7 +122,16 @@ module Typogrowth
122
122
  }.join(%Q(
123
123
 
124
124
  ))
125
- .gsub(/#{delims.first}(.*)#{delims.last}/m) { |m| Base64.decode64 m }
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 = /<[A-Za-z]+(.*?)>/
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, HTML_TAG_RE]
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typogrowth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexei Matyushkin