Class: Repubmark::Elems::Figure
- Defined in:
- lib/repubmark/elems/figure.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #caption_html ⇒ Object private
-
#initialize(parent, name, alt) ⇒ Figure
constructor
A new instance of Figure.
- #method_missing(method_name) ⇒ Object
-
#respond_to_missing?(method_name, _include_private) ⇒ Boolean
Builder methods #.
- #src ⇒ Object private
- #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, name, alt) ⇒ Figure
Returns a new instance of Figure.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/repubmark/elems/figure.rb', line 8 def initialize(parent, name, alt) super parent alt = String(alt).strip.split.join(' ').freeze raise 'Empty alt text' if alt.empty? @name = String(name).strip.freeze @alt = alt @caption = Caption.new self end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/repubmark/elems/figure.rb', line 50 def method_missing(method_name, ...) if @caption.respond_to? method_name @caption.public_send(method_name, ...) else super end end |
Instance Method Details
#caption_html ⇒ Object (private)
64 65 66 67 68 69 70 |
# File 'lib/repubmark/elems/figure.rb', line 64 def if @caption.empty? "#{CGI.escape_html(@alt)}\n" else @caption.to_html end end |
#respond_to_missing?(method_name, _include_private) ⇒ Boolean
Builder methods #
46 47 48 |
# File 'lib/repubmark/elems/figure.rb', line 46 def respond_to_missing?(method_name, _include_private) @caption.respond_to?(method_name) || super end |
#src ⇒ Object (private)
60 61 62 |
# File 'lib/repubmark/elems/figure.rb', line 60 def src @src ||= own_url "#{config[:images_prefix]}/#@name" end |
#to_gemtext ⇒ Object
36 37 38 39 40 |
# File 'lib/repubmark/elems/figure.rb', line 36 def to_gemtext = @caption.to_gemtext.to_s.strip = @alt if .empty? "=> #{src} #{}\n".freeze end |
#to_html ⇒ Object
Basic methods #
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/repubmark/elems/figure.rb', line 23 def to_html [ "<div#{html_class(:figure_wrap)}>\n", "<figure#{html_class(:figure_self)}>\n", "<img src=\"#{src}\" alt=\"#{CGI.escape_html(@alt)}\"/>\n", "<figcaption>\n", , "</figcaption>\n", "</figure>\n", "</div>\n", ].join.freeze end |