Class: Coradoc::Html::ConverterBase Abstract
- Inherits:
-
Object
- Object
- Coradoc::Html::ConverterBase
- Defined in:
- lib/coradoc/html/converter_base.rb
Overview
Subclass and implement #convert to create a custom converter
Abstract base class for HTML output converters
This class defines the interface that all HTML output converters must implement. It provides common functionality for document validation, configuration building, and HTML output generation.
Defined Under Namespace
Classes: ConfigurationBase, UnsupportedDocumentError, ValidationError
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Class Method Summary collapse
-
.convert(document, config = {}) ⇒ String
Class method to convert a document.
-
.to_file(document, output_path, config = {}) ⇒ String
Class method to convert and write to file.
Instance Method Summary collapse
-
#convert ⇒ String
abstract
Convert the document to HTML.
-
#initialize(document, config = {}) ⇒ ConverterBase
constructor
Initialize a new converter instance.
-
#to_file(output_path) ⇒ String
Convert and write to file.
Constructor Details
#initialize(document, config = {}) ⇒ ConverterBase
Initialize a new converter instance
48 49 50 51 |
# File 'lib/coradoc/html/converter_base.rb', line 48 def initialize(document, config = {}) @document = validate_input(document) @config = build_config(config) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
41 42 43 |
# File 'lib/coradoc/html/converter_base.rb', line 41 def config @config end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
41 42 43 |
# File 'lib/coradoc/html/converter_base.rb', line 41 def document @document end |
Class Method Details
.convert(document, config = {}) ⇒ String
Class method to convert a document
84 85 86 |
# File 'lib/coradoc/html/converter_base.rb', line 84 def self.convert(document, config = {}) new(document, config).convert end |
.to_file(document, output_path, config = {}) ⇒ String
Class method to convert and write to file
94 95 96 |
# File 'lib/coradoc/html/converter_base.rb', line 94 def self.to_file(document, output_path, config = {}) new(document, config).to_file(output_path) end |
Instance Method Details
#convert ⇒ String
Subclasses must implement this method
Convert the document to HTML
58 59 60 61 |
# File 'lib/coradoc/html/converter_base.rb', line 58 def convert raise NotImplementedError, "#{self.class.name} must implement #convert method" end |
#to_file(output_path) ⇒ String
Convert and write to file
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/coradoc/html/converter_base.rb', line 67 def to_file(output_path) html = convert # Ensure parent directory exists output_dir = File.dirname(output_path) FileUtils.mkdir_p(output_dir) unless output_dir == '.' File.write(output_path, html) output_path end |