private Method

Format.__format(to_wrap)

There's no documentation for this item.

Source Code

# File action_mailer/vendor/text-format-0.6.3/text/format.rb, line 592
def __format(to_wrap) #:nodoc:
  words = to_wrap.split(/\s+/).compact
  words.shift if words[0].nil? or words[0].empty?
  to_wrap = []

  abbrev = false
  width = @columns - @first_indent - @left_margin - @right_margin
  indent_str = ' ' * @first_indent
  first_line = true
  line = words.shift
  abbrev = __is_abbrev(line) unless line.nil? || line.empty?

  while w = words.shift
    if (w.size + line.size < (width - 1)) ||
       ((line !~ LEQ_RE || abbrev) && (w.size + line.size < width))
      line << " " if (line =~ LEQ_RE) && (not abbrev)
      line << " #{w}"
    else
      line, w = __do_break(line, w) if @nobreak
      line, w = __do_hyphenate(line, w, width) if @hard_margins
      if w.index(/\s+/)
        w, *w2 = w.split(/\s+/)
        words.unshift(w2)
        words.flatten!
      end
      to_wrap << __make_line(line, indent_str, width, w.nil?) unless line.nil?
      if first_line
        first_line = false
        width = @columns - @body_indent - @left_margin - @right_margin
        indent_str = ' ' * @body_indent
      end
      line = w
    end

    abbrev = __is_abbrev(w) unless w.nil?
  end

  loop do
    break if line.nil? or line.empty?
    line, w = __do_hyphenate(line, w, width) if @hard_margins
    to_wrap << __make_line(line, indent_str, width, w.nil?)
    line = w
  end

  if (@tag_paragraph && (to_wrap.size > 0)) then
    clr = %r{`(\w+)'}.match([caller(1)].flatten[0])[1]
    clr = "" if clr.nil?

    if ((not @tag_text[0].nil?) && (@tag_cur.size < 1) &&
        (clr != "__paragraphs")) then
      @tag_cur = @tag_text[0]
    end

    fchar = /(\S)/.match(to_wrap[0])[1]
    white = to_wrap[0].index(fchar)
    if ((white - @left_margin - 1) > @tag_cur.size) then
      white = @tag_cur.size + @left_margin
      to_wrap[0].gsub!(/^ {#{white}}/, "#{' ' * @left_margin}#{@tag_cur}")
    else
      to_wrap.unshift("#{' ' * @left_margin}#{@tag_cur}\n")
    end
  end
  to_wrap.join('')
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.