Method: String#breakify

Defined in:
lib/m_string.rb

#breakify(every = 30) ⇒ Object

makes long strings of unbroken characters wrap inside elements (hopefully! tested in Safari, Firefox, and IE for Windows) For documentation about this kind of workaround to this browser compatibility problem please see the following URL’s: www.quirksmode.org/oddsandends/wbr.html krijnhoetmer.nl/stuff/css/word-wrap-break-word/ note: if the txt has spaces, this will only try to break up runs of non-space characters longer than “every” characters



106
107
108
109
110
111
112
113
# File 'lib/m_string.rb', line 106

def breakify(every = 30)
  every = 1 if every < 1
  text = self
  brokentxt = text.gsub(/\S{#{every},}/) { |longword| longword.scan(/.{1,#{every}}/).join("<wbr/>") }
  #text = %Q[<span style='word-wrap:break-word;wbr:after{content:"\\00200B"}'>#{brokentxt}</span>]
  #brokentxt.gsub("<wbr/>", "<br />")
  brokentxt.gsub("<wbr/>", " ")
end