Sha256: 6ded7ab57332880da23b628cbc45954e0431ecdbd0a3c7f91814ea77ae178085

Contents?: true

Size: 1.97 KB

Versions: 19

Compression:

Stored size: 1.97 KB

Contents

require 'cgi'

def title
  h1
end

def section
  h3
end

def code
# _out "<pre>"
  first = true  # dumb hack! fixes blank space
  _body do |line| 
    if first
      tag = "<pre>"
      first = false
    else
    end
    _out "#{tag}   #{::CGI.escape_html(line)}"   # indentation
  end
  _out "</pre>"
end

def rx(str)
  ::Regexp.compile(::Regexp.escape(str))
end

def inout
  src, out = _args
  t1 = ::File.readlines(src) rescue (abort "t1 = #{src}")
  t2 = ::File.readlines(out) rescue (abort "t2 = #{out}")
  # To pacify markdown for README (FIXME later)
  t1 = t1.map {|x| " " + x.sub(/ +$/,"").gsub(/_/, "\\_") }.join
  t2 = t2.map {|x| " " + x.sub(/ +$/,"").gsub(/_/, "\\_") }.join

  puts <<-HTML
    <table width=80% cellpadding=4>
    <tr>
      <td width=50%><b>Input</b></td>
      <td width=50%><b>Output</b></td>
    </tr>
    <tr>
      <td width=50% bgcolor=#fee0fe valign=top>
        <pre>#{t1}</pre>
      </td>
      <td width=50% bgcolor=#eeeeee valign=top>
        <pre>#{t2}</pre>
      </td>
    </tr>
    </table>
  HTML
end

def put_table(src, exp)
  t1 = ::File.readlines(src) rescue (abort "t1 = #{src}")
  t2 = ::File.readlines(exp) rescue (abort "t2 = #{out}")
  t1 = t1.map {|x| " " + x.sub(/ +$/,"").gsub(/_/, "\\_") }.join
  t2 = t2.map {|x| " " + x.sub(/ +$/,"").gsub(/_/, "\\_") }.join

  puts <<-HTML
    <font size=+1>
    <table width=80% cellpadding=4>
    <tr>
      <td width=50%><b>Input</b></td>
      <td width=50%><b>Output</b></td>
    </tr>
    <tr>
      <td width=50% bgcolor=#fee0fe valign=top>
        <pre>#{t1}</pre>
      </td>
      <td width=50% bgcolor=#eeeeee valign=top>
        <pre>#{t2}</pre>
      </td>
    </tr>
    </table>
    </font>
  HTML
end

def testcase
  name = _args.first
  _out "\n<font size=+1><b>Test: </font><font size=+2><tt>#{name}</tt></font></b></h3><br>"
  src, exp = "test/data/#{name}/source.lt3", "test/data/#{name}/expected-output.txt"
  @_args = [src, exp]   # Better way to do this??
  put_table(src, exp)
  _out "<br>"
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
livetext-0.8.96 plugin/tutorial.rb
livetext-0.8.95 plugin/tutorial.rb
livetext-0.8.94 plugin/tutorial.rb
livetext-0.8.93 plugin/tutorial.rb
livetext-0.8.92 plugin/tutorial.rb
livetext-0.8.91 plugin/tutorial.rb
livetext-0.8.89 plugin/tutorial.rb
livetext-0.8.88 plugin/tutorial.rb
livetext-0.8.87 plugin/tutorial.rb
livetext-0.8.86 plugin/tutorial.rb
livetext-0.8.85 plugin/tutorial.rb
livetext-0.8.84 plugin/tutorial.rb
livetext-0.8.83 plugin/tutorial.rb
livetext-0.8.82 plugin/tutorial.rb
livetext-0.8.81 plugin/tutorial.rb
livetext-0.8.80 plugin/tutorial.rb
livetext-0.8.79 plugin/tutorial.rb
livetext-0.8.78 plugin/tutorial.rb
livetext-0.8.77 plugin/tutorial.rb