Class: Livetext::UserAPI
Overview
Encapsulate the UserAPI as a class
Constant Summary
collapse
- KBD =
File.new("/dev/tty", "r")
- TTY =
File.new("/dev/tty", "w")
- DotSpace =
Livetext::Sigil + Livetext::Space
". "
Constants included
from Standard
Standard::SimpleFormats
Constants included
from Helpers
Helpers::Comment, Helpers::DollarDot, Helpers::DotCmd, Helpers::ESCAPING, Helpers::Sigil, Helpers::Space
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Standard
#backtrace, #banner, #bits, #br, #cinclude, #cleanup, #comment, #copy, #dlist, #dot_def, #dot_include, #errout, #func, #functions, #h1, #h2, #h3, #h4, #h5, #h6, #heading, #heredoc, #heredoc!, #image, #import, #inherit, #link, #list, #list!, #mixin, #mono, #newpage, #nopara, #nopass, #para, #quit, #r, #raw, #reflection, #say, #seek, #set, #shell, #shell!, #table, #ttyout, #variables, #variables!, #xtable
Methods included from Helpers
#check_disallowed, #escape_html, #file_exists?, #find_file, #friendly_error, #get_name_data, #grab_file, #graceful_error, #handle_dollar_dot, #handle_dotcmd, #handle_scomment, #invoke_dotcmd, #onoff, #process_file, #process_line, #read_variables, rx, #search_upward, #set_variables, #setfile, #setfile!, #showme
#check_disallowed, #check_file_exists, #cwd_root?, #grab_file, #search_upward
Instance Attribute Details
Returns the value of attribute args.
15
16
17
|
# File 'lib/livetext/userapi.rb', line 15
def args
@args
end
|
Returns the value of attribute data.
15
16
17
|
# File 'lib/livetext/userapi.rb', line 15
def data
@data
end
|
Instance Method Details
26
27
28
|
# File 'lib/livetext/userapi.rb', line 26
def api
@live.api
end
|
#body(raw = false) ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/livetext/userapi.rb', line 131
def body(raw=false)
lines = []
end_found = false
loop do
@line = @live.nextline
break if @line.nil?
@line.chomp!
break if end?(@line)
next if (@line)
@line = format(@line) unless raw
lines << @line
end
graceful_error ExpectedEnd() unless end?(@line) optional_blank_line return lines unless block_given?
lines.each {|line| yield line } end
|
#body_text(raw = false) ⇒ Object
168
169
170
|
# File 'lib/livetext/userapi.rb', line 168
def body_text(raw=false)
raw_body.join("\n")
end
|
#body_with_raw ⇒ Object
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/livetext/userapi.rb', line 149
def body_with_raw
processed_lines = []
raw_lines = []
end_found = false
loop do
@line = @live.nextline
break if @line.nil?
@line.chomp!
break if end?(@line)
next if (@line)
raw_lines << @line
@line = format(@line)
processed_lines << @line
end
graceful_error ExpectedEnd() unless end?(@line) optional_blank_line [processed_lines, raw_lines]
end
|
#check_existence(file, msg) ⇒ Object
73
74
75
|
# File 'lib/livetext/userapi.rb', line 73
def check_existence(file, msg)
STDERR.puts msg unless File.exist?(file)
end
|
#close_paragraph ⇒ Object
205
206
207
208
209
210
|
# File 'lib/livetext/userapi.rb', line 205
def close_paragraph
return if @live.nopara
return if @live.body.empty?
return if @live.body.end_with?("</p>")
out "</p>"
end
|
103
104
105
|
# File 'lib/livetext/userapi.rb', line 103
def (str)
str.index(DotSpace) == 0
end
|
#debug(*args) ⇒ Object
246
247
248
|
# File 'lib/livetext/userapi.rb', line 246
def debug(*args)
TTY.puts *args if @live.debug
end
|
#debug=(val) ⇒ Object
242
243
244
|
# File 'lib/livetext/userapi.rb', line 242
def debug=(val)
@live.debug = val
end
|
42
43
44
|
# File 'lib/livetext/userapi.rb', line 42
def dot
@live
end
|
#dump(file = nil) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/livetext/userapi.rb', line 30
def dump(file = nil) file ||= ::STDOUT
file.puts @live.body
rescue => err
TTY.puts "#dump had an error: #{err.inspect}"
end
|
#end?(str) ⇒ Boolean
112
113
114
115
|
# File 'lib/livetext/userapi.rb', line 112
def end?(str)
return true if str == ".end" || str =~ / *\$\.end/
return false
end
|
#err(*args) ⇒ Object
228
229
230
|
# File 'lib/livetext/userapi.rb', line 228
def err(*args)
STDERR.puts *args
end
|
#expand_functions(str) ⇒ Object
57
58
59
|
# File 'lib/livetext/userapi.rb', line 57
def expand_functions(str)
@expander.expand_function_calls(str)
end
|
#expand_variables(str) ⇒ Object
53
54
55
|
# File 'lib/livetext/userapi.rb', line 53
def expand_variables(str)
@expander.expand_variables(str)
end
|
184
185
186
187
|
# File 'lib/livetext/userapi.rb', line 184
def format(line)
line2 = @expander.format(line)
line2
end
|
250
251
252
|
# File 'lib/livetext/userapi.rb', line 250
def funcs
@funcs
end
|
#handle_escapes(str, set) ⇒ Object
176
177
178
179
180
181
182
|
# File 'lib/livetext/userapi.rb', line 176
def handle_escapes(str, set)
str = str.dup
set.each_char do |ch|
str.gsub!("\\#{ch}", ch)
end
str
end
|
38
39
40
|
# File 'lib/livetext/userapi.rb', line 38
def html
@html
end
|
#include_file(file) ⇒ Object
46
47
48
49
50
51
|
# File 'lib/livetext/userapi.rb', line 46
def include_file(file)
api.data = file
api.args = [file]
dot_include
end
|
#optional_blank_line ⇒ Object
96
97
98
99
100
101
|
# File 'lib/livetext/userapi.rb', line 96
def optional_blank_line
peek = @live.peek_nextline return if peek.nil?
@line = @live.nextline if peek =~ /^ *$/
return true end
|
#out(str = "", file = nil) ⇒ Object
212
213
214
215
216
217
218
|
# File 'lib/livetext/userapi.rb', line 212
def out(str = "", file = nil)
return if str.nil?
return file.puts str unless file.nil?
str.gsub!("\b ", "") @live.body << str
@live.body << "\n" unless str.end_with?("\n")
end
|
#out!(str = "") ⇒ Object
220
221
222
|
# File 'lib/livetext/userapi.rb', line 220
def out!(str = "")
@live.body << str end
|
#passthru(line) ⇒ Object
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
# File 'lib/livetext/userapi.rb', line 189
def passthru(line)
return if @live.nopass
if line == "\n"
unless @live.nopara
out "</p>\n\n<p>"
end
else
if @live.body.empty? && !@live.nopara
out "<p>"
end
text = @expander.format(line.chomp)
out text
end
end
|
#print(*args) ⇒ Object
237
238
239
240
|
# File 'lib/livetext/userapi.rb', line 237
def print(*args)
@live.api.out! *args
end
|
#puts(*args) ⇒ Object
232
233
234
235
|
# File 'lib/livetext/userapi.rb', line 232
def puts(*args)
@live.api.out *args
end
|
#raw_body(tag = "__EOF__") ⇒ Object
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/livetext/userapi.rb', line 117
def raw_body(tag = "__EOF__")
lines = []
@live.save_location = @live.sources.last
loop do
@line = @live.nextline
break if @line.nil?
break if @line.chomp.strip == tag
lines << @line
end
optional_blank_line
return lines unless block_given?
lines.each {|line| yield line }
end
|
#raw_body! ⇒ Object
172
173
174
|
# File 'lib/livetext/userapi.rb', line 172
def raw_body!
raw_body(Livetext::Sigil).join("\n")
end
|
#setvar(var, val) ⇒ Object
61
62
63
|
# File 'lib/livetext/userapi.rb', line 61
def setvar(var, val) @live.vars.set(var, val)
end
|
#setvars(pairs) ⇒ Object
65
66
67
68
69
70
71
|
# File 'lib/livetext/userapi.rb', line 65
def setvars(pairs)
pairs = pairs.to_a pairs.each do |var, value|
@live.vars.set(var, value)
end
end
|
#trailing?(char) ⇒ Boolean
107
108
109
110
|
# File 'lib/livetext/userapi.rb', line 107
def trailing?(char)
return true if ["\n", " ", nil].include?(char)
return false
end
|
#tty(*args) ⇒ Object
224
225
226
|
# File 'lib/livetext/userapi.rb', line 224
def tty(*args)
TTY.puts *args
end
|
92
93
94
|
# File 'lib/livetext/userapi.rb', line 92
def vars
@vars
end
|