Class: Coradoc::Html::Static

Inherits:
ConverterBase show all
Defined in:
lib/coradoc/html/static.rb

Overview

Static HTML converter

Converts CoreModel documents to static HTML5 output. This converter produces traditional HTML with external or embedded CSS/JS.

Examples:

Basic usage

doc = Coradoc.parse_file('document.adoc')
html = Coradoc::Html::Static.convert(doc)

With configuration

config = Coradoc::Html::Static::Configuration.new(
  css_theme: :professional,
  include_toc: true,
  theme_toggle: true
)
html = Coradoc::Html::Static.convert(doc, config)

Write to file

Coradoc::Html::Static.to_file(doc, 'output.html', config)

Defined Under Namespace

Classes: Configuration

Instance Attribute Summary

Attributes inherited from ConverterBase

#config, #document

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ConverterBase

convert, #converter_name, #initialize, #to_file, to_file

Constructor Details

This class inherits a constructor from Coradoc::Html::ConverterBase

Class Method Details

.processor_execute(input, options = {}) ⇒ Hash

Output processor interface: execute the conversion

Parameters:

  • input (Hash)

    Input from the converter (contains document)

  • options (Hash) (defaults to: {})

    Output options

Returns:

  • (Hash)

    Hash with nil => HTML output



284
285
286
287
288
289
290
# File 'lib/coradoc/html/static.rb', line 284

def self.processor_execute(input, options = {})
  # Handle hash input from converter pipeline
  document = input.is_a?(Hash) ? (input[:document] || input.values.first) : input
  html = convert(document, options)
  # Return in format expected by converter (hash with filename => content)
  { nil => html }
end

.processor_idSymbol

Output processor interface: unique identifier

Returns:

  • (Symbol)

    Processor identifier



267
268
269
# File 'lib/coradoc/html/static.rb', line 267

def self.processor_id
  :html_static
end

.processor_match?(filename) ⇒ Boolean

Output processor interface: check if this processor handles the file

Parameters:

  • filename (String)

    Output filename

Returns:

  • (Boolean)

    true if this processor can handle the file



275
276
277
# File 'lib/coradoc/html/static.rb', line 275

def self.processor_match?(filename)
  filename.downcase.end_with?('.html', '.htm')
end

Instance Method Details

#convertString

Convert document to static HTML

Returns:

  • (String)

    Complete HTML5 document or fragment (if embedded mode)



192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/coradoc/html/static.rb', line 192

def convert
  # Build options hash for ClassicRenderer
  options = build_renderer_options

  # Use ClassicRenderer to generate HTML
  renderer = Html::Theme::ClassicRenderer.new(@document, options)

  if @config.embedded
    renderer.render
  else
    renderer.render_html5
  end
end