Class: Coradoc::Html::Theme::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/coradoc/html/theme/base.rb

Overview

This class is abstract.

Subclass and implement #render to create a custom theme

Abstract base class for all HTML themes

This class defines the interface that all theme renderers must implement. Themes are responsible for converting Coradoc document models to HTML output.

Direct Known Subclasses

ClassicRenderer, ModernRenderer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document, options = {}) ⇒ Base

Initialize a new theme instance

Parameters:

  • document (Coradoc::CoreModel::StructuralElement)

    The document to render

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

    Rendering options



21
22
23
24
# File 'lib/coradoc/html/theme/base.rb', line 21

def initialize(document, options = {})
  @document = document
  @options = options
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



15
16
17
# File 'lib/coradoc/html/theme/base.rb', line 15

def document
  @document
end

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/coradoc/html/theme/base.rb', line 15

def options
  @options
end

Instance Method Details

#renderString

This method is abstract.

Render the document to HTML

This method must be implemented by subclasses.

Returns:

  • (String)

    The rendered HTML content

Raises:

  • (NotImplementedError)


32
33
34
35
# File 'lib/coradoc/html/theme/base.rb', line 32

def render
  raise NotImplementedError,
        "#{self.class.name} must implement #render method"
end

#render_html5String

Render the complete HTML5 document

Returns:

  • (String)

    Complete HTML5 document



40
41
42
43
# File 'lib/coradoc/html/theme/base.rb', line 40

def render_html5
  html_body = render
  build_html5_document(html_body)
end

#supported_featuresArray<Symbol>

List of features supported by this theme

Subclasses can override to declare supported features.

Returns:

  • (Array<Symbol>)

    List of supported features



68
69
70
# File 'lib/coradoc/html/theme/base.rb', line 68

def supported_features
  []
end

#supports?(feature) ⇒ Boolean

Check if this theme supports a specific feature

Parameters:

  • feature (Symbol)

    Feature to check (e.g., :dark_mode, :interactive_toc)

Returns:

  • (Boolean)

    true if the feature is supported



59
60
61
# File 'lib/coradoc/html/theme/base.rb', line 59

def supports?(feature)
  supported_features.include?(feature)
end

#theme_nameSymbol

Get the theme name

Returns:

  • (Symbol)

    Theme name (e.g., :classic, :modern)



48
49
50
51
52
53
# File 'lib/coradoc/html/theme/base.rb', line 48

def theme_name
  @theme_name ||= self.class.name.split('::').last
                      .gsub(/Renderer$/, '')
                      .downcase
                      .to_sym
end