Class: Repubmark::Elems::Footnote
- Defined in:
- lib/repubmark/elems/footnote.rb
Instance Attribute Summary collapse
-
#alt_urls ⇒ Object
Returns the value of attribute alt_urls.
-
#category ⇒ Object
Returns the value of attribute category.
-
#date ⇒ Object
Returns the value of attribute date.
-
#index ⇒ Object
Returns the value of attribute index.
-
#link_text ⇒ Object
Returns the value of attribute link_text.
-
#slug ⇒ Object
Returns the value of attribute slug.
-
#url ⇒ Object
Returns the value of attribute url.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(parent, **kwargs) ⇒ Footnote
constructor
A new instance of Footnote.
- #method_missing(method_name) ⇒ Object
-
#respond_to_missing?(method_name, _include_private) ⇒ Boolean
Builder methods #.
- #to_gemtext ⇒ Object
-
#to_html ⇒ Object
Basic methods #.
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_urls ⇒ Object
Returns the value of attribute alt_urls.
8 9 10 |
# File 'lib/repubmark/elems/footnote.rb', line 8 def alt_urls @alt_urls end |
#category ⇒ Object
Returns the value of attribute category.
8 9 10 |
# File 'lib/repubmark/elems/footnote.rb', line 8 def category @category end |
#date ⇒ Object
Returns the value of attribute date.
8 9 10 |
# File 'lib/repubmark/elems/footnote.rb', line 8 def date @date end |
#index ⇒ Object
Returns the value of attribute index.
8 9 10 |
# File 'lib/repubmark/elems/footnote.rb', line 8 def index @index end |
#link_text ⇒ Object
Returns the value of attribute link_text.
8 9 10 |
# File 'lib/repubmark/elems/footnote.rb', line 8 def link_text @link_text end |
#slug ⇒ Object
Returns the value of attribute slug.
8 9 10 |
# File 'lib/repubmark/elems/footnote.rb', line 8 def slug @slug end |
#url ⇒ Object
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 #
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_gemtext ⇒ Object
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_html ⇒ Object
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 |