Module: Coradoc::Html
- Defined in:
- lib/coradoc/html/input.rb,
lib/coradoc/html.rb,
lib/coradoc/html/spa.rb,
lib/coradoc/html/base.rb,
lib/coradoc/html/theme.rb,
lib/coradoc/html/config.rb,
lib/coradoc/html/entity.rb,
lib/coradoc/html/static.rb,
lib/coradoc/html/version.rb,
lib/coradoc/html/renderer.rb,
lib/coradoc/html/theme/base.rb,
lib/coradoc/html/converter_base.rb,
lib/coradoc/html/theme/registry.rb,
lib/coradoc/html/converters/base.rb,
lib/coradoc/html/converters/bold.rb,
lib/coradoc/html/converters/link.rb,
lib/coradoc/html/converters/open.rb,
lib/coradoc/html/converters/span.rb,
lib/coradoc/html/converters/term.rb,
lib/coradoc/html/element_mapping.rb,
lib/coradoc/html/template_config.rb,
lib/coradoc/html/converters/audio.rb,
lib/coradoc/html/converters/break.rb,
lib/coradoc/html/converters/quote.rb,
lib/coradoc/html/converters/table.rb,
lib/coradoc/html/converters/verse.rb,
lib/coradoc/html/converters/video.rb,
lib/coradoc/html/template_helpers.rb,
lib/coradoc/html/template_locator.rb,
lib/coradoc/html/converters/italic.rb,
lib/coradoc/html/converters/source.rb,
lib/coradoc/html/converters/example.rb,
lib/coradoc/html/converters/include.rb,
lib/coradoc/html/converters/listing.rb,
lib/coradoc/html/converters/literal.rb,
lib/coradoc/html/converters/ordered.rb,
lib/coradoc/html/converters/section.rb,
lib/coradoc/html/converters/sidebar.rb,
lib/coradoc/html/converters/document.rb,
lib/coradoc/html/converters/attribute.rb,
lib/coradoc/html/converters/highlight.rb,
lib/coradoc/html/converters/list_item.rb,
lib/coradoc/html/converters/monospace.rb,
lib/coradoc/html/converters/paragraph.rb,
lib/coradoc/html/converters/subscript.rb,
lib/coradoc/html/converters/table_row.rb,
lib/coradoc/html/converters/underline.rb,
lib/coradoc/html/converters/unordered.rb,
lib/coradoc/html/converters/admonition.rb,
lib/coradoc/html/converters/line_break.rb,
lib/coradoc/html/converters/table_cell.rb,
lib/coradoc/html/theme/modern_renderer.rb,
lib/coradoc/html/converters/block_image.rb,
lib/coradoc/html/converters/source_code.rb,
lib/coradoc/html/converters/superscript.rb,
lib/coradoc/html/theme/classic_renderer.rb,
lib/coradoc/html/converters/bibliography.rb,
lib/coradoc/html/converters/comment_line.rb,
lib/coradoc/html/converters/inline_image.rb,
lib/coradoc/html/converters/text_element.rb,
lib/coradoc/html/transform/to_core_model.rb,
lib/coradoc/html/converters/comment_block.rb,
lib/coradoc/html/converters/reviewer_note.rb,
lib/coradoc/html/converters/strikethrough.rb,
lib/coradoc/html/transform/from_core_model.rb,
lib/coradoc/html/converters/cross_reference.rb,
lib/coradoc/html/theme/modern/css_generator.rb,
lib/coradoc/html/converters/reviewer_comment.rb,
lib/coradoc/html/converters/bibliography_entry.rb,
lib/coradoc/html/converters/attribute_reference.rb,
lib/coradoc/html/theme/modern/javascript_generator.rb,
lib/coradoc/html/converters/template_html_converter.rb,
lib/coradoc/html/theme/modern/vue_template_generator.rb,
lib/coradoc/html/theme/modern/tailwind_config_builder.rb,
lib/coradoc/html/theme/modern/components/ui_components.rb,
lib/coradoc/html/theme/modern/serializers/document_serializer.rb
Overview
Backward compatibility alias Some legacy code references Coradoc::Html::Input instead of Coradoc::Input::Html
Defined Under Namespace
Modules: Base, Config, Converters, ElementMapping, Entity, TemplateFilters, Theme, Transform Classes: ConverterBase, Renderer, Spa, Static, TemplateConfig, TemplateLocator
Constant Summary collapse
- Input =
Coradoc::Input::Html
- VERSION =
'1.1.7'- TemplateRenderer =
Backwards compatibility alias
Renderer
Class Method Summary collapse
-
.available_templates ⇒ Array<Symbol>
List all available default templates.
-
.configuration ⇒ TemplateConfig
Get the global configuration.
-
.configure {|TemplateConfig| ... } ⇒ void
Configure the template system.
-
.from_core_model(core_document) ⇒ Object
Transform CoreModel to HTML-ready structure.
-
.from_file(filename, **options) ⇒ Object
Parse HTML file.
-
.handles_model?(model) ⇒ Boolean
Check if this format can transform the given model to CoreModel.
-
.parse(html, options = {}) ⇒ Object
Parse HTML content and return CoreModel elements (may be an Array).
-
.parse_to_core(html, options = {}) ⇒ Coradoc::CoreModel::StructuralElement
Parse HTML content directly into a CoreModel document.
-
.reset_configuration! ⇒ void
Reset configuration to defaults.
-
.serialize(document, options = {}) ⇒ String
Serialize CoreModel document to HTML.
-
.serialize_as(document, format, options = {}) ⇒ String
Serialize CoreModel document to HTML with specified format.
-
.serialize_spa(document, config = {}) ⇒ String
Serialize CoreModel document to SPA HTML.
-
.serialize_static(document, config = {}) ⇒ String
Serialize CoreModel document to static HTML.
-
.template_path_for(name) ⇒ Pathname?
Get the path to a default template.
- .to_core(document) ⇒ Object
-
.to_core_model(document) ⇒ Coradoc::CoreModel::Base
Transform HTML model to CoreModel.
-
.validate_core_model!(document) ⇒ Object
Validate that input is a CoreModel type.
Class Method Details
.available_templates ⇒ Array<Symbol>
List all available default templates
138 139 140 |
# File 'lib/coradoc/html/template_config.rb', line 138 def available_templates TemplateConfig.available_templates end |
.configuration ⇒ TemplateConfig
Get the global configuration
111 112 113 |
# File 'lib/coradoc/html/template_config.rb', line 111 def configuration @configuration ||= TemplateConfig.new end |
.configure {|TemplateConfig| ... } ⇒ void
This method returns an undefined value.
Configure the template system
124 125 126 |
# File 'lib/coradoc/html/template_config.rb', line 124 def configure yield(configuration) if block_given? end |
.from_core_model(core_document) ⇒ Object
Transform CoreModel to HTML-ready structure
246 247 248 |
# File 'lib/coradoc/html.rb', line 246 def self.from_core_model(core_document) Transform::FromCoreModel.transform(core_document) end |
.from_file(filename, **options) ⇒ Object
Parse HTML file
144 145 146 147 |
# File 'lib/coradoc/html.rb', line 144 def self.from_file(filename, **) content = File.read(filename) parse(content, **) end |
.handles_model?(model) ⇒ Boolean
Check if this format can transform the given model to CoreModel
HTML produces CoreModel directly, so it only handles already-CoreModel objects.
234 235 236 |
# File 'lib/coradoc/html.rb', line 234 def self.handles_model?(model) model.is_a?(Coradoc::CoreModel::Base) end |
.parse(html, options = {}) ⇒ Object
Parse HTML content and return CoreModel elements (may be an Array)
105 106 107 108 |
# File 'lib/coradoc/html.rb', line 105 def self.parse(html, = {}) # Input::Html is autoloaded via Coradoc::Input ::Coradoc::Html::Input.to_coradoc(html, ) end |
.parse_to_core(html, options = {}) ⇒ Coradoc::CoreModel::StructuralElement
Parse HTML content directly into a CoreModel document
Unlike #parse which returns an Array of CoreModel elements, this wraps the result into a top-level StructuralElement document suitable for use with Coradoc.serialize and other CoreModel pipelines.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/coradoc/html.rb', line 119 def self.parse_to_core(html, = {}) elements = parse(html, ) return elements if elements.is_a?(Coradoc::CoreModel::Base) # Extract document title from the first heading element title = nil children = elements if elements.is_a?(Array) && !elements.empty? first = elements.first if first.is_a?(Coradoc::CoreModel::StructuralElement) && first.section? && first.level == 1 title = first.title children = first.children + elements[1..] end end Coradoc::CoreModel::StructuralElement.new( element_type: 'document', title: title, children: Array(children) ) end |
.reset_configuration! ⇒ void
This method returns an undefined value.
Reset configuration to defaults
131 132 133 |
# File 'lib/coradoc/html/template_config.rb', line 131 def reset_configuration! @configuration = nil end |
.serialize(document, options = {}) ⇒ String
Serialize CoreModel document to HTML
Uses the theme system to render HTML. Default theme is :classic.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/coradoc/html.rb', line 156 def self.serialize(document, = {}) # Validate input is CoreModel validate_core_model!(document) # Trigger theme autoloads to ensure renderers are registered Theme::ClassicRenderer if [:theme].nil? || [:theme] == :classic Theme::ModernRenderer if [:theme] == :modern # Use theme registry to find and use the appropriate renderer theme = [:theme] || :classic renderer_class = Theme::Registry.find(theme) renderer = renderer_class.new(document, ) renderer.render_html5 end |
.serialize_as(document, format, options = {}) ⇒ String
Serialize CoreModel document to HTML with specified format
205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/coradoc/html.rb', line 205 def self.serialize_as(document, format, = {}) # Validate input is CoreModel validate_core_model!(document) case format.to_sym when :static, :html_static, :classic serialize_static(document, ) when :spa, :html_spa, :modern serialize_spa(document, ) else raise ArgumentError, "Unknown output format: #{format}. " \ 'Valid formats: :static, :spa' end end |
.serialize_spa(document, config = {}) ⇒ String
Serialize CoreModel document to SPA HTML
Uses the modern theme renderer for Vue.js + Tailwind output.
192 193 194 195 196 197 |
# File 'lib/coradoc/html.rb', line 192 def self.serialize_spa(document, config = {}) # Validate input is CoreModel validate_core_model!(document) Spa.convert(document, config) end |
.serialize_static(document, config = {}) ⇒ String
Serialize CoreModel document to static HTML
Uses the classic theme renderer for traditional HTML output.
178 179 180 181 182 183 |
# File 'lib/coradoc/html.rb', line 178 def self.serialize_static(document, config = {}) # Validate input is CoreModel validate_core_model!(document) Static.convert(document, config) end |
.template_path_for(name) ⇒ Pathname?
Get the path to a default template
146 147 148 |
# File 'lib/coradoc/html/template_config.rb', line 146 def template_path_for(name) TemplateConfig.template_path_for(name) end |
.to_core(document) ⇒ Object
238 239 240 |
# File 'lib/coradoc/html.rb', line 238 def self.to_core(document) to_core_model(document) end |
.to_core_model(document) ⇒ Coradoc::CoreModel::Base
Transform HTML model to CoreModel
224 225 226 |
# File 'lib/coradoc/html.rb', line 224 def self.to_core_model(document) Transform::ToCoreModel.transform(document) end |
.validate_core_model!(document) ⇒ Object
Validate that input is a CoreModel type
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/coradoc/html.rb', line 91 def self.validate_core_model!(document) return document if document.nil? unless document.is_a?(Coradoc::CoreModel::Base) raise ArgumentError, 'coradoc-html only accepts CoreModel types. ' \ "Got: #{document.class}. " \ 'Transform your document to CoreModel before passing to HTML conversion.' end document end |