62 lines
1.2 KiB
Ruby
62 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Repubmark
|
|
module Elems
|
|
class Caption < Base
|
|
include Joint::ForwardingBuilders
|
|
|
|
parents :Blockquote, :Figure, :ListItem, :Paragraph
|
|
|
|
def initialize(parent)
|
|
super parent
|
|
@items = []
|
|
end
|
|
|
|
#################
|
|
# Basic methods #
|
|
#################
|
|
|
|
def word_count = @items.sum(&:word_count)
|
|
|
|
def to_html
|
|
[
|
|
'<span>',
|
|
*@items.map(&:to_html),
|
|
'</span>',
|
|
].map { |s| "#{s}\n" }.join.freeze
|
|
end
|
|
|
|
def to_gemtext = @items.map(&:to_gemtext).join(' ').strip.freeze
|
|
|
|
##################
|
|
# Helper methods #
|
|
##################
|
|
|
|
def empty? = @items.empty?
|
|
|
|
###################
|
|
# Builder methods #
|
|
###################
|
|
|
|
def joint
|
|
joint = Joint.new self
|
|
yield joint
|
|
@items << joint
|
|
nil
|
|
end
|
|
|
|
def quote(str = nil)
|
|
quote = Quote.new self
|
|
case [!!str, block_given?]
|
|
when [true, false] then quote.text str
|
|
when [false, true] then yield quote
|
|
else
|
|
raise 'Invalid args'
|
|
end
|
|
@items << quote
|
|
nil
|
|
end
|
|
end
|
|
end
|
|
end
|