repubmark/lib/repubmark/elems/canvas.rb

102 lines
2.0 KiB
Ruby

# frozen_string_literal: true
module Repubmark
module Elems
class Canvas < Base
parents :Annotation, :Blockquote, :Chapter
def initialize(parent)
super parent
@items = []
end
#################
# Basic methods #
#################
def word_count = @items.sum(&:word_count)
def to_html = @items.map(&:to_html).join.freeze
def to_gemtext = @items.map(&:to_gemtext).join("\n").freeze
###################
# Builder methods #
###################
def blockquote
blockquote = Blockquote.new self
@items << blockquote
yield blockquote
nil
end
def code_block(*args, **kwargs)
code_block = CodeBlock.new self, *args, **kwargs
@items << code_block
nil
end
def custom
custom_block = CustomBlock.new self
@items << custom_block
yield custom_block
nil
end
def iframe(*args, **kwargs)
iframe = Iframe.new self, *args, **kwargs
@items << iframe
nil
end
def links_list
list = List.new self, links: true, ordered: false
@items << list
yield list
nil
end
def nice_figure(name, alt)
figure = Figure.new self, name, alt
@items << figure
yield figure if block_given?
nil
end
def nice_figures
figures = Figures.new self
@items << figures
yield figures
nil
end
def olist
list = List.new self, links: false, ordered: true
@items << list
yield list
nil
end
def paragraph
paragraph = Paragraph.new self
@items << paragraph
yield paragraph
nil
end
def separator
@items << Separator.new(self)
nil
end
def ulist
list = List.new self, links: false, ordered: false
@items << list
yield list
nil
end
end
end
end