Class: Uniword::HtmlImporter
- Inherits:
-
Object
- Object
- Uniword::HtmlImporter
- Defined in:
- lib/uniword/html_importer.rb
Overview
Imports HTML content and converts it to OOXML paragraphs or documents.
Instance Attribute Summary collapse
-
#html ⇒ String
readonly
The HTML content being imported.
Class Method Summary collapse
-
.import(html) ⇒ Array<Uniword::Wordprocessingml::Paragraph>
Class method: Import HTML content.
Instance Method Summary collapse
-
#import(html = nil) ⇒ Array<Uniword::Wordprocessingml::Paragraph>
Import HTML content and convert to OOXML paragraphs.
-
#initialize(html = nil) ⇒ HtmlImporter
constructor
Create a new HtmlImporter instance.
-
#to_document ⇒ Uniword::Wordprocessingml::DocumentRoot
Convert imported HTML to a DocumentRoot.
Constructor Details
#initialize(html = nil) ⇒ HtmlImporter
Create a new HtmlImporter instance
22 23 24 |
# File 'lib/uniword/html_importer.rb', line 22 def initialize(html = nil) @html = html end |
Instance Attribute Details
#html ⇒ String (readonly)
Returns The HTML content being imported.
17 18 19 |
# File 'lib/uniword/html_importer.rb', line 17 def html @html end |
Class Method Details
.import(html) ⇒ Array<Uniword::Wordprocessingml::Paragraph>
Class method: Import HTML content
51 52 53 |
# File 'lib/uniword/html_importer.rb', line 51 def self.import(html) new.import(html) end |
Instance Method Details
#import(html = nil) ⇒ Array<Uniword::Wordprocessingml::Paragraph>
Import HTML content and convert to OOXML paragraphs
30 31 32 33 |
# File 'lib/uniword/html_importer.rb', line 30 def import(html = nil) content = html || @html Transformation::HtmlToOoxmlConverter.html_to_paragraphs(content) end |
#to_document ⇒ Uniword::Wordprocessingml::DocumentRoot
Convert imported HTML to a DocumentRoot
38 39 40 41 42 43 44 45 |
# File 'lib/uniword/html_importer.rb', line 38 def to_document doc = Wordprocessingml::DocumentRoot.new paragraphs = import paragraphs.each do |para| doc.body.paragraphs << para end doc end |