class Parchment::Document
Primary Document
class.¶ ↑
A Document
is the primary “container” for everything necessary to format and display its contents. Holds Paragraph
and Style
objects.
Attributes
(Array) All the Styles that belong to the Document
that other objects (i.e. Paragraphs, TextRuns) can reference and apply.
Public Class Methods
- content_file
-
(File) The primary content file of the document.
- styles_file
-
(File) The styles file from the document.
# File lib/parchment/document.rb, line 28 def initialize(content_file, styles_file) @content_xml = Nokogiri::XML(content_file) @styles_xml = Nokogiri::XML(styles_file) set_styles set_paragraphs end
Public Instance Methods
Returns the Style
based on the id
given.
The XML document formats in particular store their styles in elements with unique identifiers. OpenOffice uses these extensively, relying on them to specify formatting for the text. DOCX
, not so much, but it does have user-defined styles.
- id
-
(String) The unique identifier of the
Style
.
# File lib/parchment/document.rb, line 48 def get_style_by_id(id) styles.select { |style| id == style.id }.first end
Output entire document as a HTML fragment String.
# File lib/parchment/document.rb, line 54 def to_html paragraphs.map(&:to_html).join("\n") end
Private Instance Methods
# File lib/parchment/document.rb, line 73 def set_default_paragraph_style raise MissingFormatterMethodError end
These methods add the Document’s children and default settings.
These methods should be defined in the appropriate class in the formatter module. i.e. Parchment::ODT::Document
will have these.
# File lib/parchment/document.rb, line 65 def set_paragraphs raise MissingFormatterMethodError end
# File lib/parchment/document.rb, line 69 def set_styles raise MissingFormatterMethodError end