require 'helpers'
# Created as an "ad hoc" lib for generating the README
module Tutorial
include Livetext::Helpers
def title(args = nil, body = nil)
h1
_optional_blank_line
end
def section(args = nil, body = nil)
h3
_optional_blank_line
end
def code(args = nil, body = nil)
first = true # dumb hack! fixes blank space
_body do |line|
tag, first = "
", false if first
_out "#{tag} #{escape_html(line)}" # indentation
end
_out "
"
_optional_blank_line
end
def rx(str)
::Regexp.compile(::Regexp.escape(str))
end
def inout(args = nil, body = nil)
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
_out <<-HTML
HTML
_optional_blank_line
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
_out <<-HTML
HTML
end
def testcase(args = nil, body = nil)
name = _args.first
_out "\nTest: #{name}
"
src, exp = "test/snapshots/#{name}/source.lt3", "test/snapshots/#{name}/expected-output.txt"
@_args = [src, exp] # Better way to do this??
put_table(src, exp)
_out "
"
_optional_blank_line
end
end