Class: Docbook::Services::ElementToHash

Inherits:
Object
  • Object
show all
Defined in:
lib/docbook/services/element_to_hash.rb

Overview

Converts Lutaml elements to Vue-friendly hashes Uses Lutaml's as_json but ensures compatibility with Vue rendering

Instance Method Summary collapse

Constructor Details

#initialize(element) ⇒ ElementToHash

Returns a new instance of ElementToHash.



8
9
10
# File 'lib/docbook/services/element_to_hash.rb', line 8

def initialize(element)
  @element = element
end

Instance Method Details

#to_hObject

Convert element to hash suitable for Vue



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
# File 'lib/docbook/services/element_to_hash.rb', line 13

def to_h
  case @element
  when Elements::RefEntry
    refentry_to_h
  when Elements::Para
    para_to_h
  when Elements::VariableList
    variablelist_to_h
  when Elements::OrderedList
    orderedlist_to_h
  when Elements::ItemizedList
    itemizedlist_to_h
  when Elements::ProgramListing, Elements::Screen
    codelike_to_h
  when Elements::Example, Elements::InformalExample
    example_to_h
  when Elements::Figure, Elements::InformalFigure
    figure_to_h
  when Elements::Table
    table_to_h
  when Elements::Note, Elements::Warning, Elements::Caution,
       Elements::Important, Elements::Tip, Elements::Danger
    admonition_to_h
  when Elements::BlockQuote
    blockquote_to_h
  when Elements::Title
    { type: "title", text: @element.content.join }
  else
    generic_to_h
  end
end