Module: Livetext::UserAPI

Included in:
Processor
Defined in:
lib/userapi.rb

Instance Method Summary collapse

Instance Method Details

#_argsObject



21
22
23
24
25
26
27
# File 'lib/userapi.rb', line 21

def _args
  if block_given?
    @_args.each {|arg| yield arg }
  else
    @_args
  end
end

#_body(raw = false) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/userapi.rb', line 70

def _body(raw=false)
  lines = []      #   @save_location = @sources.last
  end_found = false
  loop do
    @line = nextline
    break if @line.nil?
    @line.chomp!
    end_found = _end?(@line)
    break if end_found 
    next if _comment?(@line)  # FIXME Will cause problem with $. ?
    @line = _format(@line) unless raw
    lines << @line 
  end

  _optional_blank_line
  if block_given?
    lines.each {|line| yield line }   # FIXME what about $. ?
  else
    lines
  end
rescue => err
  str = "Fake error? 'Expecting .end, found end of file'\n" 
  str << err.inspect + "\n"
  str << err.backtrace.map {|x| "  " + x }.join("\n")
STDERR.puts str
exit
#   _error!(str)
end

#_body_text(raw = false) ⇒ Object



99
100
101
# File 'lib/userapi.rb', line 99

def _body_text(raw=false)
  _body(Livetext::Sigil).join("\n")
end

#_check_existence(file, msg) ⇒ Object



13
14
15
# File 'lib/userapi.rb', line 13

def _check_existence(file, msg)
  _error! msg unless File.exist?(file)
end

#_comment?(str) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
# File 'lib/userapi.rb', line 35

def _comment?(str)
  sigil = Livetext::Sigil
  c1 = sigil + Livetext::Space
  c2 = sigil + sigil + Livetext::Space
  str.index(c1) == 0 || str.index(c2) == 0
end

#_debug(*args) ⇒ Object



155
156
157
# File 'lib/userapi.rb', line 155

def _debug(*args)
  TTY.puts *args if @_debug
end

#_debug=(val) ⇒ Object



151
152
153
# File 'lib/userapi.rb', line 151

def _debug=(val)
  @_debug = val
end

#_end?(str) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
# File 'lib/userapi.rb', line 47

def _end?(str)
  return true if str == ".end" || str =~ / *\$\.end/
  return false
end

#_format(line) ⇒ Object



115
116
117
118
119
120
# File 'lib/userapi.rb', line 115

def _format(line)
  return "" if line == "\n"
  line2 = FormatLine.parse!(line)
  line.replace(line2) unless line.nil?
  line
end

#_handle_escapes(str, set) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/userapi.rb', line 107

def _handle_escapes(str, set)
  str = str.dup
  set.each_char do |ch|
    str.gsub!("\\#{ch}", ch)
  end
  str
end

#_optional_blank_lineObject



29
30
31
32
33
# File 'lib/userapi.rb', line 29

def _optional_blank_line
  peek = peek_nextline
  return if peek.nil?
  @line = nextline if peek =~ /^ *$/
end

#_out(str = "", file = nil) ⇒ Object



129
130
131
132
133
134
135
136
137
# File 'lib/userapi.rb', line 129

def _out(str = "", file = nil)
  return if str.nil?
  if file.nil?   # FIXME  do this elsewhere?
    @parent.body << str 
    @parent.body << "\n" unless str.end_with?("\n")
  else
    file.puts str
  end
end

#_out!(str = "") ⇒ Object



139
140
141
# File 'lib/userapi.rb', line 139

def _out!(str = "")
  @parent.body << str  # no newline
end

#_passthru(line) ⇒ Object



122
123
124
125
126
127
# File 'lib/userapi.rb', line 122

def _passthru(line)
  return if @_nopass
  _out "<p>" if line == "\n" and ! @_nopara
  line = _format(line)
  _out line
end

#_print(*args) ⇒ Object



147
148
149
# File 'lib/userapi.rb', line 147

def _print(*args)
  @output.print *args 
end

#_puts(*args) ⇒ Object



143
144
145
# File 'lib/userapi.rb', line 143

def _puts(*args)
  @output.puts *args 
end

#_raw_body(tag = "__EOF__") ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/userapi.rb', line 52

def _raw_body(tag = "__EOF__")
  lines = []
#   @save_location = @sources.last
  loop do
    @line = nextline
    break if @line.nil?
    break if @line.chomp.strip == tag
    lines << @line
  end
  _optional_blank_line
  if block_given?
    lines.each {|line| yield line }
  else
    lines
  end
  lines
end

#_raw_body!Object



103
104
105
# File 'lib/userapi.rb', line 103

def _raw_body!
  _raw_body(Livetext::Sigil).join("\n")
end

#_sourceObject



17
18
19
# File 'lib/userapi.rb', line 17

def _source
  @input
end

#_trailing?(char) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
# File 'lib/userapi.rb', line 42

def _trailing?(char)
  return true if ["\n", " ", nil].include?(char)
  return false
end

#setvar(var, val) ⇒ Object



7
8
9
10
11
# File 'lib/userapi.rb', line 7

def setvar(var, val)
  str, sym = var.to_s, var.to_sym
  Livetext::Vars[str] = val
  Livetext::Vars[sym] = val
end