private Method

Format.__do_hyphenate(line, next_line, width)

There's no documentation for this item.

Source Code

# File action_mailer/vendor/text-format-0.6.3/text/format.rb, line 743
def __do_hyphenate(line, next_line, width) #:nodoc:
  rline = line.dup rescue line
  rnext = next_line.dup rescue next_line
  loop do
    if rline.size == width
      break
    elsif rline.size > width
      words = rline.strip.split(/\s+/)
      word = words[-1].dup
      size = width - rline.size + word.size
      if (size <= 0)
        words[-1] = nil
        rline = words.join(' ').strip
        rnext = "#{word} #{rnext}".strip
        next
      end

      first = rest = nil

      if ((@split_rules & SPLIT_HYPHENATION) != 0)
        if @hyphenator_arity == 2
          first, rest = @hyphenator.hyphenate_to(word, size)
        else
          first, rest = @hyphenator.hyphenate_to(word, size, self)
        end
      end

      if ((@split_rules & SPLIT_CONTINUATION) != 0) and first.nil?
        first, rest = self.hyphenate_to(word, size)
      end

      if ((@split_rules & SPLIT_FIXED) != 0) and first.nil?
        first.nil? or @split_rules == SPLIT_FIXED
        first, rest = __do_split_word(word, size)
      end

      if first.nil?
        words[-1] = nil
        rest = word
      else
        words[-1] = first
        @split_words << SplitWord.new(word, first, rest)
      end
      rline = words.join(' ').strip
      rnext = "#{rest} #{rnext}".strip
      break
    else
      break if rnext.nil? or rnext.empty? or rline.nil? or rline.empty?
      words = rnext.split(/\s+/)
      word = words.shift
      size = width - rline.size - 1

      if (size <= 0)
        rnext = "#{word} #{words.join(' ')}".strip
        break
      end

      first = rest = nil

      if ((@split_rules & SPLIT_HYPHENATION) != 0)
        if @hyphenator_arity == 2
          first, rest = @hyphenator.hyphenate_to(word, size)
        else
          first, rest = @hyphenator.hyphenate_to(word, size, self)
        end
      end

      first, rest = self.hyphenate_to(word, size) if ((@split_rules & SPLIT_CONTINUATION) != 0) and first.nil?

      first, rest = __do_split_word(word, size) if ((@split_rules & SPLIT_FIXED) != 0) and first.nil?

      if (rline.size + (first ? first.size : 0)) < width
        @split_words << SplitWord.new(word, first, rest)
        rline = "#{rline} #{first}".strip
        rnext = "#{rest} #{words.join(' ')}".strip
      end
      break
    end
  end
  [rline, rnext]
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.