Class: TracLang::Block

Inherits:
Object
  • Object
show all
Defined in:
lib/trac_lang/block.rb

Overview

Class for storing forms under their names.

Class Method Summary collapse

Class Method Details

.delete(filename) ⇒ Object

Deletes given file.



36
37
38
39
40
41
42
# 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) ⇒ Object

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.



12
13
14
# File 'lib/trac_lang/block.rb', line 12

def self.read(filename, dispatch)
  Executor.new(dispatch).load_file(filename)
end

.write(filename, bindings) ⇒ Object

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



22
23
24
25
26
27
28
29
30
31
32
33
# 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