Class: Repubmark::Elems::Footnote

Inherits:
Base
  • Object
show all
Defined in:
lib/repubmark/elems/footnote.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#parent

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

#initialize(parent, **kwargs) ⇒ Footnote

Returns a new instance of Footnote.



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

def initialize(parent, **kwargs)
  super parent
  kwargs.each { |k, v| send :"#{k}=", v }
  @caption = Caption.new self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/repubmark/elems/footnote.rb', line 74

def method_missing(method_name, ...)
  if @caption.respond_to? method_name
    @caption.public_send(method_name, ...)
  else
    super
  end
end

Instance Attribute Details

#alt_urlsObject

Returns the value of attribute alt_urls.



8
9
10
# File 'lib/repubmark/elems/footnote.rb', line 8

def alt_urls
  @alt_urls
end

#categoryObject

Returns the value of attribute category.



8
9
10
# File 'lib/repubmark/elems/footnote.rb', line 8

def category
  @category
end

#dateObject

Returns the value of attribute date.



8
9
10
# File 'lib/repubmark/elems/footnote.rb', line 8

def date
  @date
end

#indexObject

Returns the value of attribute index.



8
9
10
# File 'lib/repubmark/elems/footnote.rb', line 8

def index
  @index
end

Returns the value of attribute link_text.



8
9
10
# File 'lib/repubmark/elems/footnote.rb', line 8

def link_text
  @link_text
end

#slugObject

Returns the value of attribute slug.



8
9
10
# File 'lib/repubmark/elems/footnote.rb', line 8

def slug
  @slug
end

#urlObject

Returns the value of attribute url.



8
9
10
# File 'lib/repubmark/elems/footnote.rb', line 8

def url
  @url
end

Instance Method Details

#respond_to_missing?(method_name, _include_private) ⇒ Boolean

Builder methods #

Returns:

  • (Boolean)


70
71
72
# File 'lib/repubmark/elems/footnote.rb', line 70

def respond_to_missing?(method_name, _include_private)
  @caption.respond_to?(method_name) || super
end

#to_gemtextObject



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

def to_gemtext
  result = ''
  result += url ? "=> #{url}" : '*'
  result += " #{index})"
  result += " #{Date.parse(date)}" if date
  result += " #{link_text}" if link_text
  result += " #{@caption.to_gemtext}"
  result.freeze
end

#to_htmlObject

Basic methods #



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/repubmark/elems/footnote.rb', line 20

def to_html
  result = ''
  result +=
    %(<li id="#{category}-#{slug}" value="#{index}" class="fragment-highlight">\n)
  if date
    result += %(<span class="text-muted">\n)
    result += %(<time datetime="#{date}">\n)
    result += "#{I18n.localize(Date.parse(date), format: :long)}\n"
    result += "</time>\n"
    result += "</span>\n"
  end
  if url
    scheme = Addressable::URI.parse(url).scheme&.downcase
    if scheme
      unless %w[http https].include? scheme
        result += %(<span class="badge text-bg-secondary">\n)
        result += %(#{scheme}://\n)
        result += "</span>\n"
      end
    end
    result += %(<a href="#{url}">#{link_text}</a>\n)
  else
    result += "#{link_text}\n" if link_text
  end
  result += @caption.to_html.to_s
  if alt_urls&.any?
    result += %[(#{
      alt_urls.map do |alt_url|
        %(<a href=\"#{alt_url[:url]}\">#{alt_url[:name]}</a>)
      end.join ', '
    })\n]
  end
  result += '</li>'
  result.freeze
end