Add builder pattern for paragraph, lists, tables

This commit is contained in:
2025-12-02 10:57:54 +01:00
parent 50c9c20eca
commit b602b2a2ff
25 changed files with 1248 additions and 47 deletions

9
lib/ezdoc/nodes/base.rb Normal file
View File

@@ -0,0 +1,9 @@
# frozen_string_literal: true
module Ezdoc
module Nodes
class Base
# Base class for all document nodes
end
end
end

20
lib/ezdoc/nodes/list.rb Normal file
View File

@@ -0,0 +1,20 @@
# frozen_string_literal: true
module Ezdoc
module Nodes
class List < Base
attr_reader :items, :type, :num_id
def initialize(type:, num_id:)
super()
@type = type
@num_id = num_id
@items = []
end
def add_item(item)
@items << item
end
end
end
end

View File

@@ -0,0 +1,20 @@
# frozen_string_literal: true
module Ezdoc
module Nodes
class ListItem < Base
attr_reader :runs, :list_type, :num_id
def initialize(runs = [], list_type:, num_id:)
super()
@runs = runs
@list_type = list_type
@num_id = num_id
end
def add_run(run)
@runs << run
end
end
end
end

View File

@@ -0,0 +1,18 @@
# frozen_string_literal: true
module Ezdoc
module Nodes
class Paragraph < Base
attr_reader :runs
def initialize(runs = [])
super()
@runs = runs
end
def add_run(run)
@runs << run
end
end
end
end

17
lib/ezdoc/nodes/run.rb Normal file
View File

@@ -0,0 +1,17 @@
# frozen_string_literal: true
module Ezdoc
module Nodes
class Run < Base
attr_reader :text, :bold, :italic, :underline
def initialize(text, bold: false, italic: false, underline: false)
super()
@text = text
@bold = bold
@italic = italic
@underline = underline
end
end
end
end

18
lib/ezdoc/nodes/table.rb Normal file
View File

@@ -0,0 +1,18 @@
# frozen_string_literal: true
module Ezdoc
module Nodes
class Table < Base
attr_reader :rows
def initialize
super
@rows = []
end
def add_row(row)
@rows << row
end
end
end
end

View File

@@ -0,0 +1,18 @@
# frozen_string_literal: true
module Ezdoc
module Nodes
class TableCell < Base
attr_reader :runs
def initialize
super
@runs = []
end
def add_run(run)
@runs << run
end
end
end
end

View File

@@ -0,0 +1,18 @@
# frozen_string_literal: true
module Ezdoc
module Nodes
class TableRow < Base
attr_reader :cells
def initialize
super
@cells = []
end
def add_cell(cell)
@cells << cell
end
end
end
end