instance method format_paragraph

Ruby on Rails 3.1.12

Since v3.1.12

Available in: v3.1.12 v3.2.22.5 v4.0.13 v4.1.16 v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

format_paragraph(text, len = 72, indent = 2)

Returns text wrapped at len columns and indented indent spaces.

Examples

my_text = "Here is a sample text with more than 40 characters"

format_paragraph(my_text, 25, 4)
# => "    Here is a sample text with\n    more than 40 characters"

Parameters

text req
len opt = 72
indent opt = 2
Source
# File actionmailer/lib/action_mailer/mail_helper.rb, line 40
    def format_paragraph(text, len = 72, indent = 2)
      sentences = [[]]

      text.split.each do |word|
        if (sentences.last + [word]).join(' ').length > len
          sentences << [word]
        else
          sentences.last << word
        end
      end

      sentences.map { |sentence|
        "#{" " * indent}#{sentence.join(' ')}"
      }.join "\n"
    end

Defined in actionmailer/lib/action_mailer/mail_helper.rb line 40 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionMailer::MailHelper

Type at least 2 characters to search.

↑↓ navigate · open · esc close