class Parchment::Paragraph

A Paragraph holds several TextRun objects and default formatting for them.

Attributes

default_font_size[R]

(Integer) It’s what it sounds like.

style[R]

(Style) The primary Style for the Paragraph.

text_runs[R]

(Array) All the TextRun children that the Paragraph has.

Public Class Methods

new() click to toggle source

This does not accept any arguments because the primary work for this is done in the formatter’s subclass.

# File lib/parchment/paragraph.rb, line 24
def initialize
  raise MissingFormatterMethodError unless @node
  @default_font_size = @document.default_paragraph_style.font_size
  set_text_runs
end

Public Instance Methods

font_size() click to toggle source

The font size of the Paragraph. Will return the Document’s default font size if not defined.

# File lib/parchment/paragraph.rb, line 33
def font_size
  @style.font_size || @default_font_size
end
text()
Alias for: to_s
to_html() click to toggle source

Return a HTML element String with formatting based on the Paragraph’s properties.

# File lib/parchment/paragraph.rb, line 54
def to_html
  html = ''
  text_runs.each { |text_run| html << text_run.to_html }
  styles = {}
  styles['font-size'] = "#{font_size}pt" unless font_size.nil?
  styles['text-align'] = @style.text_align unless @style.aligned_left?
  html_tag(:p, content: html, styles: styles)
end
to_s() click to toggle source

Output the unformatted Paragraph’s content as a String.

# File lib/parchment/paragraph.rb, line 46
def to_s
  @text_runs.map(&:to_s).join('')
end
Also aliased as: text

Private Instance Methods

set_text_runs() click to toggle source

Parses and creates the TextRun objects that belong to the Paragraph.

*This needs to be defined in the formatter’s Paragraph class.*

# File lib/parchment/paragraph.rb, line 69
def set_text_runs
  raise MissingFormatterMethodError
end