Class: Parchment::Paragraph
- Inherits:
-
Object
- Object
- Parchment::Paragraph
- Includes:
- Helpers
- Defined in:
- lib/parchment/paragraph.rb
Overview
A Paragraph holds several TextRun objects and default formatting for them.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#default_font_size ⇒ Object
readonly
(Integer) It’s what it sounds like.
-
#style ⇒ Object
readonly
(Style) The primary Style for the Paragraph.
-
#text_runs ⇒ Object
readonly
(Array) All the TextRun children that the Paragraph has.
Instance Method Summary collapse
-
#font_size ⇒ Object
The font size of the Paragraph.
-
#initialize ⇒ Paragraph
constructor
This does not accept any arguments because the primary work for this is done in the formatter’s subclass.
-
#to_html ⇒ Object
Return a HTML element String with formatting based on the Paragraph’s properties.
-
#to_s ⇒ Object
(also: #text)
Output the unformatted Paragraph’s content as a String.
Methods included from Helpers
Constructor Details
#initialize ⇒ Paragraph
This does not accept any arguments because the primary work for this is done in the formatter’s subclass.
24 25 26 27 28 |
# 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 |
Instance Attribute Details
#default_font_size ⇒ Object (readonly)
(Integer) It’s what it sounds like.
19 20 21 |
# File 'lib/parchment/paragraph.rb', line 19 def default_font_size @default_font_size end |
#style ⇒ Object (readonly)
(Style) The primary Style for the Paragraph.
13 14 15 |
# File 'lib/parchment/paragraph.rb', line 13 def style @style end |
#text_runs ⇒ Object (readonly)
(Array) All the TextRun children that the Paragraph has.
16 17 18 |
# File 'lib/parchment/paragraph.rb', line 16 def text_runs @text_runs end |
Instance Method Details
#font_size ⇒ Object
The font size of the Paragraph. Will return the Document’s default font size if not defined.
33 34 35 |
# File 'lib/parchment/paragraph.rb', line 33 def font_size @style.font_size || @default_font_size end |
#to_html ⇒ Object
Return a HTML element String with formatting based on the Paragraph’s properties.
54 55 56 57 58 59 60 61 |
# 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 ⇒ Object Also known as: text
Output the unformatted Paragraph’s content as a String.
46 47 48 |
# File 'lib/parchment/paragraph.rb', line 46 def to_s @text_runs.map(&:to_s).join('') end |