50 lines
1012 B
Ruby
50 lines
1012 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Repubmark
|
|
module Elems
|
|
class Quote < Base
|
|
include Joint::ForwardingBuilders
|
|
|
|
parents :Caption, :Joint, :Quote
|
|
|
|
def initialize(...)
|
|
super
|
|
@items = []
|
|
end
|
|
|
|
#################
|
|
# Basic methods #
|
|
#################
|
|
|
|
def word_count = @items.sum(&:word_count)
|
|
|
|
def to_html = "«#{@items.map(&:to_html).join("\n")}»".freeze
|
|
|
|
def to_gemtext = "«#{@items.map(&:to_gemtext).join(' ')}»".freeze
|
|
|
|
###################
|
|
# 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
|