class Asciidoctor::BaseTemplate
this same issue.
prevent quote processing. This requirement seems hackish, but AsciiDoc has
NOTE we must use double quotes for attribute values in the HTML/XML output to
backend templates. Concrete subclasses must implement the template method.
An abstract base class that provides methods for definining and rendering the
def self.inherited(klass)
def self.inherited(klass) @template_classes ||= [] @template_classes << klass end
def self.template_classes
def self.template_classes @template_classes end
def attribute(name, key)
def attribute(name, key) type = key.is_a?(Symbol) ? :attr : :var if type == :attr # example: <% if attr? 'foo' %> bar="<%= attr 'foo' %>"<% end %> %(<% if attr? '#{key}' %> #{name}="<%= attr '#{key}' %>"<% end %>) else # example: <% if foo %> bar="<%= foo %>"<% end %> %(<% if #{key} %> #{name}="<%= #{key} %>"<% end %>) end end
def attrvalue(key, sibling = true)
def attrvalue(key, sibling = true) delimiter = sibling ? ' ' : '' # example: <% if attr? 'foo' %><%= attr 'foo' %><% end %> %(<% if attr? '#{key}' %>#{delimiter}<%= attr '#{key}' %><% end %>) end
def common_attrs(id, role, reftext)
def common_attrs(id, role, reftext) %(#{id && " id=\"#{id}\""}#{role && " role=\"#{role}\""}#{reftext && " xreflabel=\"#{reftext}\""}) end
def common_attrs_erb
def common_attrs_erb %q{<%= template.common_attrs(@id, (attr 'role'), (attr 'reftext')) %>} end
def compact(str)
returns the text with blank lines removed and HTML line feed entities
text - the String to process
every HTML line feed entity found with an endline character.
Public: Compact blank lines in the provided text. This method also restores
def compact(str) str.gsub(BLANK_LINES_PATTERN, '').gsub(LINE_FEED_ENTITY, "\n") end
def id
def id attribute('id', '@id') end
def initialize(view, eruby)
def initialize(view, eruby) @view = view @eruby = eruby end
def preserve_endlines(str, node)
text - the String to process
replacement. Otherwise, return the text unprocessed.
If the compact flag on the document's renderer is true, perform the
Public: Preserve endlines by replacing them with the HTML line feed entity.
def preserve_endlines(str, node) node.renderer.compact ? str.gsub("\n", LINE_FEED_ENTITY) : str end
def render(node = Object.new, locals = {})
node - The concrete instance of AsciiDoctor::AbstractNode to render
the rendered output is returned unprocessed.
document or embedded, then blank lines in the output are compacted. Otherwise,
If the compact flag on the document's renderer is true and the view context is
accessible to the template data via the local variable named 'template'.
supplied concrete instance of Asciidoctor::AbstractNode. This instance is
template data and then evaluates that template in the context of the
This method invokes the template method on this instance to retrieve the
the supplied concrete instance of Asciidoctor::AbstractNode.
Public: Render this template in the execution context of
def render(node = Object.new, locals = {}) tmpl = template if tmpl.equal? :content result = node.content #elsif tmpl.is_a?(String) # result = tmpl else result = tmpl.result(node.get_binding(self)) end if (@view == 'document' || @view == 'embedded') && node.renderer.compact compact result else result end end
def role_class
def role_class attrvalue(:role) end
def style_class(sibling = true)
def style_class(sibling = true) attrvalue(:style, sibling) end
def tag(name, key)
def tag(name, key) type = key.is_a?(Symbol) ? :attr : :var key = key.to_s if type == :attr # example: <% if attr? 'foo' %><bar><%= attr 'foo' %></bar><% end %> %(<% if attr? '#{key}' %><#{name}><%= attr '#{key}' %></#{name}><% end %>) else # example: <% unless foo.to_s.empty? %><bar><%= foo %></bar><% end %> %(<% unless #{key}.to_s.empty? %><#{name}><%= #{key} %></#{name}><% end %>) end end
def template
def template raise "You chilluns need to make your own template" end
def title_div(opts = {})
def title_div(opts = {}) %(<% if title? %><div class="title">#{opts.has_key?(:caption) ? '<%= @caption %>' : ''}<%= title %></div><% end %>) end
def title_tag(optional = true)
def title_tag(optional = true) if optional %q{<%= title? ? "<title>#{title}</title>" : '' %>} else %q{<title><%= title %></title>} end end