class Asciidoctor::BaseTemplate def role attribute('role', :role) end def xreflabel attribute('xreflabel', :reftext) end def title tag('title', 'title') end def tag(name, key) type = key.is_a?(Symbol) ? :attr : :var key = key.to_s if type == :attr # example: <% if attr? 'foo' %><%= attr 'foo' %><% end %> '<% if attr? \'' + key + '\' %><' + name + '><%= attr \'' + key + '\' %><% end %>' else # example: <% unless foo.to_s.empty? %><%= foo %><% end %> '<% unless ' + key + '.to_s.empty? %><' + name + '><%= ' + key + ' %><% end %>' end end end module Asciidoctor::DocBook45 class DocumentTemplate < ::Asciidoctor::BaseTemplate def docinfo <<-EOF <% if has_header? && !notitle %> #{tag 'title', '@header.name'} <% end %> <% if attr? :revdate %> <%= attr :revdate %> <% else %> <%= attr :docdate %> <% end %> <% if has_header? %> <% if attr? :author %> #{tag 'firstname', :firstname} #{tag 'othername', :middlename} #{tag 'surname', :lastname} #{tag 'email', :email} #{tag 'authorinitials', :authorinitials} <% end %> <% if (attr? :revnumber) || (attr? :revremark) %> #{tag 'revision', :revnumber} #{tag 'date', :revdate} #{tag 'authorinitials', :authorinitials} #{tag 'revremark', :revremark} <% end %> <% end %> EOF end def template @template ||= @eruby.new <<-EOF <%#encoding:UTF-8%> PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> <% if attr? :toc %><% end %> <% if attr? :numbered %><% end %> <% if doctype == 'book' %> #{docinfo} <%= content %> <% else %>
#{docinfo} <%= content %>
<% end %> EOF end end class EmbeddedTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOS <%#encoding:UTF-8%> <%= content %> EOS end end class BlockPreambleTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOF <%#encoding:UTF-8%> <% if document.doctype == 'book' %> <%= title %> <%= content %> <% else %> <%= content %> <% end %> EOF end end class SectionTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOF <%#encoding:UTF-8%> <<%= document.doctype == 'book' && level <= 1 ? 'chapter' : 'section' %>#{id}#{role}#{xreflabel}> #{title} <%= content %> > EOF end end class BlockParagraphTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOF <%#encoding:UTF-8%> <% if !title? %> <%= content %> <% else %> <%= title %> <%= content %> <% end %> EOF end end class BlockAdmonitionTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOF <%#encoding:UTF-8%> <<%= attr :name %>#{id}#{role}#{xreflabel}> #{title} <% if blocks? %> <%= content %> <% else %> <%= content.chomp %> <% end %> > EOF end end class BlockUlistTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOF <%#encoding:UTF-8%> #{title} <% content.each do |li| %> <%= li.text %> <% if li.blocks? %> <%= li.content %> <% end %> <% end %> EOF end end class BlockOlistTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOF <%#encoding:UTF-8%> #{title} <% content.each do |li| %> <%= li.text %> <% if li.blocks? %> <%= li.content %> <% end %> <% end %> EOF end end class BlockColistTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOF <%#encoding:UTF-8%> #{title} <% content.each do |li| %> <%= li.text %> <% if li.blocks? %> <%= li.content %> <% end %> <% end %> EOF end end class BlockDlistTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOF <%#encoding:UTF-8%> #{title} <% content.each do |dt, dd| %> <%= dt.text %> <% unless dd.nil? %> <% if dd.text? %> <%= dd.text %> <% end %> <% if dd.blocks? %> <%= dd.content %> <% end %> <% end %> <% end %> EOF end end class BlockOpenTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOS <%#encoding:UTF-8%> <%= content %> EOS end end class BlockListingTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOF <%#encoding:UTF-8%> <% if !title? %> <% if (attr :style) == 'source' %> <%= template.preserve_endlines(content, self) %> <% else %> <%= template.preserve_endlines(content, self) %> <% end %> <% else %> <%= title %> <% if (attr :style) == 'source' %> <%= template.preserve_endlines(content, self) %> <% else %> <%= template.preserve_endlines(content, self) %> <% end %> <% end %> EOF end end class BlockLiteralTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOF <%#encoding:UTF-8%> <% if !title? %> <%= template.preserve_endlines(content, self) %> <% else %> <%= title %> <%= template.preserve_endlines(content, self) %> <% end %> EOF end end class BlockExampleTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOF <%#encoding:UTF-8%> #{title} <%= content %> EOF end end class BlockSidebarTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOF <%#encoding:UTF-8%> #{title} <%= content %> EOF end end class BlockQuoteTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOF <%#encoding:UTF-8%> #{title} <% if (attr? :attribution) || (attr? :citetitle) %> <% if attr? :attribution %> <%= attr(:attribution) %> <% end %> #{tag 'citetitle', :citetitle} <% end %> <% if !buffer.nil? %> <%= content %> <% else %> <%= content %> <% end %> EOF end end class BlockVerseTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOF <%#encoding:UTF-8%> #{title} <% if (attr? :attribution) || (attr? :citetitle) %> <% if attr? :attribution %> <%= attr(:attribution) %> <% end %> #{tag 'citetitle', :citetitle} <% end %> <%= content %> EOF end end class BlockPassTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOS <%#encoding:UTF-8%> <%= content %> EOS end end class BlockTableTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOS <%#encoding:UTF-8%> <<%= title? ? 'table' : 'informaltable'%>#{id}#{role}#{xreflabel} frame="<%= attr :frame, 'all'%>" rowsep="<%= ['none', 'cols'].include?(attr :grid) ? 0 : 1 %>" colsep="<%= ['none', 'rows'].include?(attr :grid) ? 0 : 1 %>"> #{title} <% if attr? :width %> "?> "?> "?> <% end %> <% @columns.each do |col| %> <% end %> <% [:head, :foot, :body].select {|tsec| !rows[tsec].empty? }.each do |tsec| %> > <% @rows[tsec].each do |row| %> <% row.each do |cell| %> namest="col_<%= cell.column.attr :colnumber %>" nameend="col_<%= (cell.column.attr :colnumber) + cell.colspan - 1 %>"<% end %><% if cell.rowspan %> morerows="<%= cell.rowspan - 1 %>"<% end %>><% if tsec == :head %><%= cell.text %><% else %><% case cell.attr(:style) when :asciidoc %><%= cell.content %><% when :verse %><%= template.preserve_endlines(cell.text, self) %><% when :literal %><%= template.preserve_endlines(cell.text, self) %><% when :header %><% cell.content.each do |text| %><%= text %><% end %><% else %><% cell.content.each do |text| %><%= text %><% end %><% %><% end %><% end %> <% end %> <% end %> > <% end %> > EOS end end class BlockImageTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOF <%#encoding:UTF-8%> #{title} <%= attr :alt %> EOF end end class BlockRulerTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOF EOF end end class InlineBreakTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOF <%= text %> EOF end end class InlineQuotedTemplate < ::Asciidoctor::BaseTemplate QUOTED_TAGS = { :emphasis => ['', ''], :strong => ['', ''], :monospaced => ['', ''], :superscript => ['', ''], :subscript => ['', ''], :double => [Asciidoctor::INTRINSICS['ldquo'], Asciidoctor::INTRINSICS['rdquo']], :single => [Asciidoctor::INTRINSICS['lsquo'], Asciidoctor::INTRINSICS['rsquo']], :none => ['', ''] } def template @template ||= @eruby.new <<-EOF <% tags = template.class::QUOTED_TAGS[@type] %><%= tags.first %><% if attr? :role %><% end %><%= @text %><% if attr? :role %><% end %><%= tags.last %> EOF end end class InlineAnchorTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOF <% if @type == :xref %><% if @text.nil? %><% else %><%= @text %><% end %><% elsif @type == :ref %><% else %><%= @text %><% end %> EOF end end class InlineImageTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOF <%= attr :alt %> EOF end end class InlineCalloutTemplate < ::Asciidoctor::BaseTemplate def template @template ||= @eruby.new <<-EOF EOF end end end