<commit_before>#!/usr/bin/env ruby

########################################################################
# Generate google code wiki from mailsend -ex output
# Mar-17-2013 
########################################################################
class GenerateMailsendExample
  ME = $0
  ME_SHORT = File.basename(ME)

  def initialize
    $stdout.sync = true
    @url = "https://mailsend.googlecode.com/svn/trunk/ex2wiki.rb"
  end

  def error(msg)
    puts "Error: #{msg}"
    exit 1
  end

  def doit
    if !File.exists?("mailsend")
      error "Program mailsend does not exist"
    end
    mhash = {}
    a = []

    last_header = nil
    block_found = false
    mailsend_found = false
    header = nil
    headers = []
    o = `mailsend -ex`
    new_lines = []
    last_h = ''

    lines = o.split("\n")
    lines.each_index do |i|
      line = lines[i]
      line.chomp!
      line.strip!
      if line =~ /^Example .*$/
        next
      end

      line1 = line
      line1.chomp! if line1
      line1.strip! if line1

      line2 = lines[i + 1]
      line2.chomp! if line2
      line2.strip! if line2
      if line2 =~ /^==.*$/
        last_h = line1
        if last_header && a
          headers << last_header
          mhash[last_header] = a
          a = []
        end
        block_found = true
        last_header = line1
        header = line1
        next
      end
      x = lines[i]
      x.chomp! if x
      x.strip! if x
      if x !~ /^==.*$/
        a << x;
      end
    end
    # handle last one
    headers << last_h
    mhash[last_h] = a

    puts <<EOD
#summary Examples of mailasend
#sidebar Toc
#labels Featured
<wiki:toc />
EOD

    headers.each do |h|
    puts "=#{h}="
      a = mhash[h]
      a.each do |line|
        next if line =~ /^==.*$/
        if line =~ /^mailsend .*$/
          puts "}}}" if mailsend_found
          mailsend_found = true
          puts "{{{"
          puts " $ #{line}"<commit_msg>add version info in example page<commit_after>#!/usr/bin/env ruby

########################################################################
# Generate google code wiki from mailsend -ex output
# Mar-17-2013 
########################################################################
class GenerateMailsendExample
  ME = $0
  ME_SHORT = File.basename(ME)

  def initialize
    $stdout.sync = true
    @url = "https://mailsend.googlecode.com/svn/trunk/ex2wiki.rb"
  end

  def error(msg)
    puts "Error: #{msg}"
    exit 1
  end

  def doit
    if !File.exists?("mailsend")
      error "Program mailsend does not exist"
    end
    mhash = {}
    a = []
    last_header = nil
    block_found = false
    mailsend_found = false
    header = nil
    headers = []
    o = `mailsend -ex`
    new_lines = []
    last_h = ''

    lines = o.split("\n")
    lines.each_index do |i|
      line = lines[i]
      line.chomp!
      line.strip!
      if line =~ /^Example .*$/
        next
      end

      line1 = line
      line1.chomp! if line1
      line1.strip! if line1

      line2 = lines[i + 1]
      line2.chomp! if line2
      line2.strip! if line2
      if line2 =~ /^==.*$/
        last_h = line1
        if last_header && a
          headers << last_header
          mhash[last_header] = a
          a = []
        end
        block_found = true
        last_header = line1
        header = line1
        next
      end
      x = lines[i]
      x.chomp! if x
      x.strip! if x
      if x !~ /^==.*$/
        a << x;
      end
    end
    # handle last one
    headers << last_h
    mhash[last_h] = a

    puts <<EOD
#summary Examples of mailasend
#sidebar Toc
#labels Featured
<wiki:toc />
EOD
# print version info first
    v = `mailsend -V 2>&1`.chomp
    v = v.gsub('^\s+','')
    puts <<-EOS
=VERSION=
These examples are generated using 
{{{
  $ mailsend -V
#{v}
}}}
EOS


    headers.each do |h|
    puts "=#{h}="
      a = mhash[h]
      a.each do |line|
        next if line =~ /^==.*$/
        if line =~ /^mailsend .*$/
          puts "}}}" if mailsend_found
          mailsend_found = true
          puts "{{{"
          puts " $ #{line}"
{'fraction_non_alphanumeric': 0.18798828125, 'fraction_numerical': 0.01220703125, 'mean_word_length': 1.887244538407329, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 6, 'https://': 2, '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': '1712749', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1364, 'n_words': 362}