<commit_before>class BaseTemplate
  def initialize
  end

  def self.inherited(klass)
    @template_classes ||= []
    @template_classes << klass
  end

  def self.template_classes
    @template_classes
  end

  # We're ignoring locals for now. Shut up.
  def render(obj = Object.new, locals = {})
    output = template.result(obj.instance_eval {binding})
    self.is_a?(DocumentTemplate) ? output.gsub(/^\s*\n/, '') : output
  end

  def template
    raise "You chilluns need to make your own template"
  end

  # create template matter to insert an attribute if the variable has a value
  def attribute(name, var = nil)
    var = var.nil? ? name : var
    if var.is_a? Symbol
      '<%= attr?(:' + var.to_s + ') ? ' + '\' ' + name + '=\\\'\' + attr(:' + var.to_s + ') + \'\\\'\' : \'\' %>'
    else
      '<%= ' + var + ' ? ' + '\' ' + name + '=\\\'\' + ' + var + ' + \'\\\'\' : \'\' %>'
    end
  end

  # create template matter to insert a style class if the variable has a value
  def styleclass(key)
    '<%= attr?(:' + key.to_s + ') ? \' \' + attr(:' + key.to_s + ') : \'\' %>'
  end

  # create template matter to insert an id if one is specified for the block
  def id
    attribute('id')
  end

  # create template matter to insert a style class from the role attribute if specified
  def role
    styleclass(:role)
  end
end

class DocumentTemplate < BaseTemplate
  def template
    @template ||= ::ERB.new <<-EOF
<!DOCTYPE html>
<html lang='en'>
  <head>
    <meta http-equiv='Content-Type' content='text/html; charset=<%= attr :encoding %>'>
    <meta name='generator' content='Asciidoctor <%= attr 'asciidoctor-version' %>'>
    <% if attr? :description %><meta name='description' content='<%= attr :description %>'><% end %>
    <% if attr? :keywords %><meta name='keywords' content='<%= attr :keywords %>'><% end %>
    <title><%= title ? title : (doctitle ? doctitle : '') %></title>
  </head>
  <body class='<%= attr :doctype %>'>
    <div id='header'>
      <% if !notitle && doctitle %>
        <h1><%= doctitle %></h1>
        <% if attr? :author %><span id='author'><%= attr :author %></span><br><% end %>
      <% end %>
    </div>
    <div id='content'>
<%= content %>
    </div>
    <div id='footer'>
      <div id='footer-text'>
        Last updated <%= attr :localdatetime %>
      </div>
    </div>
  </body><commit_msg>add stylesheet if attribute is set<commit_after>class BaseTemplate
  def initialize
  end

  def self.inherited(klass)
    @template_classes ||= []
    @template_classes << klass
  end

  def self.template_classes
    @template_classes
  end

  # We're ignoring locals for now. Shut up.
  def render(obj = Object.new, locals = {})
    output = template.result(obj.instance_eval {binding})
    self.is_a?(DocumentTemplate) ? output.gsub(/^\s*\n/, '') : output
  end

  def template
    raise "You chilluns need to make your own template"
  end

  # create template matter to insert an attribute if the variable has a value
  def attribute(name, var = nil)
    var = var.nil? ? name : var
    if var.is_a? Symbol
      '<%= attr?(:' + var.to_s + ') ? ' + '\' ' + name + '=\\\'\' + attr(:' + var.to_s + ') + \'\\\'\' : \'\' %>'
    else
      '<%= ' + var + ' ? ' + '\' ' + name + '=\\\'\' + ' + var + ' + \'\\\'\' : \'\' %>'
    end
  end

  # create template matter to insert a style class if the variable has a value
  def styleclass(key)
    '<%= attr?(:' + key.to_s + ') ? \' \' + attr(:' + key.to_s + ') : \'\' %>'
  end

  # create template matter to insert an id if one is specified for the block
  def id
    attribute('id')
  end

  # create template matter to insert a style class from the role attribute if specified
  def role
    styleclass(:role)
  end
end

class DocumentTemplate < BaseTemplate
  def template
    @template ||= ::ERB.new <<-EOF
<!DOCTYPE html>
<html lang='en'>
  <head>
    <meta http-equiv='Content-Type' content='text/html; charset=<%= attr :encoding %>'>
    <meta name='generator' content='Asciidoctor <%= attr 'asciidoctor-version' %>'>
    <% if attr? :description %><meta name='description' content='<%= attr :description %>'><% end %>
    <% if attr? :keywords %><meta name='keywords' content='<%= attr :keywords %>'><% end %>
    <title><%= title ? title : (doctitle ? doctitle : '') %></title>
    <% unless attr(:stylesheet, '').empty? %>
    <link rel='stylesheet' href='<%= attr(:stylesdir, '') + attr(:stylesheet) %>' type='text/css'>
    <% end %>
  </head>
  <body class='<%= attr :doctype %>'>
    <div id='header'>
      <% if !notitle && doctitle %>
        <h1><%= doctitle %></h1>
        <% if attr? :author %><span id='author'><%= attr :author %></span><br><% end %>
      <% end %>
    </div>
    <div id='content'>
<%= content %>
    </div>
    <div id='footer'>
      <div id='footer-text'>
        Last updated <%= attr :localdatetime %>
      </div>
    </div>
  </body>
{'fraction_non_alphanumeric': 0.19257588187038557, 'fraction_numerical': 0.0008203445447087777, 'mean_word_length': 2.8371361132966166, 'pattern_counts': {'":': 0, '<': 109, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6014609', 'n_tokens_mistral': 1708, 'n_tokens_neox': 1588, 'n_words': 464}