Class: Metanorma::Html::Drops::FigureDrop

Inherits:
BlockElementDrop show all
Defined in:
lib/metanorma/html/drops/figure_drop.rb

Instance Attribute Summary collapse

Attributes inherited from BlockElementDrop

#content_html, #css_class, #id, #label_html, #type

Class Method Summary collapse

Methods inherited from BlockElementDrop

#initialize

Constructor Details

This class inherits a constructor from Metanorma::Html::Drops::BlockElementDrop

Instance Attribute Details

#caption_htmlObject (readonly)

Returns the value of attribute caption_html.



7
8
9
# File 'lib/metanorma/html/drops/figure_drop.rb', line 7

def caption_html
  @caption_html
end

#image_htmlObject (readonly)

Returns the value of attribute image_html.



7
8
9
# File 'lib/metanorma/html/drops/figure_drop.rb', line 7

def image_html
  @image_html
end

#key_htmlObject (readonly)

Returns the value of attribute key_html.



7
8
9
# File 'lib/metanorma/html/drops/figure_drop.rb', line 7

def key_html
  @key_html
end

#sub_figures_htmlObject (readonly)

Returns the value of attribute sub_figures_html.



7
8
9
# File 'lib/metanorma/html/drops/figure_drop.rb', line 7

def sub_figures_html
  @sub_figures_html
end

Class Method Details

.from_model(figure, renderer:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
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
# File 'lib/metanorma/html/drops/figure_drop.rb', line 9

def self.from_model(figure, renderer:)
  id = renderer.safe_attr(figure, :id)
  fig_name = renderer.safe_attr(figure, :fmt_name) || renderer.safe_attr(figure, :name)
  if id && fig_name
    renderer.register_figure_entry(id: id, text: renderer.extract_plain_text(fig_name))
  end

  image_html = renderer.capture_output do
    if figure.image
      renderer.render_image(figure.image)
    elsif renderer.safe_attr(figure, :source)
      src = renderer.safe_attr(figure, :source)
      @output << %(<img src="#{renderer.escape_html(src)}" />)
    end
  end

  caption_html = if fig_name || renderer.safe_attr(figure, :name)
                   renderer.capture_output do
                     el = renderer.safe_attr(figure, :fmt_name) || figure.name
                     renderer.render_inline_element(el)
                   end
                 end

  sub_figures_html = renderer.capture_output do
    figure.figure&.each { |sub| renderer.render_figure(sub) }
  end

  key_html = renderer.capture_output do
    renderer.safe_attr(figure, :note)&.each { |n| renderer.render_note(n) }
    renderer.safe_attr(figure, :dl)&.then { |dl| renderer.render_definition_list(dl) }
  end

  new(
    id: id,
    image_html: image_html,
    caption_html: caption_html,
    key_html: key_html,
    sub_figures_html: sub_figures_html,
    css_class: "figure",
  )
end