Class: P2EStatblockProcessor

Inherits:
Extensions::BlockProcessor
  • Object
show all
Defined in:
lib/asciidoctor-p2e/extension.rb

Instance Method Summary collapse

Instance Method Details

#process(parent, reader, attrs) ⇒ Object



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/asciidoctor-p2e/extension.rb', line 29

def process parent, reader, attrs
  # parse TOML
  lines = reader.lines
  data = Tomlrb.parse(lines * "\n")

  # get/set attributes
  if attrs.key?('type')
    type = attrs['type']
  else
    type = 'creature'
  end
  if attrs.key?('role')
    data['role'] = attrs['role']
  end

  # create HTML from template
  extdir = ::File.join(::File.dirname __FILE__)
  templates = {
    'creature' => "#{extdir}/creatureblock.html.erb",
    'item' => "#{extdir}/itemblock.html.erb",
    'hazard' => "#{extdir}/hazardblock.html.erb"
  }
  template = File.read(templates[type])
  html = ERB.new(template).result_with_hash(data)
  create_pass_block parent, html, attrs, subs: nil
end