string_tools 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +9 -0
- data/lib/string_tools.rb +44 -0
- data/lib/string_tools/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzBlZjNmZjE3MDVkYTFjZmQ2ZjY2YTcwM2I3MTRlMGY2ZmFkYTY1YQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGNjM2E4MzczODYwNDk1YjI1NDBjZmUwZTMyZjg4M2YxMzUyMDgyYg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YWZkYTdhZWFkMjI4OWI3NWQwN2U2M2NlODMzODI3ZDZhMDYxMWU0MTI5YjMz
|
10
|
+
NWNmNjY3YzM4OTlkN2NkYTM1ZGNkZmQxZGU5OTUxYmNiNDY4M2VmMGYwODI2
|
11
|
+
OWI1MThjMDE4YWE5N2UxNDdkMzQyZmNlNTc0NDM1YWEwZDhkM2U=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzU2YjNjYTM3ZTI3NjUwZmU5YjJhYjc1NDU3NGU5NjM0Yjk3ZjdmN2YxODBl
|
14
|
+
MWJlMDI4ODAwNjhmZWNjMmQ1MzcyNDYwYjNkZTBlNWEwMjhiNzdlZjA1MzM0
|
15
|
+
NzhiYTAyOTBjMjJjNDIyZDc5MDJmOGY0YjFmYzRlOTljNDAzMzU=
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
|
2
2
|
#### [Current]
|
3
|
+
|
4
|
+
|
5
|
+
#### v3.0.1
|
6
|
+
* 2015-12-21 [ed85f26](../../commit/ed85f26) - __(Salahutdinov Dmitry)__ Release 3.0.1
|
7
|
+
* 2015-12-16 [d310cbf](../../commit/d310cbf) - __(Maxim Derbenev)__ feature(string_tools): add params concatenation method
|
8
|
+
* 2015-11-12 [f665c33](../../commit/f665c33) - __(Konstantin Lazarev)__ feature: перенос методов очистки от html-разметки
|
9
|
+
|
10
|
+
#### v0.3.0
|
11
|
+
* 2015-10-28 [a3ca238](../../commit/a3ca238) - __(Sergey D)__ Release 0.3.0
|
3
12
|
* 2015-10-26 [62ce841](../../commit/62ce841) - __(Dmitry Bochkarev)__ feature(html): удаление ссылок без хоста по-умолчанию
|
4
13
|
* 2015-10-23 [8fe4384](../../commit/8fe4384) - __(Dmitry Bochkarev)__ fix(sanitizer): нормализация ссылок в юникоде
|
5
14
|
* 2015-10-23 [4017e3d](../../commit/4017e3d) - __(Dmitry Bochkarev)__ fix(html): кириллические ссылки в урлах
|
data/lib/string_tools.rb
CHANGED
@@ -105,6 +105,40 @@ module StringTools
|
|
105
105
|
def clear_control_characters(string)
|
106
106
|
string.tr("\u0000-\u001f", '')
|
107
107
|
end
|
108
|
+
|
109
|
+
# Public: вычищает все html тэги и пробельные символы
|
110
|
+
#
|
111
|
+
# string - String строка для очистки
|
112
|
+
#
|
113
|
+
# Examples
|
114
|
+
#
|
115
|
+
# strip_all_tags_and_entities("<a>ссылка с пробелом</a><p>параграф	с\tтабуляцией</p>")
|
116
|
+
# # => "ссылкаспробелом параграфстабуляцией "
|
117
|
+
#
|
118
|
+
# Returns String
|
119
|
+
def strip_all_tags_and_entities(string)
|
120
|
+
Sanitize.fragment(string.gsub(/&#([0-9]|10|11|12|13);| |\xc2\xa0|\s/, ''))
|
121
|
+
end
|
122
|
+
|
123
|
+
# Public: вычищает html тэги кроме переносов
|
124
|
+
#
|
125
|
+
# string - String строка для очистки
|
126
|
+
#
|
127
|
+
# Examples
|
128
|
+
#
|
129
|
+
# strip_tags_leave_br("<a></a><ul><li>элемент списка</li></ul><p>параграф</p>просто перенос<br>")
|
130
|
+
# # => "<br />элемент списка<br /><br />параграф<br />просто перенос<br>"
|
131
|
+
#
|
132
|
+
# Returns String
|
133
|
+
def strip_tags_leave_br(string)
|
134
|
+
sanitized = Sanitize.fragment(string, remove_contents: %w(style javascript), elements: %w(p ul li br blockquote))
|
135
|
+
|
136
|
+
sanitized.gsub!(/<(p|li|blockquote)[^>]*>/, '')
|
137
|
+
sanitized.gsub!(%r{<(br /|ul[^>]*|/[^>]*)>}, '<br />')
|
138
|
+
sanitized.gsub!(/<br \/>(\s|\302\240)+/, '<br />')
|
139
|
+
|
140
|
+
sanitized
|
141
|
+
end
|
108
142
|
end
|
109
143
|
extend Sanitizing
|
110
144
|
|
@@ -182,4 +216,14 @@ module StringTools
|
|
182
216
|
end
|
183
217
|
end
|
184
218
|
extend SumInWords
|
219
|
+
|
220
|
+
module Uri
|
221
|
+
def add_params_to_url(url, params = nil)
|
222
|
+
uri = Addressable::URI.parse(url)
|
223
|
+
uri = Addressable::URI.parse("http://#{url}") unless uri.scheme
|
224
|
+
uri.query_values = (uri.query_values || {}).merge!(params.stringify_keys) if params.present?
|
225
|
+
uri.normalize.to_s
|
226
|
+
end
|
227
|
+
end
|
228
|
+
extend Uri
|
185
229
|
end
|
data/lib/string_tools/version.rb
CHANGED