The CoreModel is Ceradoc’s canonical document representation. All format transformations use CoreModel as the hub.
Architecture
┌─────────────────────────────────────┐
│ Source Formats │
│ │
┌─────────┐ │ ┌─────────┐ ┌─────────┐ ┌──────┐ │ ┌─────────┐
│AsciiDoc │────►│ │ ToCore │ │ From │ │ HTML │────►│ HTML │
│ .adoc │ │ │ │ │ Core │ │Render│ │ │ .html │
└─────────┘ │ │ │ │ │ │ │ │ └─────────┘
│ │ ▼ ▼ │ │ │ │
┌─────────┐ │ │ ┌─────────┐ │ │ │ │ ┌─────────┐
│Markdown │────►│ │ │CoreModel│ │ │ │────►│Markdown │
│ .md │ │ │ │ Hub │ │ │ │ │ │ .md │
└─────────┘ │ │ └─────────┘ │ │ │ │ └─────────┘
│ │ │ │ │ │
┌─────────┐ │ │ │ │ │ │ ┌─────────┐
│ HTML │────►│ │ │ │ │────►│ AsciiDoc│
│ .html │ │ └─────────────────────┘ └──────┘ │ │ .adoc │
└─────────┘ │ │ └─────────┘
└──────────────────────────────────────┘Base Class
Ceradoc::CoreModel::Base
All CoreModel elements inherit from Base.
new(attributes = {}) | Create new instance with attributes |
attribute(name, type, options = {}) | Define an attribute |
to_h | Convert to hash representation |
to_json(*args) | Convert to JSON |
==(other) | Equality comparison |
eql?(other) | Hash equality |
Structural Elements
Ceradoc::CoreModel::StructuralElement
Represents document structure (document, section).
element_type |
|
title |
|
level |
|
id |
|
children |
|
attributes |
|
# Create a document
doc = Ceradoc::CoreModel::StructuralElement.new(
element_type: "document",
title: "My Document",
id: "my-doc",
children: []
)
# Create a section
section = Ceradoc::CoreModel::StructuralElement.new(
element_type: "section",
level: 1,
title: "Introduction",
id: "intro",
children: []
)Block Elements
Ceradoc::CoreModel::Block
Generic content block.
element_type |
|
content |
|
delimiter_type |
|
language |
|
title |
|
id |
|
attributes |
|
"----" | Source/listing block |
"====" | Example block |
"__" | Quote block |
"**" | Sidebar block |
"" | Pass block |
"…." | Literal block |
"--" | Open block |
# Paragraph
para = Ceradoc::CoreModel::Block.new(
element_type: "paragraph",
content: "This is a paragraph."
)
# Code block
code = Ceradoc::CoreModel::Block.new(
element_type: "block",
delimiter_type: "----",
content: "def hello; puts 'world'; end",
language: "ruby",
title: "Hello World Example"
)
# Quote block
quote = Ceradoc::CoreModel::Block.new(
element_type: "block",
delimiter_type: "____",
content: "To be or not to be.",
attributes: { "attribution" => "Shakespeare" }
)Ceradoc::CoreModel::AnnotationBlock
Admonition block (NOTE, TIP, WARNING, etc.).
annotation_type |
|
content |
|
title |
|
id |
|
note = Ceradoc::CoreModel::AnnotationBlock.new(
annotation_type: "NOTE",
content: "This is an important note."
)List Elements
Ceradoc::CoreModel::ListBlock
List container (ordered, unordered, definition).
marker_type |
|
items |
|
title |
|
id |
|
"ordered" | Numbered list ( |
"unordered" | Bulleted list ( |
"definition" | Definition list ( |
# Unordered list
ulist = Ceradoc::CoreModel::ListBlock.new(
marker_type: "unordered",
items: [
Ceradoc::CoreModel::ListItem.new(content: "First item", marker: "*"),
Ceradoc::CoreModel::ListItem.new(content: "Second item", marker: "*")
]
)
# Ordered list
olist = Ceradoc::CoreModel::ListBlock.new(
marker_type: "ordered",
items: [
Ceradoc::CoreModel::ListItem.new(content: "Step one", marker: "."),
Ceradoc::CoreModel::ListItem.new(content: "Step two", marker: ".")
]
)Ceradoc::CoreModel::ListItem
Individual list item.
content |
|
marker |
|
id |
|
attached |
|
nested |
|
item = Ceradoc::CoreModel::ListItem.new(
content: "Main item text",
marker: "*",
attached: [
Ceradoc::CoreModel::Block.new(
element_type: "paragraph",
content: "Attached paragraph via continuation"
)
],
nested: [
Ceradoc::CoreModel::ListBlock.new(
marker_type: "unordered",
items: [...]
)
]
)Table Elements
Ceradoc::CoreModel::Table
Table container.
rows |
|
title |
|
id |
|
frame |
|
grid |
|
width |
|
float |
|
cols |
|
col_alignments |
|
col_styles |
|
bgcolor |
|
table = Ceradoc::CoreModel::Table.new(
title: "Data Table",
frame: "all",
grid: "all",
cols: ["1", "2", "1"],
rows: [
Ceradoc::CoreModel::TableRow.new(
header: true,
cells: [
Ceradoc::CoreModel::TableCell.new(content: "Name", header: true),
Ceradoc::CoreModel::TableCell.new(content: "Value", header: true)
]
),
Ceradoc::CoreModel::TableRow.new(
cells: [
Ceradoc::CoreModel::TableCell.new(content: "Item 1"),
Ceradoc::CoreModel::TableCell.new(content: "100")
]
)
]
)Ceradoc::CoreModel::TableRow
Table row container.
cells |
|
header |
|
header_row = Ceradoc::CoreModel::TableRow.new(
header: true,
cells: [
Ceradoc::CoreModel::TableCell.new(content: "Column A", header: true),
Ceradoc::CoreModel::TableCell.new(content: "Column B", header: true)
]
)Ceradoc::CoreModel::TableCell
Table cell with full formatting support.
content |
|
alignment |
|
vertical_alignment |
|
colspan |
|
rowspan |
|
header |
|
style |
|
bgcolor |
|
color |
|
width |
|
height |
|
repeat |
|
"default" | Normal text |
"strong" | Bold/strong text |
"emphasis" | Itic/emphasis text |
"monospace" | Code/mono text |
"asciidoc" | Parse nested AsciiDoc content |
"literal" | Preserve whitespace |
"verse" | Verse/poetry format |
# Basic cell
cell = Ceradoc::CoreModel::TableCell.new(content: "Data")
# Header cell
header = Ceradoc::CoreModel::TableCell.new(
content: "Title",
header: true,
alignment: "center"
)
# Spanning cell
spanning = Ceradoc::CoreModel::TableCell.new(
content: "Spans 2 columns",
colspan: 2,
alignment: "center"
)
# Styled cell
styled = Ceradoc::CoreModel::TableCell.new(
content: "Important",
style: "strong",
bgcolor: "#ffcccc"
)Inline Elements
Ceradoc::CoreModel::InlineElement
Inline formatting element.
format_type |
|
content |
|
target |
|
attributes |
|
"bold" | Bold text |
"italic" | Italic text |
"monospace" | Monospace/code text |
"link" | Hyperlink |
"xref" | Cross-reference |
"highlight" | Highlighted text |
"subscript" | Subscript text |
"superscript" | Superscript text |
# Bold text
bold = Ceradoc::CoreModel::InlineElement.new(
format_type: "bold",
content: "Important text"
)
# Link
link = Ceradoc::CoreModel::InlineElement.new(
format_type: "link",
content: "Click here",
target: "https://example.com"
)
# Cross-reference
xref = Ceradoc::CoreModel::InlineElement.new(
format_type: "xref",
content: "See Section 1",
target: "section-1"
)Image Elements
Ceradoc::CoreModel::Image
Block image.
src |
|
alt |
|
title |
|
width |
|
height |
|
id |
|
link |
|
image = Ceradoc::CoreModel::Image.new(
src: "images/diagram.png",
alt: "System Architecture",
title: "Figure 1: System Architecture",
width: "800"
)Working with CoreModel
Creating Documents
# Build a document programmatically
doc = Ceradoc::CoreModel::StructuralElement.new(
element_type: "document",
title: "Generated Document",
children: [
Ceradoc::CoreModel::StructuralElement.new(
element_type: "section",
level: 1,
title: "Introduction",
children: [
Ceradoc::CoreModel::Block.new(
element_type: "paragraph",
content: "This is the introduction."
)
]
)
]
)Modifying Documents
# Parse existing document
doc = Ceradoc.parse(input, format: :asciidoc)
# Modify structure
doc.title = "Updated Title"
doc.children.each do |child|
if child.is_a?(Ceradoc::CoreModel::Block)
child.content = child.content.upcase
end
end
# Serialize to another format
html = Ceradoc.serialize(doc, to: :html)Querying Documents
# Find all sections
sections = doc.query('section')
# Find paragraphs
paragraphs = doc.query('paragraph')
# Find by ID
intro = doc.query('#intro').first
# Find by class
examples = doc.query('.example')
# Complex query
results = doc.query('section > paragraph:first-child')Validation
# Validate document structure
schema = Ceradoc::Validation::Schema.define do
required :title, type: String, min_length: 1
required :children, type: Array
end
result = schema.validate(doc)
if result.valid?
puts "Document is valid"
else
result.errors.each { |e| puts "#{e.path}: #{e.message}" }
endType Reference
:string | String value |
:integer | Integer value |
:boolean | True/false value |
:float | Floating-point number |
:date | Date value |
:time | Time value |
ClassName | Nested model (e.g., |
Array<ClassName> | Collection of models |
# Single nested model
attribute :image, Image
# Collection of models
attribute :rows, TableRow, collection: true
# Optional attribute
attribute :title, :string, default: nil
# With default value
attribute :level, :integer, default: -> { 1 }