Class: Repubmark::Elems::Blockquote
- Inherits:
-
Base
- Object
- Base
- Repubmark::Elems::Blockquote
show all
- Defined in:
- lib/repubmark/elems/blockquote.rb
Instance Attribute Summary
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
Constructor Details
#initialize(parent) ⇒ Blockquote
Returns a new instance of Blockquote.
8
9
10
11
12
13
|
# File 'lib/repubmark/elems/blockquote.rb', line 8
def initialize(parent)
super parent
@canvas = Canvas.new self
@caption = nil
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/repubmark/elems/blockquote.rb', line 53
def method_missing(method_name, ...)
if @canvas.respond_to? method_name
raise 'Paragraph after caption' unless @caption.nil?
@canvas.public_send(method_name, ...)
else
super
end
end
|
Instance Method Details
#caption {|@caption| ... } ⇒ Object
43
44
45
46
47
|
# File 'lib/repubmark/elems/blockquote.rb', line 43
def caption
@caption = Caption.new self
yield @caption
nil
end
|
#caption_gemtext ⇒ Object
75
76
77
|
# File 'lib/repubmark/elems/blockquote.rb', line 75
def caption_gemtext
"#{@caption.to_gemtext}\n".freeze unless @caption.nil?
end
|
#caption_html ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'lib/repubmark/elems/blockquote.rb', line 65
def caption_html
return if @caption.nil?
[
"<figcaption#{html_class(:blockquote_figcaption)}>\n",
@caption.to_html,
"</figcaption>\n",
].join.freeze
end
|
#respond_to_missing?(method_name, _include_private) ⇒ Boolean
49
50
51
|
# File 'lib/repubmark/elems/blockquote.rb', line 49
def respond_to_missing?(method_name, _include_private)
@canvas.respond_to?(method_name) || super
end
|
#to_gemtext ⇒ Object
32
33
34
35
36
37
|
# File 'lib/repubmark/elems/blockquote.rb', line 32
def to_gemtext
[
@canvas.to_gemtext.split("\n").map { |s| "> #{s}\n" }.join,
caption_gemtext,
].join.freeze
end
|
#to_html ⇒ Object
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/repubmark/elems/blockquote.rb', line 21
def to_html
[
"<figure#{html_class(:blockquote_figure)}>\n",
"<blockquote#{html_class(:blockquote_blockquote)}>\n",
@canvas.to_html,
"</blockquote>\n",
caption_html,
"</figure>\n",
].join.freeze
end
|
#word_count ⇒ Object
19
|
# File 'lib/repubmark/elems/blockquote.rb', line 19
def word_count = @canvas.word_count + (@caption&.word_count || 0)
|