mack_ruby_core_extensions 0.1.26 → 0.1.27

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/extensions/string.rb +24 -25
  2. metadata +1 -1
@@ -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
- 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
206
- matched
207
- end
208
- end
209
- #text = %Q[<span style='word-wrap:break-word;wbr:after{content:"\\00200B"}'>#{brokentxt}</span>]
210
- #brokentxt.gsub("<wbr/>", "<br />")
211
- brokentxt.gsub("<wbr/>", " ")
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))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mack_ruby_core_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.26
4
+ version: 0.1.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - markbates