<commit_before>## Thoughts:
# Support column summing?
module Tablinate
  def self.parse_table_parameters(params={})
  end
  ## A method that determines whether or not to apply params to a tag.
  ## If they are to be applied, apply
  #TODO: get a better function name
  def self.generate_tag(tag, params, offset=0)
    unless params.nil? || params[tag.to_sym].nil?
      html = "<#{tag}"
      params[tag.to_sym].each do |k,v|
        next if v.class == Hash
        if v.class==[].class
          ## mod #{v.count}
          adjusted_offset = offset % v.count
          html+= " #{k}='#{v[adjusted_offset]}'"
        else
          html+= " #{k}='#{v}'"
        end
      end
      html+=">"
    else 
      "<#{tag}>"
    end
  end
  def self.table_head(keys, params)
    params = {} if params.nil?
    thead = generate_tag("thead", params)
    thead += generate_tag("tr", params[:thead])
    keys.each do |key|
      thead += "#{generate_tag("th", params[:thead])}#{key}</th>"
    end
    thead += "</thead>"
    return thead
  end
  def self.table_body(rows, params)
    tbody = generate_tag("tbody", params)
    tr_i = 0
    rows.each do |row|
      tbody += generate_tag("tr", params[:tbody], tr_i)
        td_i = 0
        #there needs to be some way to determinte the max offset and reset back to 0 when that number is reached. 
        row.each do |k,v|
          tbody += "#{generate_tag("td", params[:tbody], td_i)}#{v}</td>"
          td_i += 1
        end
      tbody +="</tr>"
      tr_i += 1
    end
    tbody +="</tbody>"
    return tbody
  end
  #the extraneous args are excluded columns?
  def self.generate_table(object, params, *args)
    table = generate_tag("table", params)
    #thead
    table += table_head(object[0].keys, params[:thead])
    #tbody
    table += table_body(object, params)    
    #tfoot?
    table += "</table>"
  end
end<commit_msg>Added method to add whitespace to html output in order to make it more readable.<commit_after>## Thoughts:
# Support column summing?
module Tablinate
  def self.parse_table_parameters(params={})
  end
  ## A method that determines whether or not to apply params to a tag.
  ## If they are to be applied, apply
  #TODO: get a better function name
  def self.generate_tag(tag, params, offset=0)
    unless params.nil? || params[tag.to_sym].nil?
      html = "<#{tag}"
      params[tag.to_sym].each do |k,v|
        next if v.class == Hash
        if v.class==[].class
          ## mod #{v.count}
          adjusted_offset = offset % v.count
          html+= " #{k}='#{v[adjusted_offset]}'"
        else
          html+= " #{k}='#{v}'"
        end
      end
      html+=">"
    else 
      "<#{tag}>"
    end
  end
  def self.table_head(keys, params)
    params = {} if params.nil?
    thead = generate_tag("thead", params)
    thead += generate_tag("tr", params[:thead])
    keys.each do |key|
      thead += "#{generate_tag("th", params[:thead])}#{key}</th>"
    end
    thead += "</thead>"
    return thead
  end
  def self.table_body(rows, params)
    tbody = generate_tag("tbody", params)
    tr_i = 0
    rows.each do |row|
      tbody += generate_tag("tr", params[:tbody], tr_i)
        td_i = 0
        #there needs to be some way to determinte the max offset and reset back to 0 when that number is reached. 
        row.each do |k,v|
          tbody += "#{generate_tag("td", params[:tbody], td_i)}#{v}</td>"
          td_i += 1
        end
      tbody +="</tr>"
      tr_i += 1
    end
    tbody +="</tbody>"
    return tbody
  end
  #the extraneous args are excluded columns?
  def self.format_html(html)
    html.split('')
    tags = html.scan(%r{</?[^>]+?>}).uniq
    tags.each do |tag|
      if tag.length > 5 || tag.include?("/") || tag.include?("tr>")
        html = html.gsub(tag,"#{tag}\n") 
      else
        html = html.gsub(tag,"\s\s#{tag}")
      end
    end
    return html
  end
  def self.generate_table(object, params, *args)
    table = generate_tag("table", params)
    #thead
    table += table_head(object[0].keys, params[:thead])
    #tbody
    table += table_body(object, params)    
    #tfoot?
    table += "</table>"
    table = format_html(table)
  end
end
{'fraction_non_alphanumeric': 0.15174069627851142, 'fraction_numerical': 0.003601440576230492, 'mean_word_length': 2.465890183028286, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 23, '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': '2079935', 'n_tokens_mistral': 1407, 'n_tokens_neox': 1374, 'n_words': 396}