livetext 0.9.09 → 0.9.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/livetext +0 -1
- data/lib/errors.rb +15 -0
- data/lib/formatline.rb +3 -5
- data/lib/functions.rb +6 -2
- data/lib/helpers.rb +25 -0
- data/lib/html.rb +32 -0
- data/lib/livetext/importable.rb +2 -0
- data/lib/livetext.rb +60 -48
- data/lib/parser/general.rb +38 -0
- data/lib/parser/import.rb +17 -0
- data/lib/parser/mixin.rb +40 -0
- data/lib/parser/set.rb +136 -0
- data/lib/parser/string.rb +55 -0
- data/lib/parser.rb +5 -0
- data/lib/processor.rb +22 -23
- data/lib/standard.rb +145 -298
- data/lib/userapi.rb +2 -5
- data/livetext.gemspec +1 -2
- data/test/all.rb +4 -0
- data/test/formatting-tests.rb +35 -0
- data/test/formatting.rb +2 -9
- data/test/snapshots/OMIT.txt +10 -0
- data/test/{data → snapshots}/basic_formatting/expected-error.txt +0 -0
- data/test/{data → snapshots}/basic_formatting/expected-output.txt +0 -0
- data/test/{data → snapshots}/basic_formatting/source.lt3 +0 -0
- data/test/{data → snapshots}/block_comment/expected-error.txt +0 -0
- data/test/{data → snapshots}/block_comment/expected-output.txt +0 -0
- data/test/{data → snapshots}/block_comment/source.lt3 +0 -0
- data/test/{data → snapshots}/comments_ignored_1/expected-error.txt +0 -0
- data/test/{data → snapshots}/comments_ignored_1/expected-output.txt +0 -0
- data/test/{data → snapshots}/comments_ignored_1/source.lt3 +0 -0
- data/test/{data → snapshots}/copy_is_raw/expected-error.txt +0 -0
- data/test/{data → snapshots}/copy_is_raw/expected-output.txt +0 -0
- data/test/{data → snapshots}/copy_is_raw/rawtext.inc +0 -0
- data/test/{data → snapshots}/copy_is_raw/source.lt3 +0 -0
- data/test/{data → snapshots}/crap +0 -0
- data/test/{data → snapshots}/def_method/expected-error.txt +0 -0
- data/test/{data → snapshots}/def_method/expected-output.txt +0 -0
- data/test/{data → snapshots}/def_method/source.lt3 +0 -0
- data/test/{data → snapshots}/error_inc_line_num/expected-output.txt +6 -0
- data/test/{data → snapshots}/error_inc_line_num/file2.lt3 +0 -0
- data/test/snapshots/error_inc_line_num/match-error.txt +1 -0
- data/test/{data → snapshots}/error_inc_line_num/source.lt3 +0 -0
- data/test/{data → snapshots}/error_invalid_name/expected-output.txt +0 -0
- data/test/snapshots/error_invalid_name/match-error.txt +1 -0
- data/test/{data → snapshots}/error_invalid_name/source.lt3 +0 -0
- data/test/{data → snapshots}/error_line_num/expected-output.txt +0 -0
- data/test/snapshots/error_line_num/match-error.txt +1 -0
- data/test/{data → snapshots}/error_line_num/source.lt3 +0 -0
- data/test/{data → snapshots}/error_mismatched_end/expected-output.txt +0 -0
- data/test/snapshots/error_mismatched_end/match-error.txt +1 -0
- data/test/{data → snapshots}/error_mismatched_end/source.lt3 +0 -0
- data/test/{data → snapshots}/error_missing_end/expected-output.txt +1 -0
- data/test/snapshots/error_missing_end/match-error.txt +1 -0
- data/test/{data → snapshots}/error_missing_end/source.lt3 +0 -0
- data/test/{data/error_no_such_mixin → snapshots/error_name_not_permitted}/expected-output.txt +0 -0
- data/test/snapshots/error_name_not_permitted/match-error.txt +1 -0
- data/test/{data → snapshots}/error_name_not_permitted/source.lt3 +0 -0
- data/test/{data → snapshots}/error_no_such_copy/expected-output.txt +0 -1
- data/test/snapshots/error_no_such_copy/match-error.txt +1 -0
- data/test/{data → snapshots}/error_no_such_copy/source.lt3 +1 -0
- data/test/{data → snapshots}/error_no_such_inc/expected-output.txt +0 -0
- data/test/snapshots/error_no_such_inc/match-error.txt +1 -0
- data/test/{data → snapshots}/error_no_such_inc/source.lt3 +0 -0
- data/test/snapshots/error_no_such_mixin/expected-output.txt +5 -0
- data/test/snapshots/error_no_such_mixin/match-error.txt +1 -0
- data/test/{data → snapshots}/error_no_such_mixin/source.lt3 +0 -0
- data/test/{data → snapshots}/example_alpha/expected-error.txt +0 -0
- data/test/{data → snapshots}/example_alpha/expected-output.txt +0 -0
- data/test/{data → snapshots}/example_alpha/source.lt3 +0 -0
- data/test/{data → snapshots}/example_alpha2/expected-error.txt +0 -0
- data/test/{data → snapshots}/example_alpha2/expected-output.txt +0 -0
- data/test/{data → snapshots}/example_alpha2/source.lt3 +0 -0
- data/test/{data → snapshots}/fixit +0 -0
- data/test/{data/lines.txt → snapshots/formatting-tests.txt} +4 -0
- data/test/{data → snapshots}/functions/expected-error.txt +0 -0
- data/test/{data → snapshots}/functions/expected-output.txt +0 -0
- data/test/{data → snapshots}/functions/source.lt3 +0 -0
- data/test/{data → snapshots}/hello_world/expected-error.txt +0 -0
- data/test/{data → snapshots}/hello_world/expected-output.txt +0 -0
- data/test/{data → snapshots}/hello_world/source.lt3 +0 -0
- data/test/{data → snapshots}/more_complex_vars/expected-error.txt +0 -0
- data/test/{data → snapshots}/more_complex_vars/expected-output.txt +0 -0
- data/test/{data → snapshots}/more_complex_vars/source.lt3 +0 -0
- data/test/{data/raw_lines → snapshots/predef_vars}/expected-error.txt +0 -0
- data/test/snapshots/predef_vars/match-output.txt +6 -0
- data/test/snapshots/predef_vars/source.lt3 +6 -0
- data/test/{data/raw_text_block → snapshots/raw_lines}/expected-error.txt +0 -0
- data/test/{data → snapshots}/raw_lines/expected-output.txt +0 -0
- data/test/{data → snapshots}/raw_lines/source.lt3 +0 -0
- data/test/{data/simple_copy → snapshots/raw_text_block}/expected-error.txt +0 -0
- data/test/{data → snapshots}/raw_text_block/expected-output.txt +0 -0
- data/test/{data → snapshots}/raw_text_block/rawtext.inc +0 -0
- data/test/{data → snapshots}/raw_text_block/source.lt3 +0 -0
- data/test/{data/simple_include → snapshots/simple_copy}/expected-error.txt +0 -0
- data/test/{data → snapshots}/simple_copy/expected-output.txt +0 -0
- data/test/{data → snapshots}/simple_copy/simplefile.inc +0 -0
- data/test/{data → snapshots}/simple_copy/source.lt3 +0 -0
- data/test/{data/simple_mixin → snapshots/simple_include}/expected-error.txt +0 -0
- data/test/{data → snapshots}/simple_include/expected-output.txt +0 -0
- data/test/{data → snapshots}/simple_include/simplefile.inc +0 -0
- data/test/{data → snapshots}/simple_include/source.lt3 +0 -0
- data/test/{data/simple_vars → snapshots/simple_mixin}/expected-error.txt +0 -0
- data/test/{data → snapshots}/simple_mixin/expected-output.txt +0 -0
- data/test/{data → snapshots}/simple_mixin/simple_mixin.rb +0 -0
- data/test/{data → snapshots}/simple_mixin/source.lt3 +0 -0
- data/test/{data/single_raw_line → snapshots/simple_vars}/expected-error.txt +0 -0
- data/test/{data → snapshots}/simple_vars/expected-output.txt +0 -0
- data/test/{data → snapshots}/simple_vars/source.lt3 +0 -0
- data/test/{data/table_with_heredocs → snapshots/single_raw_line}/expected-error.txt +0 -0
- data/test/{data → snapshots}/single_raw_line/expected-output.txt +0 -0
- data/test/{data → snapshots}/single_raw_line/source.lt3 +0 -0
- data/test/{data → snapshots}/subset.txt +0 -0
- data/test/snapshots/table_with_heredocs/expected-error.txt +0 -0
- data/test/{data → snapshots}/table_with_heredocs/expected-output.txt +0 -0
- data/test/{data → snapshots}/table_with_heredocs/source.lt3 +0 -0
- data/test/snapshots.rb +168 -0
- data/test/testlines.rb +17 -7
- data/test/unit/all.rb +3 -0
- data/test/unit/html.rb +38 -0
- data/test/unit/parser/all.rb +3 -0
- data/test/unit/parser/general.rb +59 -0
- data/test/unit/parser/importable.rb +19 -0
- data/test/unit/parser/mixin.rb +19 -0
- data/test/unit/parser/set.rb +157 -0
- data/test/unit/parser/string.rb +130 -0
- data/test/unit/parser.rb +6 -0
- data/test/unit/standard.rb +23 -0
- data/test/unit/stringparser.rb +140 -0
- metadata +122 -96
- data/test/data/error_inc_line_num/expected-err-line1match.txt +0 -1
- data/test/data/error_invalid_name/expected-err-line1match.txt +0 -1
- data/test/data/error_line_num/expected-err-line1match.txt +0 -1
- data/test/data/error_mismatched_end/expected-err-line1match.txt +0 -1
- data/test/data/error_missing_end/expected-err-line1match.txt +0 -1
- data/test/data/error_name_not_permitted/expected-error.txt +0 -1
- data/test/data/error_name_not_permitted/expected-output.txt +0 -4
- data/test/data/error_no_such_copy/expected-err-line1match.txt +0 -1
- data/test/data/error_no_such_inc/expected-err-line1match.txt +0 -1
- data/test/data/error_no_such_mixin/expected-err-line1match.txt +0 -1
- data/test/extratests.txt +0 -20
- data/test/test.rb +0 -140
data/lib/standard.rb
CHANGED
@@ -1,5 +1,21 @@
|
|
1
|
+
require 'pathname' # For _seek - remove later??
|
2
|
+
|
3
|
+
require_relative 'parser' # nested requires
|
4
|
+
require_relative 'html'
|
5
|
+
require_relative 'helpers'
|
6
|
+
|
7
|
+
make_exception(:ExpectedOnOff, "Error: expected 'on' or 'off'")
|
8
|
+
make_exception(:DisallowedName, "Error: name %1 is invalid")
|
9
|
+
make_exception(:FileNotFound, "Error: file %1 not found")
|
10
|
+
|
11
|
+
|
12
|
+
# Module Standard comprises most of the standard or "common" methods.
|
13
|
+
|
1
14
|
module Livetext::Standard
|
2
15
|
|
16
|
+
include HTMLHelper
|
17
|
+
include Helpers
|
18
|
+
|
3
19
|
SimpleFormats = # Move this?
|
4
20
|
{ b: %w[<b> </b>],
|
5
21
|
i: %w[<i> </i>],
|
@@ -8,7 +24,7 @@ module Livetext::Standard
|
|
8
24
|
|
9
25
|
attr_reader :_data
|
10
26
|
|
11
|
-
def data=(val)
|
27
|
+
def data=(val) # FIXME this is weird, let's remove it soonish
|
12
28
|
@_data = val.chomp
|
13
29
|
@_args = val.split rescue []
|
14
30
|
@_mixins = []
|
@@ -23,69 +39,75 @@ module Livetext::Standard
|
|
23
39
|
end
|
24
40
|
|
25
41
|
def backtrace
|
26
|
-
|
27
|
-
|
28
|
-
@backtrace = false if arg == "off"
|
42
|
+
@backtrace = onoff(@_args.first)
|
43
|
+
_optional_blank_line
|
29
44
|
end
|
30
45
|
|
31
46
|
def comment
|
32
47
|
_body
|
48
|
+
_optional_blank_line
|
33
49
|
end
|
34
50
|
|
35
51
|
def shell
|
36
52
|
cmd = @_data.chomp
|
37
|
-
# _errout("Running: #{cmd}")
|
38
53
|
system(cmd)
|
54
|
+
_optional_blank_line
|
39
55
|
end
|
40
56
|
|
41
57
|
def func
|
42
58
|
funcname = @_args[0]
|
43
|
-
|
44
|
-
func_def =
|
59
|
+
check_disallowed(funcname)
|
60
|
+
func_def = <<~EOS
|
45
61
|
def #{funcname}(param)
|
46
62
|
#{_body.to_a.join("\n")}
|
47
63
|
end
|
48
|
-
EOS
|
64
|
+
EOS
|
49
65
|
_optional_blank_line
|
50
|
-
|
66
|
+
|
51
67
|
Livetext::Functions.class_eval func_def
|
52
68
|
end
|
53
69
|
|
54
|
-
def h1; _out
|
55
|
-
def h2; _out
|
56
|
-
def h3; _out
|
57
|
-
def h4; _out
|
58
|
-
def h5; _out
|
59
|
-
def h6; _out
|
70
|
+
def h1; _out wrapped(@_data, :h1); end
|
71
|
+
def h2; _out wrapped(@_data, :h2); end
|
72
|
+
def h3; _out wrapped(@_data, :h3); end
|
73
|
+
def h4; _out wrapped(@_data, :h4); end
|
74
|
+
def h5; _out wrapped(@_data, :h5); end
|
75
|
+
def h6; _out wrapped(@_data, :h6); end
|
60
76
|
|
61
77
|
def list
|
62
|
-
|
63
|
-
|
64
|
-
|
78
|
+
wrap :ul do
|
79
|
+
_body {|line| _out wrapped(line, :li) }
|
80
|
+
end
|
81
|
+
_optional_blank_line
|
65
82
|
end
|
66
83
|
|
67
84
|
def list!
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
_out
|
75
|
-
else
|
76
|
-
_out "<li>#{line}</li>"
|
85
|
+
wrap(:ul) do
|
86
|
+
lines = _body.each # enumerator
|
87
|
+
loop do
|
88
|
+
line = lines.next
|
89
|
+
line = _format(line)
|
90
|
+
str = line[0] == " " ? line : wrapped(line, :li)
|
91
|
+
_out str
|
77
92
|
end
|
78
93
|
end
|
79
|
-
|
94
|
+
_optional_blank_line
|
80
95
|
end
|
81
96
|
|
82
97
|
def shell!
|
83
98
|
cmd = @_data.chomp
|
84
99
|
system(cmd)
|
100
|
+
_optional_blank_line
|
85
101
|
end
|
86
102
|
|
87
103
|
def errout
|
104
|
+
STDERR.puts @_data.chomp
|
105
|
+
_optional_blank_line
|
106
|
+
end
|
107
|
+
|
108
|
+
def ttyout
|
88
109
|
TTY.puts @_data.chomp
|
110
|
+
_optional_blank_line
|
89
111
|
end
|
90
112
|
|
91
113
|
def say
|
@@ -96,135 +118,44 @@ EOS
|
|
96
118
|
|
97
119
|
def banner
|
98
120
|
str = _format(@_data.chomp)
|
99
|
-
|
100
|
-
|
101
|
-
puts str
|
102
|
-
puts "-"*n
|
121
|
+
num = str.length - 1
|
122
|
+
decor = "-"*num + "\n"
|
123
|
+
puts decor + str + "\n" + decor
|
103
124
|
end
|
104
125
|
|
105
126
|
def quit
|
106
127
|
puts @body
|
107
128
|
@body = ""
|
108
129
|
@output.close
|
109
|
-
# exit!
|
110
130
|
end
|
111
131
|
|
112
|
-
|
113
132
|
def cleanup
|
114
|
-
@_args.each do |item|
|
115
|
-
|
116
|
-
|
117
|
-
else
|
118
|
-
::FileUtils.rm(item)
|
119
|
-
end
|
133
|
+
@_args.each do |item|
|
134
|
+
cmd = ::File.directory?(item) ? "rm -f #{item}/*" : "rm #{item}"
|
135
|
+
system(cmd)
|
120
136
|
end
|
121
137
|
end
|
122
138
|
|
123
139
|
def _def
|
124
140
|
name = @_args[0]
|
125
141
|
str = "def #{name}\n"
|
126
|
-
|
127
|
-
|
128
|
-
str
|
142
|
+
check_disallowed(name)
|
143
|
+
# Difficult to avoid eval here
|
144
|
+
str << _body(true).join("\n")
|
145
|
+
str << "\nend\n"
|
129
146
|
eval str
|
130
|
-
|
131
|
-
|
147
|
+
# rescue => err
|
148
|
+
# _error!(err)
|
132
149
|
end
|
133
150
|
|
134
151
|
def set
|
135
|
-
# FIXME bug -- .set var="RIP, Hope Gallery"
|
136
|
-
assigns = @_data.chomp.split(/, */)
|
137
|
-
# Do a better way?
|
138
|
-
# FIXME *Must* allow for vars/functions
|
139
|
-
assigns.each do |a|
|
140
|
-
var, val = a.split("=")
|
141
|
-
var.strip!
|
142
|
-
val.strip!
|
143
|
-
val = val[1..-2] if val[0] == ?" && val[-1] == ?"
|
144
|
-
val = val[1..-2] if val[0] == ?' && val[-1] == ?'
|
145
|
-
val = FormatLine.var_func_parse(val)
|
146
|
-
@parent._setvar(var, val)
|
147
|
-
end
|
148
|
-
_optional_blank_line
|
149
|
-
end
|
150
|
-
|
151
|
-
def _assign_get_var(c, e)
|
152
|
-
name = c
|
153
|
-
loop do
|
154
|
-
c = e.peek
|
155
|
-
case c
|
156
|
-
when /[a-zA-Z_\.0-9]/
|
157
|
-
name << e.next
|
158
|
-
next
|
159
|
-
when / =/
|
160
|
-
return name
|
161
|
-
else
|
162
|
-
raise "Error: did not expect #{c.inspect} in variable name"
|
163
|
-
end
|
164
|
-
end
|
165
|
-
raise "Error: loop ended parsing variable name"
|
166
|
-
end
|
167
|
-
|
168
|
-
def _assign_skip_equal(e)
|
169
|
-
loop { break if e.peek != " "; e.next }
|
170
|
-
if e.peek == "="
|
171
|
-
e.next # skip spaces too
|
172
|
-
loop { break if e.peek != " "; e.next }
|
173
|
-
else
|
174
|
-
raise "Error: expect equal sign"
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
def _quoted_value(quote, e)
|
179
|
-
value = ""
|
180
|
-
loop do
|
181
|
-
c = e.next
|
182
|
-
break if c == quote
|
183
|
-
value << c
|
184
|
-
end
|
185
|
-
value
|
186
|
-
end
|
187
|
-
|
188
|
-
def _unquoted_value(e)
|
189
|
-
value = ""
|
190
|
-
loop do
|
191
|
-
c = e.next
|
192
|
-
break if c == " " || c == ","
|
193
|
-
value << c
|
194
|
-
end
|
195
|
-
value
|
196
|
-
end
|
197
|
-
|
198
|
-
def _assign_get_value
|
199
|
-
c = e.peek
|
200
|
-
value = ""
|
201
|
-
case c
|
202
|
-
when ?", ?'
|
203
|
-
value = _quoted_value(c, e)
|
204
|
-
else
|
205
|
-
value = _unquoted_value(e)
|
206
|
-
end
|
207
|
-
c = e.peek
|
208
|
-
value
|
209
|
-
end
|
210
|
-
|
211
|
-
def set_NEW
|
212
152
|
line = _data.chomp
|
213
|
-
|
214
|
-
|
215
|
-
c = e.next
|
216
|
-
case c
|
217
|
-
when /a-z/i
|
218
|
-
_assign_get_var(c, e)
|
219
|
-
_assign_skip_equal
|
220
|
-
when " "
|
221
|
-
next
|
222
|
-
else
|
223
|
-
raise "set: Huh? line = #{line}"
|
224
|
-
end
|
225
|
-
end
|
153
|
+
pairs = Livetext::ParseSet.new(line).parse
|
154
|
+
set_variables(pairs)
|
226
155
|
end
|
227
156
|
|
157
|
+
# FIXME really these should be one method...
|
158
|
+
|
228
159
|
def variables! # cwd, not FileDir - weird, fix later
|
229
160
|
prefix = _args[0]
|
230
161
|
file = _args[1]
|
@@ -235,14 +166,8 @@ EOS
|
|
235
166
|
else
|
236
167
|
lines = _body
|
237
168
|
end
|
238
|
-
|
239
|
-
|
240
|
-
next if line.strip.empty?
|
241
|
-
var, val = line.split(" ", 2)
|
242
|
-
val = FormatLine.var_func_parse(val)
|
243
|
-
var = prefix + "." + var if prefix
|
244
|
-
@parent._setvar(var, val)
|
245
|
-
end
|
169
|
+
pairs = Livetext::ParseGeneral.parse_vars(prefix, lines)
|
170
|
+
set_variables(pairs)
|
246
171
|
end
|
247
172
|
|
248
173
|
def variables
|
@@ -255,90 +180,56 @@ EOS
|
|
255
180
|
else
|
256
181
|
lines = _body
|
257
182
|
end
|
258
|
-
|
259
|
-
|
260
|
-
next if line.strip.empty?
|
261
|
-
var, val = line.split(" ", 2)
|
262
|
-
val = FormatLine.var_func_parse(val)
|
263
|
-
var = prefix + "." + var if prefix
|
264
|
-
@parent._setvar(var, val)
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
def reval
|
269
|
-
eval _data.chomp
|
270
|
-
end
|
271
|
-
|
272
|
-
def heredoc! # adds <br>...
|
273
|
-
_heredoc(true)
|
183
|
+
pairs = Livetext::ParseGeneral.parse_vars(prefix, lines)
|
184
|
+
set_variables(pairs)
|
274
185
|
end
|
275
186
|
|
276
187
|
def heredoc
|
277
|
-
_heredoc
|
278
|
-
end
|
279
|
-
|
280
|
-
def _heredoc(bang=false)
|
281
188
|
var = @_args[0]
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
str = FormatLine.var_func_parse(
|
286
|
-
|
189
|
+
text = _body.join("\n")
|
190
|
+
rhs = ""
|
191
|
+
text.each_line do |line|
|
192
|
+
str = FormatLine.var_func_parse(line.chomp)
|
193
|
+
rhs << str + "<br>"
|
287
194
|
end
|
288
195
|
indent = @parent.indentation.last
|
289
196
|
indented = " " * indent
|
290
|
-
@parent._setvar(var,
|
197
|
+
@parent._setvar(var, rhs.chomp)
|
291
198
|
_optional_blank_line
|
292
199
|
end
|
293
200
|
|
294
201
|
def _seek(file)
|
295
|
-
require 'pathname' # ;)
|
296
202
|
value = nil
|
297
|
-
if File.exist?(file)
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
end
|
310
|
-
end
|
203
|
+
return file if File.exist?(file)
|
204
|
+
|
205
|
+
count = 1
|
206
|
+
loop do
|
207
|
+
front = "../" * count
|
208
|
+
count += 1
|
209
|
+
here = Pathname.new(front).expand_path.dirname.to_s
|
210
|
+
break if here == "/"
|
211
|
+
path = front + file
|
212
|
+
value = path if File.exist?(path)
|
213
|
+
break if value
|
214
|
+
end
|
311
215
|
STDERR.puts "Cannot find #{file.inspect} from #{Dir.pwd}" unless value
|
312
216
|
return value
|
313
217
|
rescue
|
314
218
|
STDERR.puts "Can't find #{file.inspect} from #{Dir.pwd}"
|
315
219
|
return nil
|
316
220
|
end
|
317
|
-
|
318
|
-
def seek
|
319
|
-
# like include, but search upward as needed
|
221
|
+
|
222
|
+
def seek # like include, but search upward as needed
|
320
223
|
file = @_args.first
|
321
224
|
file = _seek(file)
|
322
|
-
|
225
|
+
check_file_exists(file)
|
323
226
|
@parent.process_file(file)
|
324
227
|
_optional_blank_line
|
325
|
-
rescue => err
|
326
|
-
STDERR.puts ".seek error - #{err}"
|
327
|
-
STDERR.puts err.inspect
|
328
|
-
return nil
|
329
228
|
end
|
330
229
|
|
331
|
-
def
|
332
|
-
file, dest = *@_args
|
333
|
-
_check_existence(file, "No such include file #{file.inspect}")
|
334
|
-
@parent.process_file(file, dest)
|
335
|
-
_optional_blank_line
|
336
|
-
end
|
337
|
-
|
338
|
-
def _include
|
339
|
-
STDERR.puts "_include: vars View/ViewDir #{::Livetext::Vars[:View]} #{::Livetext::Vars[:ViewDir]} "
|
230
|
+
def _include # dot command
|
340
231
|
file = _format(@_args.first) # allows for variables
|
341
|
-
|
232
|
+
check_file_exists(file)
|
342
233
|
@parent.process_file(file)
|
343
234
|
_optional_blank_line
|
344
235
|
end
|
@@ -351,62 +242,37 @@ STDERR.puts "_include: vars View/ViewDir #{::Livetext::Vars[:View]} #{::Livetext
|
|
351
242
|
def inherit
|
352
243
|
file = @_args.first
|
353
244
|
upper = "../#{file}"
|
354
|
-
|
245
|
+
got_upper, got_file = File.exist?(upper), File.exist?(file)
|
246
|
+
good = got_upper || got_file
|
355
247
|
_error!("File #{file} not found (local or parent)") unless good
|
356
248
|
|
357
|
-
@parent.process_file(upper) if
|
358
|
-
@parent.process_file(file) if
|
249
|
+
@parent.process_file(upper) if got_upper
|
250
|
+
@parent.process_file(file) if got_file
|
359
251
|
_optional_blank_line
|
360
252
|
end
|
361
253
|
|
362
|
-
# def include! # FIXME huh?
|
363
|
-
# file = @_args.first
|
364
|
-
# return unless File.exist?(file)
|
365
|
-
#
|
366
|
-
# lines = @parent.process_file(file)
|
367
|
-
# #? File.delete(file)
|
368
|
-
# _optional_blank_line
|
369
|
-
# end
|
370
|
-
|
371
|
-
def _mixin(name)
|
372
|
-
@_args = [name]
|
373
|
-
mixin
|
374
|
-
end
|
375
|
-
|
376
254
|
def mixin
|
377
255
|
name = @_args.first # Expect a module name
|
378
|
-
file = "#{Plugins}/" + name.downcase + ".rb"
|
379
256
|
return if @_mixins.include?(name)
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
return
|
387
|
-
else
|
388
|
-
STDERR.puts "No such mixin '#{name}'"
|
389
|
-
puts @body
|
390
|
-
exit!
|
391
|
-
end
|
392
|
-
end
|
257
|
+
@_mixins << name
|
258
|
+
parse = Livetext::ParseMixin.new # (name) # FIXME??
|
259
|
+
file = parse.find_mixin(name)
|
260
|
+
parse.use_mixin(name, file)
|
261
|
+
_optional_blank_line
|
262
|
+
end
|
393
263
|
|
264
|
+
def import
|
265
|
+
name = @_args.first # Expect a module name
|
266
|
+
return if @_mixins.include?(name)
|
394
267
|
@_mixins << name
|
395
|
-
|
396
|
-
|
397
|
-
string = "module ::#{modname}; #{meths}\nend"
|
398
|
-
|
399
|
-
eval(string)
|
400
|
-
newmod = Object.const_get("::" + modname)
|
401
|
-
self.extend(newmod)
|
402
|
-
init = "init_#{name}"
|
403
|
-
self.send(init) if self.respond_to? init
|
268
|
+
parse = Livetext::ParseImport.new(name)
|
269
|
+
parse.use_import(name)
|
404
270
|
_optional_blank_line
|
405
271
|
end
|
406
272
|
|
407
273
|
def copy
|
408
274
|
file = @_args.first
|
409
|
-
|
275
|
+
check_file_exists(file)
|
410
276
|
_out grab_file(file)
|
411
277
|
_optional_blank_line
|
412
278
|
end
|
@@ -417,24 +283,16 @@ STDERR.puts "_include: vars View/ViewDir #{::Livetext::Vars[:View]} #{::Livetext
|
|
417
283
|
|
418
284
|
def raw
|
419
285
|
# No processing at all (terminate with __EOF__)
|
420
|
-
_raw_body {|
|
286
|
+
_raw_body {|line| _out line } # no formatting
|
421
287
|
end
|
422
288
|
|
423
289
|
def debug
|
424
|
-
|
425
|
-
self._debug = true
|
426
|
-
self._debug = false if arg == "off"
|
290
|
+
self._debug = onoff(@_args.first)
|
427
291
|
end
|
428
292
|
|
429
293
|
def passthru
|
430
|
-
# FIXME - add check for args size (helpers)
|
431
|
-
|
432
|
-
case onoff
|
433
|
-
when nil; @_nopass = false
|
434
|
-
when "on"; @_nopass = false
|
435
|
-
when "off"; @_nopass = true
|
436
|
-
else _error!("Unknown arg '#{onoff}'")
|
437
|
-
end
|
294
|
+
# FIXME - add check for args size? (helpers)
|
295
|
+
@_nopass = ! onoff(_args.first)
|
438
296
|
end
|
439
297
|
|
440
298
|
def nopass
|
@@ -442,13 +300,20 @@ STDERR.puts "_include: vars View/ViewDir #{::Livetext::Vars[:View]} #{::Livetext
|
|
442
300
|
end
|
443
301
|
|
444
302
|
def para
|
445
|
-
# FIXME - add check for args size (helpers)
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
303
|
+
# FIXME - add check for args size? (helpers)
|
304
|
+
@_nopara = ! onoff(_args.first)
|
305
|
+
end
|
306
|
+
|
307
|
+
def onoff(arg) # helper
|
308
|
+
arg ||= "on"
|
309
|
+
raise ExpectedOnOff unless String === arg
|
310
|
+
case arg.downcase
|
311
|
+
when "on"
|
312
|
+
return true
|
313
|
+
when "off"
|
314
|
+
return false
|
315
|
+
else
|
316
|
+
raise ExpectedOnOff
|
452
317
|
end
|
453
318
|
end
|
454
319
|
|
@@ -467,39 +332,23 @@ STDERR.puts "_include: vars View/ViewDir #{::Livetext::Vars[:View]} #{::Livetext
|
|
467
332
|
_out "<p/>"
|
468
333
|
end
|
469
334
|
|
470
|
-
def invoke(str)
|
471
|
-
end
|
472
|
-
|
473
335
|
def mono
|
474
|
-
|
475
|
-
|
476
|
-
|
336
|
+
wrap ":pre" do
|
337
|
+
_body(true) {|line| _out line }
|
338
|
+
end
|
477
339
|
_optional_blank_line
|
478
340
|
end
|
479
341
|
|
480
342
|
def dlist
|
481
343
|
delim = _args.first
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
_out "</dl>"
|
490
|
-
end
|
491
|
-
|
492
|
-
def old_dlist
|
493
|
-
delim = _args.first
|
494
|
-
_out "<table>"
|
495
|
-
_body do |line|
|
496
|
-
line = _format(line)
|
497
|
-
term, defn = line.split(delim)
|
498
|
-
_out "<tr>"
|
499
|
-
_out "<td width=3%><td width=10%>#{term}</td><td>#{defn}</td>"
|
500
|
-
_out "</tr>"
|
344
|
+
wrap(:dl) do
|
345
|
+
_body do |line|
|
346
|
+
line = _format(line)
|
347
|
+
term, defn = line.split(delim)
|
348
|
+
_out wrapped(term, :dt)
|
349
|
+
_out wrapped(defn, :dd)
|
350
|
+
end
|
501
351
|
end
|
502
|
-
_out "</table>"
|
503
352
|
end
|
504
353
|
|
505
354
|
def link
|
@@ -518,21 +367,19 @@ STDERR.puts "_include: vars View/ViewDir #{::Livetext::Vars[:View]} #{::Livetext
|
|
518
367
|
line = _format(line)
|
519
368
|
line.gsub!(/\n+/, "<br>")
|
520
369
|
cells = line.split(delim)
|
521
|
-
wide = cells.map {|
|
370
|
+
wide = cells.map {|cell| cell.length }
|
522
371
|
maxw = [0] * cells.size
|
523
372
|
maxw = maxw.map.with_index {|x, i| [x, wide[i]].max }
|
524
373
|
end
|
525
|
-
|
374
|
+
|
526
375
|
sum = maxw.inject(0, :+)
|
527
376
|
maxw.map! {|x| (x/sum*100).floor }
|
528
|
-
|
377
|
+
|
529
378
|
lines.each do |line|
|
530
379
|
cells = line.split(delim)
|
531
|
-
|
532
|
-
|
533
|
-
_out " <td valign=top>#{cell}</td>"
|
380
|
+
wrap :tr do
|
381
|
+
cells.each {|cell| _out " <td valign=top>#{cell}</td>" }
|
534
382
|
end
|
535
|
-
_out "</tr>"
|
536
383
|
end
|
537
384
|
_out "</table></center>"
|
538
385
|
end
|
@@ -543,10 +390,10 @@ STDERR.puts "_include: vars View/ViewDir #{::Livetext::Vars[:View]} #{::Livetext
|
|
543
390
|
end
|
544
391
|
|
545
392
|
def br
|
546
|
-
|
393
|
+
num = _args.first || "1"
|
547
394
|
out = ""
|
548
|
-
|
395
|
+
num.to_i.times { out << "<br>" }
|
549
396
|
_out out
|
550
397
|
end
|
551
398
|
|
552
|
-
end
|
399
|
+
end
|
data/lib/userapi.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# User API
|
2
2
|
|
3
|
-
|
3
|
+
require_relative 'formatline'
|
4
4
|
|
5
|
+
# UserAPI deals mostly with user-level methods.
|
5
6
|
module Livetext::UserAPI
|
6
7
|
|
7
8
|
def setvar(var, val)
|
@@ -93,10 +94,6 @@ module Livetext::UserAPI
|
|
93
94
|
else
|
94
95
|
lines
|
95
96
|
end
|
96
|
-
rescue => err
|
97
|
-
str = err.inspect + "\n"
|
98
|
-
str << err.backtrace.map {|x| " " + x }.join("\n")
|
99
|
-
_error!(str)
|
100
97
|
end
|
101
98
|
|
102
99
|
def _body_text(raw=false)
|
data/livetext.gemspec
CHANGED
data/test/all.rb
ADDED