Class: Livetext::Processor

Inherits:
Object
  • Object
show all
Includes:
Standard, UserAPI
Defined in:
lib/livetext.rb

Constant Summary collapse

Disallowed =
[:nil?, :===, :=~, :!~, :eql?, :hash, :<=>, 
:class, :singleton_class, :clone, :dup, :taint, :tainted?, 
:untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, 
:to_s, :inspect, :methods, :singleton_methods, :protected_methods, 
:private_methods, :public_methods, :instance_variables, 
:instance_variable_get, :instance_variable_set, 
:instance_variable_defined?, :remove_instance_variable, 
:instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, 
:respond_to?, :extend, :display, :method, :public_method, 
:singleton_method, :define_singleton_method, :object_id, :to_enum, 
:enum_for, :pretty_inspect, :==, :equal?, :!, :!=, :instance_eval, 
:instance_exec, :__send__, :__id__, :__binding__]

Constants included from Standard

Standard::SimpleFormats

Instance Attribute Summary

Attributes included from Standard

#_data

Instance Method Summary collapse

Methods included from UserAPI

#_args, #_body, #_body_text, #_check_existence, #_comment?, #_debug, #_debug=, #_end?, #_formatting, #_handle_escapes, #_optional_blank_line, #_out, #_passthru, #_print, #_puts, #_raw_body, #_raw_body!, #_source, #_trailing?

Methods included from Standard

#_append, #_def, #_include, #_next_output, #_output, #append, #backtrace, #banner, #bits, #br, #cleanup, #comment, #copy, #data=, #debug, #dlist, #errout, #func, #heading, #heredoc, #include!, #invoke, #link, #mixin, #mono, #newpage, #next_output, #nopara, #nopass, #old_dlist, #outdir, #outdir!, #output, #para, #passthru, #quit, #r, #raw, #say, #set, #shell, #shell!, #xtable

Constructor Details

#initialize(parent, output = nil) ⇒ Processor

Returns a new instance of Processor.



50
51
52
53
54
55
56
57
58
# File 'lib/livetext.rb', line 50

def initialize(parent, output = nil)
  @parent = parent
  @_nopass = false
  @_nopara = false
  parent.no_puts = output.nil?
  @body = ""  # not always used
  @output = ::Livetext.output = (output || File.open("/dev/null", "w"))
  @sources = []
end

Instance Method Details

#_disallowed?(name) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/livetext.rb', line 72

def _disallowed?(name)
  Disallowed.include?(name.to_sym)
end

#_error!(err, abort = true, trace = false) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/livetext.rb', line 64

def _error!(err, abort=true, trace=false)
  where = @sources.last || @save_location
  STDERR.puts "Error: #{err} (at #{where[1]} line #{where[2]})"
#     STDERR.puts err.backtrace if @backtrace && err.respond_to?(:backtrace)
  STDERR.puts err.backtrace if err.respond_to?(:backtrace)
  exit if abort
end

#grab_file(fname) ⇒ Object



97
98
99
# File 'lib/livetext.rb', line 97

def grab_file(fname)
  File.read(fname)
end

#nextlineObject



87
88
89
90
91
92
93
94
95
# File 'lib/livetext.rb', line 87

def nextline
  return nil if @sources.empty?
  line = @sources.last[0].next
  @sources.last[2] += 1
  line
rescue StopIteration
  @sources.pop
  nil
end

#output=(io) ⇒ Object



60
61
62
# File 'lib/livetext.rb', line 60

def output=(io)
  @output = io
end

#peek_nextlineObject



80
81
82
83
84
85
# File 'lib/livetext.rb', line 80

def peek_nextline
  @sources.last[0].peek
rescue StopIteration
  @sources.pop
  nil
end

#source(enum, file, line) ⇒ Object



76
77
78
# File 'lib/livetext.rb', line 76

def source(enum, file, line)
  @sources.push([enum, file, line])
end