Class: Repubmark::Elems::Caption

Inherits:
Base
  • Object
show all
Includes:
Joint::ForwardingBuilders
Defined in:
lib/repubmark/elems/caption.rb

Instance Attribute Summary

Attributes inherited from Base

#parent

Instance Method Summary collapse

Methods included from Joint::ForwardingBuilders

#abbrev, #bold, #code_inline, #ellipsis, #fraction, #italic, #link, #link_italic, #mdash, #power, #quote_italic, #section, #text

Methods inherited from Base

#absolute_url, #config, #count_words, #html_class, #own_url, parent?, parents, #relative_url

Constructor Details

#initialize(parent) ⇒ Caption

Returns a new instance of Caption.



10
11
12
13
# File 'lib/repubmark/elems/caption.rb', line 10

def initialize(parent)
  super parent
  @items = []
end

Instance Method Details

#empty?Boolean

Helper methods #

Returns:

  • (Boolean)


43
# File 'lib/repubmark/elems/caption.rb', line 43

def empty? = @items.empty?

#joint {|joint| ... } ⇒ Object

Builder methods #

Yields:



49
50
51
52
53
54
# File 'lib/repubmark/elems/caption.rb', line 49

def joint
  joint = Joint.new self
  yield joint
  @items << joint
  nil
end

#quote(str = nil) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/repubmark/elems/caption.rb', line 56

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

#to_gemtextObject



35
36
37
# File 'lib/repubmark/elems/caption.rb', line 35

def to_gemtext
  @items.map(&:to_gemtext).join(' ').strip.freeze unless @items.empty?
end

#to_htmlObject



25
26
27
28
29
30
31
32
33
# File 'lib/repubmark/elems/caption.rb', line 25

def to_html
  return if @items.empty?

  [
    '<span>',
    *@items.map(&:to_html),
    '</span>',
  ].map { |s| "#{s}\n" }.join.freeze
end

#to_summary_plainObject



21
22
23
# File 'lib/repubmark/elems/caption.rb', line 21

def to_summary_plain
  @items.map(&:to_summary_plain).join(' ').freeze unless @items.empty?
end

#word_countObject

Basic methods #



19
# File 'lib/repubmark/elems/caption.rb', line 19

def word_count = @items.sum(&:word_count)