Module: Livetext::UserAPI

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

Instance Method Summary collapse

Instance Method Details

#_argsObject



15
16
17
18
19
20
21
# File 'lib/userapi.rb', line 15

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

#_body(raw = false) ⇒ Object



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
98
99
# File 'lib/userapi.rb', line 71

def _body(raw=false)
  lines = []
  @save_location = @sources.last
  end_found = false
  loop do
    @line = nextline
    break if @line.nil?
    @line.chomp!
    if _end?(@line)
      end_found = true
      break 
    end
    next if _comment?(@line)
    # FIXME Will cause problem with $. ?
    @line = _format(@line) unless raw
    lines << @line 
  end
  raise unless end_found
  _optional_blank_line
  if block_given?
    lines.each {|line| yield line }   # FIXME what about $. ?
  else
    lines
  end
rescue => err
#   p err.inspect
#   puts err.backtrace
  _error!("Expecting .end, found end of file")
end

#_body_text(raw = false) ⇒ Object



101
102
103
# File 'lib/userapi.rb', line 101

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

#_check_existence(file, msg) ⇒ Object



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

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

#_comment?(str) ⇒ Boolean

Returns:

  • (Boolean)


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

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



153
154
155
# File 'lib/userapi.rb', line 153

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

#_debug=(val) ⇒ Object



149
150
151
# File 'lib/userapi.rb', line 149

def _debug=(val)
  @_debug = val
end

#_end?(str) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/userapi.rb', line 41

def _end?(str)
  indent = ""
#   n = @parent.indentation.last - 1
#   n = 0 if n < 0  # Gahhh FIXM
#   indent = " " * n
#   indent << "$" unless indent.empty?
  return false if str.nil?
  cmd = indent + Livetext::Sigil + "end"
  return false if str.index(cmd) != 0 
  return false unless _trailing?(str[5])
  return true
end

#_format(line) ⇒ Object



117
118
119
120
121
122
# File 'lib/userapi.rb', line 117

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

#_handle_escapes(str, set) ⇒ Object



109
110
111
112
113
114
115
# File 'lib/userapi.rb', line 109

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

#_optional_blank_lineObject



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

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

#_out(str = "") ⇒ Object



131
132
133
134
135
# File 'lib/userapi.rb', line 131

def _out(str = "")
  return if str.nil?
  @parent.body << str 
  @parent.body << "\n" unless str.end_with?("\n")
end

#_out!(str = "") ⇒ Object



137
138
139
# File 'lib/userapi.rb', line 137

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

#_passthru(line) ⇒ Object



124
125
126
127
128
129
# File 'lib/userapi.rb', line 124

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

#_print(*args) ⇒ Object



145
146
147
# File 'lib/userapi.rb', line 145

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

#_puts(*args) ⇒ Object



141
142
143
# File 'lib/userapi.rb', line 141

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

#_raw_body(tag = "__EOF__") ⇒ Object



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

def _raw_body(tag = "__EOF__")
  lines = []
  @save_location = @sources.last
  loop do
    @line = nextline
    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



105
106
107
# File 'lib/userapi.rb', line 105

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

#_sourceObject



11
12
13
# File 'lib/userapi.rb', line 11

def _source
  @input
end

#_trailing?(char) ⇒ Boolean

Returns:

  • (Boolean)


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

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