Class: Parchment::Document
- Inherits:
-
Object
- Object
- Parchment::Document
- Defined in:
- lib/parchment/document.rb
Overview
Primary Document class.
A Document is the primary “container” for everything necessary to format and display its contents. Holds Paragraph and Style objects.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#default_paragraph_style ⇒ Object
readonly
(Style) A Style referenced when style attributes on the child are not available.
-
#paragraphs ⇒ Object
readonly
(Array) Paragraph objects that belong to the Document.
-
#styles ⇒ Object
readonly
(Array) All the Styles that belong to the Document that other objects (i.e. Paragraphs, TextRuns) can reference and apply.
Instance Method Summary collapse
-
#get_style_by_id(id) ⇒ Object
Returns the Style based on the
id
given. -
#initialize(content_file, styles_file) ⇒ Document
constructor
- content_file
-
(File) The primary content file of the document.
-
#to_html ⇒ Object
Output entire document as a HTML fragment String.
Constructor Details
#initialize(content_file, styles_file) ⇒ Document
- content_file
-
(File) The primary content file of the document.
- styles_file
-
(File) The styles file from the document.
28 29 30 31 32 33 |
# 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 |
Instance Attribute Details
#default_paragraph_style ⇒ Object (readonly)
(Style) A Style referenced when style attributes on the child are not available.
23 24 25 |
# File 'lib/parchment/document.rb', line 23 def default_paragraph_style @default_paragraph_style end |
#paragraphs ⇒ Object (readonly)
(Array) Paragraph objects that belong to the Document.
19 20 21 |
# File 'lib/parchment/document.rb', line 19 def paragraphs @paragraphs end |
#styles ⇒ Object (readonly)
(Array) All the Styles that belong to the Document that other objects (i.e. Paragraphs, TextRuns) can reference and apply.
16 17 18 |
# File 'lib/parchment/document.rb', line 16 def styles @styles end |
Instance Method Details
#get_style_by_id(id) ⇒ Object
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.
– DOCX styles are not implemented yet. ++
- id
-
(String) The unique identifier of the Style.
48 49 50 |
# File 'lib/parchment/document.rb', line 48 def get_style_by_id(id) styles.select { |style| id == style.id }.first end |
#to_html ⇒ Object
Output entire document as a HTML fragment String.
54 55 56 |
# File 'lib/parchment/document.rb', line 54 def to_html paragraphs.map(&:to_html).join("\n") end |