module Livetext::Standard SimpleFormats = # Move this? { b: %w[ ], i: %w[ ], t: %w[ ], s: %w[ ] } attr_reader :_data def data=(val) @_data = val @_args = val.split @_mixins = [] end def bits # dumb name - bold, italic, teletype, striketrough b0, b1, i0, i1, t0, t1, s0, s1 = *@_args SimpleFormats[:b] = [b0, b1] SimpleFormats[:i] = [i0, i1] SimpleFormats[:t] = [t0, t1] SimpleFormats[:s] = [s0, s1] end def backtrace arg = @_args.first @backtrace = true @backtrace = false if arg == "off" end def comment _body end def shell cmd = @_data _errout("Running: #{cmd}") system(cmd) end def func funcname = @_args[0] _error! "Illegal name '#{funcname}'" if _disallowed?(funcname) func_def = <<-EOS def #{funcname} #{_body!} end EOS Livetext::Functions.class_eval func_def end def shell! cmd = @_data system(cmd) end def errout TTY.puts @_data end def say str = _formatting(@_data) TTY.puts str _optional_blank_line end def banner str = _formatting(@_data) n = str.length - 1 _errout "-"*n _errout str _errout "-"*n end def quit @output.close exit end def outdir @_outdir = @_args.first _optional_blank_line end def outdir! # FIXME ? @_outdir = @_args.first raise "No output directory specified" if @_outdir.nil? raise "No output directory specified" if @_outdir.empty? system("rm -f #@_outdir/*.html") _optional_blank_line end def _output(name) @_outdir ||= "." # FIXME @output.close unless @output == STDOUT @output = File.open(@_outdir + "/" + name, "w") @output.puts "\n\n" end def _append(name) @_outdir ||= "." # FIXME @output.close unless @output == STDOUT @output = File.open(@_outdir + "/" + name, "a") @output.puts "\n\n" end def output name = @_args.first _debug "Redirecting output to: #{name}" _output(name) end def append file = @_args[0] _append(file) end def next_output tag, num = @_args _next_output(tag, num) _optional_blank_line end def cleanup @_args.each do |item| if ::File.directory?(item) system("rm -f #{item}/*") else ::FileUtils.rm(item) end end end def _next_output(tag = "sec", num = nil) @_file_num = num ? num : @_file_num + 1 @_file_num = @_file_num.to_i name = "#{'%03d' % @_file_num}-#{tag}.html" _output(name) end def _def name = @_args[0] str = "def #{name}\n" raise "Illegal name '#{name}'" if _disallowed?(name) str += _body! str += "end\n" eval str rescue => err _error!(err) end def set assigns = @_data.chomp.split(/, */) # Do a better way? assigns.each do |a| var, val = a.split("=") val = val[1..-2] if val[0] == ?" and val[-1] == ?" val = val[1..-2] if val[0] == ?' and val[-1] == ?' Livetext::Vars[var] = val end _optional_blank_line end def _include file = @_args.first _check_existence(file, "No such include file '#{file}'") @parent.process_file(file) _optional_blank_line end def include! # FIXME huh? file = @_args.first return unless File.exist?(file) lines = @parent.process_file(file) File.delete(file) _optional_blank_line end def mixin name = @_args.first # Expect a module name file = "#{Plugins}/" + name.downcase + ".rb" return if @_mixins.include?(name) file = "./#{name}.rb" unless File.exist?(file) _check_existence(file, "No such mixin '#{name}'") @_mixins << name meths = grab_file(file) modname = name.gsub("/","_").capitalize string = "module ::#{modname}\n#{meths}\nend" eval(string) newmod = Object.const_get("::" + modname) self.extend(newmod) init = "init_#{name}" self.send(init) if self.respond_to? init # STDERR.puts "mixin: self = #{self} @meta = #@meta" _optional_blank_line end def copy file = @_args.first _check_existence(file, "No such file '#{file}' to copy") @output.puts grab_file(file) _optional_blank_line end def r _puts @_data # No processing at all end def raw # No processing at all (terminate with __EOF__) _puts _raw_body end def debug arg = @_args.first self._debug = true self._debug = false if arg == "off" end def passthru # FIXME - add check for args size (helpers); _onoff helper?? onoff = _args.first case onoff when nil; @_nopass = false when "on"; @_nopass = false when "off"; @_nopass = true else _error!("Unknown arg '#{onoff}'") end end def nopass @_nopass = true end def para # FIXME - add check for args size (helpers); _onoff helper?? onoff = _args.first case onoff when nil; @_nopara = false when "on"; @_nopara = false when "off"; @_nopara = true else _error!("Unknown arg '#{onoff}'") end end def nopara @_nopara = true end def heading _print "
" _print @_data _print "
" end def newpage _puts '

' _puts "

" end def invoke(str) end def dlist delim = _args.first _puts "" _body do |line| line = _formatting(line) term, defn = line.split(delim) _puts "" _puts "" _puts "" end _puts "
#{term}#{defn}
" end end