string_master 0.3.19 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile.lock +73 -76
- data/VERSION +1 -1
- data/lib/string_master/string_master.rb +34 -15
- data/spec/lib/string_master/string_master_spec.rb +119 -19
- data/spec/spec_helper.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: db109c39955fd4d1cff51273ffebc3cbc3408e8e1bec70e78f6708c7502edcda
|
4
|
+
data.tar.gz: e76a26c8d32c689e71ee384f855c80a439b127e4e485c352b40725fbde3da9c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3190989568bd6d9488480127b16b37c4aff378a4e418e88674e7e0a743d3cc37738f809f90b12382b364a58d7d4da442397543a51752d336341fc4ffee3fec87
|
7
|
+
data.tar.gz: 1a6cb57073486eac0aeb9d38451f2b74f483014cdb22907c6a7ee142419c521746c0273ea45ddfdd4bfade91a2ae1597b0517bb5d701f4195a7113824edfb200
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
GIT
|
2
2
|
remote: git@github.com:technicalpickles/jeweler.git
|
3
|
-
revision:
|
3
|
+
revision: f1a62a72ca08a0f707a83541414ff9d36c875c90
|
4
4
|
specs:
|
5
|
-
jeweler (2.3.
|
5
|
+
jeweler (2.3.9)
|
6
6
|
builder
|
7
|
-
bundler
|
7
|
+
bundler
|
8
8
|
git (>= 1.2.5)
|
9
|
-
github_api (~> 0.
|
9
|
+
github_api (~> 0.16.0)
|
10
10
|
highline (>= 1.6.15)
|
11
11
|
nokogiri (>= 1.5.10)
|
12
|
-
psych
|
12
|
+
psych
|
13
13
|
rake
|
14
14
|
rdoc
|
15
15
|
semver2
|
@@ -17,94 +17,91 @@ GIT
|
|
17
17
|
GEM
|
18
18
|
remote: http://rubygems.org/
|
19
19
|
specs:
|
20
|
-
actionpack (
|
21
|
-
actionview (=
|
22
|
-
activesupport (=
|
23
|
-
rack (~>
|
24
|
-
rack-test (
|
25
|
-
rails-dom-testing (~>
|
20
|
+
actionpack (5.2.2)
|
21
|
+
actionview (= 5.2.2)
|
22
|
+
activesupport (= 5.2.2)
|
23
|
+
rack (~> 2.0)
|
24
|
+
rack-test (>= 0.6.3)
|
25
|
+
rails-dom-testing (~> 2.0)
|
26
26
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
27
|
-
actionview (
|
28
|
-
activesupport (=
|
27
|
+
actionview (5.2.2)
|
28
|
+
activesupport (= 5.2.2)
|
29
29
|
builder (~> 3.1)
|
30
|
-
|
31
|
-
rails-dom-testing (~>
|
32
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.
|
33
|
-
activesupport (
|
34
|
-
|
35
|
-
|
30
|
+
erubi (~> 1.4)
|
31
|
+
rails-dom-testing (~> 2.0)
|
32
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
33
|
+
activesupport (5.2.2)
|
34
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
35
|
+
i18n (>= 0.7, < 2)
|
36
36
|
minitest (~> 5.1)
|
37
|
-
thread_safe (~> 0.3, >= 0.3.4)
|
38
37
|
tzinfo (~> 1.1)
|
39
|
-
addressable (2.
|
40
|
-
|
41
|
-
|
38
|
+
addressable (2.4.0)
|
39
|
+
builder (3.2.3)
|
40
|
+
concurrent-ruby (1.1.4)
|
41
|
+
crass (1.0.4)
|
42
42
|
descendants_tracker (0.0.4)
|
43
43
|
thread_safe (~> 0.3, >= 0.3.1)
|
44
|
-
diff-lcs (1.
|
45
|
-
|
44
|
+
diff-lcs (1.3)
|
45
|
+
erubi (1.8.0)
|
46
46
|
faraday (0.9.2)
|
47
47
|
multipart-post (>= 1.2, < 3)
|
48
|
-
git (1.
|
49
|
-
github_api (0.
|
50
|
-
addressable (~> 2.
|
51
|
-
descendants_tracker (~> 0.0.
|
48
|
+
git (1.5.0)
|
49
|
+
github_api (0.16.0)
|
50
|
+
addressable (~> 2.4.0)
|
51
|
+
descendants_tracker (~> 0.0.4)
|
52
52
|
faraday (~> 0.8, < 0.10)
|
53
|
-
hashie (>=
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
53
|
+
hashie (>= 3.4)
|
54
|
+
mime-types (>= 1.16, < 3.0)
|
55
|
+
oauth2 (~> 1.0)
|
56
|
+
hashie (3.6.0)
|
57
|
+
highline (2.0.0)
|
58
|
+
i18n (1.3.0)
|
59
|
+
concurrent-ruby (~> 1.0)
|
60
|
+
jwt (2.1.0)
|
61
|
+
loofah (2.2.3)
|
62
|
+
crass (~> 1.0.2)
|
63
63
|
nokogiri (>= 1.5.9)
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
mime-types (2.99.3)
|
65
|
+
mini_portile2 (2.4.0)
|
66
|
+
minitest (5.11.3)
|
67
|
+
multi_json (1.13.1)
|
67
68
|
multi_xml (0.6.0)
|
68
69
|
multipart-post (2.0.0)
|
69
|
-
nokogiri (1.
|
70
|
-
|
71
|
-
oauth2 (1.
|
72
|
-
faraday (>= 0.8, < 0.
|
73
|
-
jwt (
|
70
|
+
nokogiri (1.9.1)
|
71
|
+
mini_portile2 (~> 2.4.0)
|
72
|
+
oauth2 (1.4.1)
|
73
|
+
faraday (>= 0.8, < 0.16.0)
|
74
|
+
jwt (>= 1.0, < 3.0)
|
74
75
|
multi_json (~> 1.3)
|
75
76
|
multi_xml (~> 0.5)
|
76
77
|
rack (>= 1.2, < 3)
|
77
|
-
psych (
|
78
|
-
|
79
|
-
rack (1.
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
rails-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
rspec (3.
|
93
|
-
rspec-
|
94
|
-
|
95
|
-
rspec-mocks (~> 3.3.0)
|
96
|
-
rspec-core (3.3.2)
|
97
|
-
rspec-support (~> 3.3.0)
|
98
|
-
rspec-expectations (3.3.1)
|
78
|
+
psych (3.1.0)
|
79
|
+
rack (2.0.6)
|
80
|
+
rack-test (1.1.0)
|
81
|
+
rack (>= 1.0, < 3)
|
82
|
+
rails-dom-testing (2.0.3)
|
83
|
+
activesupport (>= 4.2.0)
|
84
|
+
nokogiri (>= 1.6)
|
85
|
+
rails-html-sanitizer (1.0.4)
|
86
|
+
loofah (~> 2.2, >= 2.2.2)
|
87
|
+
rake (12.3.2)
|
88
|
+
rdoc (6.1.0)
|
89
|
+
rspec (3.8.0)
|
90
|
+
rspec-core (~> 3.8.0)
|
91
|
+
rspec-expectations (~> 3.8.0)
|
92
|
+
rspec-mocks (~> 3.8.0)
|
93
|
+
rspec-core (3.8.0)
|
94
|
+
rspec-support (~> 3.8.0)
|
95
|
+
rspec-expectations (3.8.2)
|
99
96
|
diff-lcs (>= 1.2.0, < 2.0)
|
100
|
-
rspec-support (~> 3.
|
101
|
-
rspec-mocks (3.
|
97
|
+
rspec-support (~> 3.8.0)
|
98
|
+
rspec-mocks (3.8.0)
|
102
99
|
diff-lcs (>= 1.2.0, < 2.0)
|
103
|
-
rspec-support (~> 3.
|
104
|
-
rspec-support (3.
|
100
|
+
rspec-support (~> 3.8.0)
|
101
|
+
rspec-support (3.8.0)
|
105
102
|
semver2 (3.4.2)
|
106
|
-
thread_safe (0.3.
|
107
|
-
tzinfo (1.2.
|
103
|
+
thread_safe (0.3.6)
|
104
|
+
tzinfo (1.2.5)
|
108
105
|
thread_safe (~> 0.1)
|
109
106
|
|
110
107
|
PLATFORMS
|
@@ -117,4 +114,4 @@ DEPENDENCIES
|
|
117
114
|
rspec
|
118
115
|
|
119
116
|
BUNDLED WITH
|
120
|
-
1.
|
117
|
+
1.16.1
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
@@ -2,7 +2,7 @@ class StringMaster
|
|
2
2
|
|
3
3
|
require "erb"
|
4
4
|
require "action_view"
|
5
|
-
|
5
|
+
|
6
6
|
include ERB::Util
|
7
7
|
include ActionView::Helpers
|
8
8
|
|
@@ -23,7 +23,7 @@ class StringMaster
|
|
23
23
|
text.scan(/<([a-zA-Z0-9]+?)(\s[^>]*)?>/).each { |t| open_tags.unshift(t[0]) }
|
24
24
|
text.scan(/<\/\s*?([a-zA-Z0-9]+)\s*?>/).each { |t| open_tags.slice!(open_tags.index(t[0])) unless open_tags.index(t[0]).nil? }
|
25
25
|
open_tags.each { |t| text += "</#{t}>" unless %w(img br hr).include?(t.to_s) }
|
26
|
-
|
26
|
+
|
27
27
|
@modified_string = text
|
28
28
|
return self
|
29
29
|
end
|
@@ -45,7 +45,7 @@ class StringMaster
|
|
45
45
|
end
|
46
46
|
# Convert all unclosed left tag brackets (<) into <
|
47
47
|
@modified_string.gsub!(/<+([^>]*)\Z/, '<\1')
|
48
|
-
# Convert all unopened right tag brackets (
|
48
|
+
# Convert all unopened right tag brackets (>) into >
|
49
49
|
@modified_string.gsub!(/\A([^<]*)>+/, '\1>')
|
50
50
|
self
|
51
51
|
end
|
@@ -67,16 +67,22 @@ class StringMaster
|
|
67
67
|
def urls_to_links(options = {})
|
68
68
|
wrap_with = options[:wrap_with] || ['','']
|
69
69
|
html_options = options[:html_options] || ''
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
|
71
|
+
# ascii_only option - show URLs with warning about contain non-latin characters
|
72
|
+
if options[:ascii_only]
|
73
|
+
validate_url_contains_ascii(@modified_string, html_options, wrap_with)
|
74
|
+
else
|
75
|
+
@modified_string.gsub!(
|
76
|
+
/(\s|^|\A|\n|\t|\r)((http|https):\/\/.*?)([,.])?(\s|$|\n|\Z|\t|\r|<)/,
|
77
|
+
'\1<a href="\2" ' + html_options + '>\2</a>\4\5'
|
78
|
+
)
|
79
|
+
end
|
74
80
|
self
|
75
81
|
end
|
76
82
|
|
77
83
|
# Breaks words that are longer than 'length'
|
78
84
|
def break_long_words(length=75, break_char=" ", &block)
|
79
|
-
@modified_string.gsub!(
|
85
|
+
@modified_string.gsub!(/https?:\/\/\S+|<a [^>]+>|<img [^>]+>|([^\s^\n^\^^\A^\t^\r<]{#{length},}?)|<\/a>/) do |s|
|
80
86
|
if $1
|
81
87
|
ns = block_given? ? yield($1) : $1
|
82
88
|
last_pos, result_string = 0, ''
|
@@ -118,7 +124,7 @@ class StringMaster
|
|
118
124
|
if line =~ regexp
|
119
125
|
unless code_tag == :opened
|
120
126
|
result.chomp! if options[:remove_newlines]
|
121
|
-
result += "<#{tag}>"
|
127
|
+
result += "<#{tag}>"
|
122
128
|
code_tag = :opened
|
123
129
|
end
|
124
130
|
result += line.sub(regexp, '')
|
@@ -134,11 +140,11 @@ class StringMaster
|
|
134
140
|
result += line
|
135
141
|
end
|
136
142
|
end
|
137
|
-
|
143
|
+
|
138
144
|
# Make sure there's always a closing tag
|
139
145
|
if code_tag == :opened
|
140
146
|
result.chomp!
|
141
|
-
result += "</#{tag}>\n"
|
147
|
+
result += "</#{tag}>\n"
|
142
148
|
end
|
143
149
|
|
144
150
|
@modified_string = result
|
@@ -147,9 +153,9 @@ class StringMaster
|
|
147
153
|
|
148
154
|
# Finds all lines that start with 4 spaces and wraps them into <code> tags.
|
149
155
|
# It also transforms each occurence of 2 or more spaces into an entity,
|
150
|
-
# which is available as a standalone method #preserve_whitespace
|
156
|
+
# which is available as a standalone method #preserve_whitespace
|
151
157
|
def wrap_code
|
152
|
-
wrap_lines("code", /\A\s{4}/, remove_newlines: true)
|
158
|
+
wrap_lines("code", /\A\s{4}/, remove_newlines: true)
|
153
159
|
preserve_whitespace_within("code") # already returns `self`
|
154
160
|
end
|
155
161
|
|
@@ -166,7 +172,7 @@ class StringMaster
|
|
166
172
|
@modified_string.gsub!(/`(.+?)`/m, opening_tag + '\1' + closing_tag)
|
167
173
|
self
|
168
174
|
end
|
169
|
-
|
175
|
+
|
170
176
|
# Same as wrap_inline_code, but spans across multiplelines
|
171
177
|
def wrap_backticks_code(opening_tag="<code>", closing_tag="</code>")
|
172
178
|
@modified_string.gsub!(/`(.+?)`/m, opening_tag + '\1' + closing_tag)
|
@@ -177,5 +183,18 @@ class StringMaster
|
|
177
183
|
modified_string.html_safe
|
178
184
|
end
|
179
185
|
|
180
|
-
|
186
|
+
private
|
181
187
|
|
188
|
+
# Checking references for the presence of non-latin characters. If such
|
189
|
+
# characters are found, the link will not be displayed like html link.
|
190
|
+
# Instead of it, will be returned a warning message.
|
191
|
+
def validate_url_contains_ascii(string, html_options, wrap_with)
|
192
|
+
string.gsub!(/((http|https)[^<\s,]{7,}\b)/im) do |link|
|
193
|
+
if link.ascii_only?
|
194
|
+
"<a href='#{link}'#{html_options}>#{link}</a>"
|
195
|
+
else
|
196
|
+
"[WARNING, URL CONTAINS NON-LATIN LETTERS: #{link}]"
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe StringMaster do
|
4
|
-
|
4
|
+
|
5
5
|
it "closes unclosed tags" do
|
6
6
|
parser = StringMaster.new("<b>Hello,<i>world</b>")
|
7
7
|
parser.close_tags.string.should == '<b>Hello,<i>world</b></i>'
|
@@ -50,33 +50,121 @@ describe StringMaster do
|
|
50
50
|
|
51
51
|
it "makes images of urls that end with .jpg and other image extensions" do
|
52
52
|
parser = StringMaster.new('Hello, this is my photo http://image.com/image.jpg, yeah baby')
|
53
|
-
parser.urls_to_images(:wrap_with => ['<p>', '</p>'], :html_options => 'class="ico"').string.should ==
|
53
|
+
parser.urls_to_images(:wrap_with => ['<p>', '</p>'], :html_options => 'class="ico"').string.should ==
|
54
54
|
'Hello, this is my photo<p><img src="http://image.com/image.jpg" alt="" class="ico"/> </p>yeah baby'
|
55
55
|
|
56
56
|
# use https
|
57
57
|
parser = StringMaster.new('Hello, this is my photo https://image.com/image.jpg, yeah baby')
|
58
|
-
parser.urls_to_images(:wrap_with => ['<p>', '</p>'], :html_options => 'class="ico"').string.should ==
|
58
|
+
parser.urls_to_images(:wrap_with => ['<p>', '</p>'], :html_options => 'class="ico"').string.should ==
|
59
59
|
'Hello, this is my photo<p><img src="https://image.com/image.jpg" alt="" class="ico"/> </p>yeah baby'
|
60
60
|
end
|
61
61
|
|
62
|
-
|
63
|
-
#
|
64
|
-
|
65
|
-
|
66
|
-
'
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
62
|
+
describe 'makes links of urls' do
|
63
|
+
# ascii_only option - show URLs with warning about contain non-latin characters
|
64
|
+
describe 'without ascii_only validate' do
|
65
|
+
# example 1
|
66
|
+
it 'when text include url' do
|
67
|
+
parser = StringMaster.new('Hello, this is my homepage http://url.com, yeah baby')
|
68
|
+
parser.urls_to_links(ascii_only: false).string.should ==
|
69
|
+
'Hello, this is my homepage <a href="http://url.com" >http://url.com</a>, yeah baby'
|
70
|
+
end
|
71
|
+
|
72
|
+
# example 2
|
73
|
+
it 'when text have several urls' do
|
74
|
+
parser = StringMaster.new("http://localhost:3000/\nhttp://localhost:3000/")
|
75
|
+
parser.urls_to_links(ascii_only: false).string.should ==
|
76
|
+
"<a href=\"http://localhost:3000/\" >http://localhost:3000/</a>\n<a href=\"http://localhost:3000/\" >http://localhost:3000/</a>"
|
77
|
+
end
|
78
|
+
|
79
|
+
# example 3
|
80
|
+
it 'when text have html tag and url' do
|
81
|
+
parser = StringMaster.new('http://gyazo.com/a4c16e7a6009f40f29248ad4fed41bd3.png<br>')
|
82
|
+
parser.urls_to_links(ascii_only: false).string.should == '<a href="http://gyazo.com/a4c16e7a6009f40f29248ad4fed41bd3.png" >http://gyazo.com/a4c16e7a6009f40f29248ad4fed41bd3.png</a><br>'
|
83
|
+
end
|
84
|
+
|
85
|
+
# example 4, with https
|
86
|
+
it 'when text include https and url' do
|
87
|
+
parser = StringMaster.new('https://gyazo.com/a4c16e7a6009f40f29248ad4fed41bd3.png<br>')
|
88
|
+
parser.urls_to_links(ascii_only: false).string.should == '<a href="https://gyazo.com/a4c16e7a6009f40f29248ad4fed41bd3.png" >https://gyazo.com/a4c16e7a6009f40f29248ad4fed41bd3.png</a><br>'
|
89
|
+
end
|
90
|
+
|
91
|
+
describe 'when url contain non-latin characters and' do
|
92
|
+
|
93
|
+
it "warning message doesn't shows" do
|
94
|
+
parser = StringMaster.new('http://url.cоm')
|
95
|
+
parser.urls_to_links(ascii_only: false).string.should_not ==
|
96
|
+
'[WARNING, URL CONTAINS NON-LATIN LETTERS: http://url.cоm]'
|
97
|
+
end
|
98
|
+
|
99
|
+
it "non-latin url shows like a url with latin only characters" do
|
100
|
+
parser = StringMaster.new('http://url.cоm')
|
101
|
+
parser.urls_to_links(ascii_only: false).string.should ==
|
102
|
+
'<a href="http://url.cоm" >http://url.cоm</a>'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe 'with ascii_only validate' do
|
108
|
+
# example 1
|
109
|
+
it 'show warning when text include non-latin url' do
|
110
|
+
parser = StringMaster.new('Hello, this is my homepage http://url.cоm, yeah baby')
|
111
|
+
parser.urls_to_links(ascii_only: true).string.should ==
|
112
|
+
'Hello, this is my homepage [WARNING, URL CONTAINS NON-LATIN LETTERS: http://url.cоm], yeah baby'
|
113
|
+
end
|
114
|
+
|
115
|
+
# example 2
|
116
|
+
it 'show warning when text have several non-latin urls' do
|
117
|
+
parser = StringMaster.new("http://lоcalhost:3000\nhttp://lоcalhost:3000")
|
118
|
+
parser.urls_to_links(ascii_only: true).string.should ==
|
119
|
+
"[WARNING, URL CONTAINS NON-LATIN LETTERS: http://lоcalhost:3000]\n[WARNING, URL CONTAINS NON-LATIN LETTERS: http://lоcalhost:3000]"
|
120
|
+
end
|
72
121
|
|
73
|
-
|
74
|
-
|
75
|
-
|
122
|
+
# example 3
|
123
|
+
it 'show warning when text have html tag and non-latin url' do
|
124
|
+
parser = StringMaster.new('http://gyаzo.com/a4c16e7a6009f40f29248ad4fed41bd3.png<br>')
|
125
|
+
parser.urls_to_links(ascii_only: true).string.should == '[WARNING, URL CONTAINS NON-LATIN LETTERS: http://gyаzo.com/a4c16e7a6009f40f29248ad4fed41bd3.png]<br>'
|
126
|
+
end
|
76
127
|
|
77
|
-
|
78
|
-
|
79
|
-
|
128
|
+
# example 4, with https
|
129
|
+
it 'show warning when text include https and non-latin url' do
|
130
|
+
parser = StringMaster.new('https://gyаzo.com/a4c16e7a6009f40f29248ad4fed41bd3.png<br>')
|
131
|
+
parser.urls_to_links(ascii_only: true).string.should == '[WARNING, URL CONTAINS NON-LATIN LETTERS: https://gyаzo.com/a4c16e7a6009f40f29248ad4fed41bd3.png]<br>'
|
132
|
+
end
|
133
|
+
|
134
|
+
describe 'when url contain latin characters and' do
|
135
|
+
it "warning message doesn't shows" do
|
136
|
+
parser = StringMaster.new('http://url.com')
|
137
|
+
parser.urls_to_links(ascii_only: true).string.should_not ==
|
138
|
+
'[WARNING, URL CONTAINS NON-LATIN LETTERS: http://url.cоm]'
|
139
|
+
end
|
140
|
+
|
141
|
+
it "latin url shows correct" do
|
142
|
+
parser = StringMaster.new('http://url.com')
|
143
|
+
parser.urls_to_links(ascii_only: true).string.should ==
|
144
|
+
"<a href='http://url.com'>http://url.com</a>"
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe 'when text contain' do
|
149
|
+
it 'non-latin symbols and latin url' do
|
150
|
+
parser = StringMaster.new('тест http://url.com')
|
151
|
+
parser.urls_to_links(ascii_only: true).string.should ==
|
152
|
+
"тест <a href='http://url.com'>http://url.com</a>"
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'both symbol types and non-latin url' do
|
156
|
+
parser = StringMaster.new('тест non-latin url http://url.cоm')
|
157
|
+
parser.urls_to_links(ascii_only: true).string.should ==
|
158
|
+
"тест non-latin url [WARNING, URL CONTAINS NON-LATIN LETTERS: http://url.cоm]"
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'both symbol types both url types' do
|
162
|
+
parser = StringMaster.new('тест non-latin url http://url.cоm и тест only-latin url https://url.com')
|
163
|
+
parser.urls_to_links(ascii_only: true).string.should ==
|
164
|
+
"тест non-latin url [WARNING, URL CONTAINS NON-LATIN LETTERS: http://url.cоm] и тест only-latin url <a href='https://url.com'>https://url.com</a>"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
80
168
|
end
|
81
169
|
|
82
170
|
it "wraps code in <code> tags" do
|
@@ -143,6 +231,18 @@ WRAPPED_CODE
|
|
143
231
|
parser.break_long_words(5).string.should == '<img src="image.gif" alt="looooooooooooongalt"/>'
|
144
232
|
end
|
145
233
|
|
234
|
+
it "handles http links when attempt to break long words" do
|
235
|
+
string_with_long_link = 'some text http://verylonglink.com other text'
|
236
|
+
parser = StringMaster.new(string_with_long_link)
|
237
|
+
parser.break_long_words(6).string.should == string_with_long_link
|
238
|
+
end
|
239
|
+
|
240
|
+
it "handles http links when attempt to break long words" do
|
241
|
+
string_with_long_link = 'some text https://verylonglink.com other text'
|
242
|
+
parser = StringMaster.new(string_with_long_link)
|
243
|
+
parser.break_long_words(6).string.should == string_with_long_link
|
244
|
+
end
|
245
|
+
|
146
246
|
it "cuts too long string and appends (if specified) characters to its end" do
|
147
247
|
parser = StringMaster.new("This is quite a long text")
|
148
248
|
parser.cut(11, 7, :append => '...').string.should == "This is..."
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: string_master
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Snitko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
113
|
version: '0'
|
114
114
|
requirements: []
|
115
115
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.
|
116
|
+
rubygems_version: 2.7.6
|
117
117
|
signing_key:
|
118
118
|
specification_version: 4
|
119
119
|
summary: Most common string manipulations for a webapp
|