class TracLang::Block

Class for storing forms under their names.

Public Class Methods

delete(filename) click to toggle source

Deletes given file.

# File lib/trac_lang/block.rb, line 36
def self.delete(filename)
  begin
    File.delete(filename)
  rescue Errno::ENOENT
    # ignore non-existant file
  end
end
read(filename, dispatch) click to toggle source

Reads block from the given file. The file may have any valid TRAC commands in it, as well as ordinary text, which will be ignored. The options for trace and savedir will be inherited from the Dispatch calling this method.

# File lib/trac_lang/block.rb, line 12
def self.read(filename, dispatch)
  Executor.new(dispatch).load_file(filename)
end
write(filename, bindings) click to toggle source

Writes block to the given file. Block is written with the following:

  1. Version of the TRAC Language processor

  2. Current time

  3. #(DS) commands for each bound form

  4. #(SS) commands for each bound form that has segments

  5. A mix of #(CN) and #(CS) commands to position the form pointer

# File lib/trac_lang/block.rb, line 22
def self.write(filename, bindings)
  begin
    File.open(filename, "w") do |f|
      f.puts "TRAC Lang Version #{VERSION}"
      f.puts "Saved: #{Time.now}"
      f.puts
      bindings.each { |name, form| f.puts(form.to_trac(name)) if form }
    end
  rescue
    # do nothing if file open fails
  end
end