class P2EStatblockProcessor

Public Instance Methods

process(parent, reader, attrs) click to toggle source
# 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