mack_ruby_core_extensions 0.1.26 → 0.1.27
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.
- data/lib/extensions/string.rb +24 -25
- metadata +1 -1
data/lib/extensions/string.rb
CHANGED
@@ -185,31 +185,30 @@ class String
|
|
185
185
|
# http://www.quirksmode.org/oddsandends/wbr.html
|
186
186
|
# http://krijnhoetmer.nl/stuff/css/word-wrap-break-word/
|
187
187
|
# note: if the txt has spaces, this will only try to break up runs of non-space characters longer than "every" characters
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
end
|
188
|
+
def breakify(every = 30)
|
189
|
+
every = 1 if every < 1
|
190
|
+
text = self
|
191
|
+
textile_regex = /([^\"]+\"):([^:]*:[\/\/]{0,1}[^ ]*)/
|
192
|
+
long_regex = /\S{#{every},}/
|
193
|
+
brokentxt = text.gsub(long_regex) do |longword|
|
194
|
+
if longword =~ textile_regex #if the longword is a textile link...ignore and recheck for the link text only
|
195
|
+
textile_link = textile_regex.match(longword)[0]
|
196
|
+
link_text = textile_regex.match(longword)[1]
|
197
|
+
longword = link_text
|
198
|
+
if longword =~ long_regex #link text is long...allow break
|
199
|
+
textile_link = '"' + textile_link unless textile_link[0].to_i == 34 #adds the double quote back if missing from above regex
|
200
|
+
textile_link.scan(/.{1,#{every}}/).join("<wbr/>")
|
201
|
+
else
|
202
|
+
textile_link #the url is what triggered the match...so leave it alone
|
203
|
+
end
|
204
|
+
else
|
205
|
+
longword.scan(/.{1,#{every}}/).join("<wbr/>") #no textile link matched
|
206
|
+
end
|
207
|
+
end
|
208
|
+
#text = %Q[<span style='word-wrap:break-word;wbr:after{content:"\\00200B"}'>#{brokentxt}</span>]
|
209
|
+
#brokentxt.gsub("<wbr/>", "<br />")
|
210
|
+
brokentxt.gsub("<wbr/>", " ")
|
211
|
+
end
|
213
212
|
|
214
213
|
def breakify!(every = 30)
|
215
214
|
self.replace(self.breakify(every))
|