class Asciidoctor::DocBook45::DocumentTemplate

def author indexed = false

def author indexed = false
  <<-EOF
uthor>
tag 'firstname', indexed ? :"firstname_\#{idx}" : :firstname, indexed}
tag 'othername', indexed ? :"middlename_\#{idx}" : :middlename, indexed}
tag 'surname', indexed ? :"lastname_\#{idx}" : :lastname, indexed}
tag 'email', indexed ? :"email_\#{idx}" : :email, indexed}
author>
  EOF
end

def docinfo

def docinfo
  <<-EOF
 unless notitle %><%= has_header? ? template.title_tags(@header.title) : %(<title>\#{attr 'untitled-label'}</title>) %><% end
 attr? :revdate %>
ate><%= attr :revdate %></date><%
se %>
ate><%= attr :docdate %></date><%
d
 has_header?
if attr? :author
  if (attr :authorcount).to_i < 2 %>
author}
tag 'authorinitials', :authorinitials}<%
  else %>
uthorgroup><%
    (1..((attr :authorcount).to_i)).each do |idx| %>
author true}<%
    end %>
authorgroup><%
  end
end
if (attr? :revnumber) || (attr? :revremark) %>
evhistory>
evision>
tag 'revnumber', :revnumber}
tag 'date', :revdate}
tag 'authorinitials', :authorinitials}
tag 'revremark', :revremark}
revision>
revhistory><%
end %>
= docinfo %>
tag 'orgname', :orgname}<%
d %>
  EOF
end

def template

def template
  @template ||= @eruby.new <<-EOF
#encoding:UTF-8%><?xml version="1.0" encoding="UTF-8"?>
DOCTYPE <%= doctype %> PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"><%
 attr? :toc %>
asciidoc-toc?><%
d
 attr? :numbered %>
asciidoc-numbered?><%
d
 doctype == 'book' %>
ook<% unless attr? :noxmlns %> xmlns="http://docbook.org/ns/docbook"<% end %><% unless attr? :nolang %> lang="<%= attr :lang, 'en' %>"<% end %>>
ookinfo>
docinfo}
bookinfo>
= content %><%= (docinfo_content = docinfo :footer).empty? ? nil : %(
{docinfo_content}) %>
book><%
se %>
rticle<% unless attr? :noxmlns %> xmlns="http://docbook.org/ns/docbook"<% end %><% unless attr? :nolang %> lang="<%= attr :lang, 'en' %>"<% end %>>
rticleinfo>
docinfo}
articleinfo>
= content %><%= (docinfo_content = docinfo :footer).empty? ? nil : %(
{docinfo_content}) %>
article><%
d %>
  EOF
end

def title_tags(str)

def title_tags(str)
  if str.include?(': ')
    title, _, subtitle = str.rpartition(': ')
    %(<title>#{title}</title>
ubtitle>#{subtitle}</subtitle>)
  else
    %(<title>#{str}</title>)
  end
end