livetext 0.9.11 → 0.9.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.lt3 +2 -2
- data/lib/cmdargs.rb +93 -0
- data/lib/errors.rb +15 -0
- data/lib/formatline.rb +59 -88
- data/lib/functions.rb +6 -2
- data/lib/handler/icanhaz.rb +35 -0
- data/lib/handler.rb +1 -0
- data/lib/helpers.rb +194 -0
- data/lib/html.rb +32 -0
- data/lib/livetext/importable.rb +2 -0
- data/lib/livetext.rb +35 -152
- data/lib/parser/file.rb +8 -0
- data/lib/parser/general.rb +38 -0
- data/lib/parser/import.rb +15 -0
- data/lib/parser/mixin.rb +38 -0
- data/lib/parser/set.rb +145 -0
- data/lib/parser/string.rb +70 -0
- data/lib/parser.rb +5 -0
- data/lib/processor.rb +23 -27
- data/lib/standard.rb +164 -346
- data/lib/userapi.rb +3 -5
- data/livetext.gemspec +1 -2
- data/plugin/bookish.rb +26 -22
- data/plugin/calibre.rb +1 -1
- data/plugin/livemagick.rb +10 -10
- data/plugin/markdown.rb +13 -11
- data/plugin/pyggish.rb +94 -84
- data/plugin/tutorial.rb +10 -5
- data/test/all.rb +3 -0
- data/test/snapshots/OMIT.txt +11 -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/snapshots/clusion.txt +70 -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 +0 -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 -2
- 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 +0 -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 -5
- data/test/snapshots/error_no_such_copy/match-error.txt +1 -0
- data/test/{data → snapshots}/error_no_such_copy/source.lt3 +0 -1
- data/test/{data → snapshots}/error_no_such_inc/expected-output.txt +0 -4
- 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 → 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/snapshots/icanhaz/expected-output.txt +5 -0
- data/test/snapshots/icanhaz/match-error.txt +1 -0
- data/test/snapshots/icanhaz/simple_import.rb +5 -0
- data/test/snapshots/icanhaz/source.lt3 +10 -0
- data/test/{data/more_complex_vars → snapshots/icanhaz2}/expected-error.txt +0 -0
- data/test/snapshots/icanhaz2/expected-output.txt +6 -0
- data/test/snapshots/icanhaz2/simple_canhaz.rb +5 -0
- data/test/snapshots/icanhaz2/source.lt3 +6 -0
- data/test/{data/predef_vars → 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/{data → snapshots}/predef_vars/source.lt3 +0 -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_import}/expected-error.txt +0 -0
- data/test/snapshots/simple_import/expected-output.txt +7 -0
- data/test/snapshots/simple_import/simple_import.rb +5 -0
- data/test/snapshots/simple_import/source.lt3 +7 -0
- data/test/{data/simple_vars → 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 -1
- data/test/{data/single_raw_line → 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/table_with_heredocs → 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/subset.txt → 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/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 +177 -0
- data/test/testlines.rb +2 -2
- data/test/unit/all.rb +4 -0
- data/test/unit/formatline.rb +650 -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 +164 -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 +137 -100
- data/test/data/error_inc_line_num/FOO +0 -21
- 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/ERR +0 -32
- 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/data/lines.txt +0 -124
- data/test/data/predef_vars/expected-output.txt +0 -6
- data/test/formatting.rb +0 -110
- 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,13 +24,14 @@ 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 = []
|
15
31
|
end
|
16
32
|
|
17
|
-
|
33
|
+
# dumb name - bold, italic, teletype, striketrough
|
34
|
+
def bits(args = nil, body = nil)
|
18
35
|
b0, b1, i0, i1, t0, t1, s0, s1 = *@_args
|
19
36
|
SimpleFormats[:b] = [b0, b1]
|
20
37
|
SimpleFormats[:i] = [i0, i1]
|
@@ -22,210 +39,122 @@ module Livetext::Standard
|
|
22
39
|
SimpleFormats[:s] = [s0, s1]
|
23
40
|
end
|
24
41
|
|
25
|
-
def backtrace
|
26
|
-
|
27
|
-
|
28
|
-
@backtrace = false if arg == "off"
|
42
|
+
def backtrace(args = nil, body = nil)
|
43
|
+
@backtrace = onoff(@_args.first)
|
44
|
+
_optional_blank_line
|
29
45
|
end
|
30
46
|
|
31
|
-
def comment
|
47
|
+
def comment(args = nil, body = nil)
|
32
48
|
_body
|
49
|
+
_optional_blank_line
|
33
50
|
end
|
34
51
|
|
35
|
-
def shell
|
52
|
+
def shell(args = nil, body = nil)
|
36
53
|
cmd = @_data.chomp
|
37
|
-
# _errout("Running: #{cmd}")
|
38
54
|
system(cmd)
|
55
|
+
_optional_blank_line
|
39
56
|
end
|
40
57
|
|
41
|
-
def func
|
58
|
+
def func(args = nil, body = nil)
|
42
59
|
funcname = @_args[0]
|
43
|
-
|
44
|
-
func_def =
|
60
|
+
check_disallowed(funcname)
|
61
|
+
func_def = <<~EOS
|
45
62
|
def #{funcname}(param)
|
46
63
|
#{_body.to_a.join("\n")}
|
47
64
|
end
|
48
|
-
EOS
|
65
|
+
EOS
|
49
66
|
_optional_blank_line
|
50
|
-
|
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(args = nil, body = nil); _out wrapped(@_data, :h1); end
|
71
|
+
def h2(args = nil, body = nil); _out wrapped(@_data, :h2); end
|
72
|
+
def h3(args = nil, body = nil); _out wrapped(@_data, :h3); end
|
73
|
+
def h4(args = nil, body = nil); _out wrapped(@_data, :h4); end
|
74
|
+
def h5(args = nil, body = nil); _out wrapped(@_data, :h5); end
|
75
|
+
def h6(args = nil, body = nil); _out wrapped(@_data, :h6); end
|
60
76
|
|
61
|
-
def list
|
62
|
-
|
63
|
-
|
64
|
-
|
77
|
+
def list(args = nil, body = nil)
|
78
|
+
wrap :ul do
|
79
|
+
_body {|line| _out wrapped(line, :li) }
|
80
|
+
end
|
81
|
+
_optional_blank_line
|
65
82
|
end
|
66
83
|
|
67
|
-
def list!
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
_out
|
75
|
-
else
|
76
|
-
_out "<li>#{line}</li>"
|
84
|
+
def list!(args = nil, body = nil)
|
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
|
-
def shell!
|
97
|
+
def shell!(args = nil, body = nil)
|
83
98
|
cmd = @_data.chomp
|
84
99
|
system(cmd)
|
100
|
+
_optional_blank_line
|
101
|
+
end
|
102
|
+
|
103
|
+
def errout(args = nil, body = nil)
|
104
|
+
STDERR.puts @_data.chomp
|
105
|
+
_optional_blank_line
|
85
106
|
end
|
86
107
|
|
87
|
-
def
|
108
|
+
def ttyout(args = nil, body = nil)
|
88
109
|
TTY.puts @_data.chomp
|
110
|
+
_optional_blank_line
|
89
111
|
end
|
90
112
|
|
91
|
-
def say
|
113
|
+
def say(args = nil, body = nil)
|
92
114
|
str = _format(@_data.chomp)
|
93
115
|
TTY.puts str
|
94
116
|
_optional_blank_line
|
95
117
|
end
|
96
118
|
|
97
|
-
def banner
|
119
|
+
def banner(args = nil, body = nil)
|
98
120
|
str = _format(@_data.chomp)
|
99
|
-
|
100
|
-
|
101
|
-
puts str
|
102
|
-
puts "-"*n
|
121
|
+
num = str.length
|
122
|
+
decor = "-"*num + "\n"
|
123
|
+
puts decor + str + "\n" + decor
|
103
124
|
end
|
104
125
|
|
105
|
-
def quit
|
126
|
+
def quit(args = nil, body = nil)
|
106
127
|
puts @body
|
107
128
|
@body = ""
|
108
129
|
@output.close
|
109
|
-
# exit!
|
110
130
|
end
|
111
131
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
system("rm -f #{item}/*")
|
117
|
-
else
|
118
|
-
::FileUtils.rm(item)
|
119
|
-
end
|
132
|
+
def cleanup(args = nil, body = nil)
|
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
|
-
def
|
139
|
+
def dot_def(args = nil, body = nil)
|
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
|
-
rescue => err
|
131
|
-
_error!(err)
|
132
|
-
end
|
133
|
-
|
134
|
-
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
147
|
end
|
150
148
|
|
151
|
-
def
|
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
|
149
|
+
def set(args = nil, body = nil)
|
212
150
|
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
|
151
|
+
pairs = Livetext::ParseSet.new(line).parse
|
152
|
+
set_variables(pairs)
|
226
153
|
end
|
227
154
|
|
228
|
-
|
155
|
+
# FIXME really these should be one method...
|
156
|
+
|
157
|
+
def variables!(args = nil, body = nil) # cwd, not FileDir - weird, fix later
|
229
158
|
prefix = _args[0]
|
230
159
|
file = _args[1]
|
231
160
|
prefix = nil if prefix == "-" # FIXME dumb hack
|
@@ -235,17 +164,11 @@ EOS
|
|
235
164
|
else
|
236
165
|
lines = _body
|
237
166
|
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
|
167
|
+
pairs = Livetext::ParseGeneral.parse_vars(prefix, lines)
|
168
|
+
set_variables(pairs)
|
246
169
|
end
|
247
170
|
|
248
|
-
def variables
|
171
|
+
def variables(args = nil, body = nil)
|
249
172
|
prefix = _args[0]
|
250
173
|
file = _args[1]
|
251
174
|
prefix = nil if prefix == "-" # FIXME dumb hack
|
@@ -255,260 +178,157 @@ EOS
|
|
255
178
|
else
|
256
179
|
lines = _body
|
257
180
|
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)
|
274
|
-
end
|
275
|
-
|
276
|
-
def heredoc
|
277
|
-
_heredoc
|
181
|
+
pairs = Livetext::ParseGeneral.parse_vars(prefix, lines)
|
182
|
+
set_variables(pairs)
|
278
183
|
end
|
279
184
|
|
280
|
-
def
|
185
|
+
def heredoc(args = nil, body = nil)
|
281
186
|
var = @_args[0]
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
str = FormatLine.var_func_parse(
|
286
|
-
|
187
|
+
text = _body.join("\n")
|
188
|
+
rhs = ""
|
189
|
+
text.each_line do |line|
|
190
|
+
str = FormatLine.var_func_parse(line.chomp)
|
191
|
+
rhs << str + "<br>"
|
287
192
|
end
|
288
193
|
indent = @parent.indentation.last
|
289
194
|
indented = " " * indent
|
290
|
-
@parent.
|
195
|
+
@parent.setvar(var, rhs.chomp)
|
291
196
|
_optional_blank_line
|
292
197
|
end
|
293
198
|
|
294
|
-
def
|
295
|
-
require 'pathname' # ;)
|
296
|
-
value = nil
|
297
|
-
if File.exist?(file)
|
298
|
-
return file
|
299
|
-
else
|
300
|
-
count = 1
|
301
|
-
loop do
|
302
|
-
front = "../" * count
|
303
|
-
count += 1
|
304
|
-
here = Pathname.new(front).expand_path.dirname.to_s
|
305
|
-
break if here == "/"
|
306
|
-
path = front + file
|
307
|
-
value = path if File.exist?(path)
|
308
|
-
break if value
|
309
|
-
end
|
310
|
-
end
|
311
|
-
STDERR.puts "Cannot find #{file.inspect} from #{Dir.pwd}" unless value
|
312
|
-
return value
|
313
|
-
rescue
|
314
|
-
STDERR.puts "Can't find #{file.inspect} from #{Dir.pwd}"
|
315
|
-
return nil
|
316
|
-
end
|
317
|
-
|
318
|
-
def seek
|
319
|
-
# like include, but search upward as needed
|
199
|
+
def seek(args = nil, body = nil) # like include, but search upward as needed
|
320
200
|
file = @_args.first
|
321
|
-
file =
|
322
|
-
|
201
|
+
file = search_upward(file)
|
202
|
+
check_file_exists(file)
|
323
203
|
@parent.process_file(file)
|
324
204
|
_optional_blank_line
|
325
|
-
rescue => err
|
326
|
-
STDERR.puts ".seek error - #{err}"
|
327
|
-
STDERR.puts err.inspect
|
328
|
-
return nil
|
329
|
-
end
|
330
|
-
|
331
|
-
def in_out # FIXME dumb name!
|
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
205
|
end
|
337
206
|
|
338
|
-
def
|
207
|
+
def dot_include(args = nil, body = nil) # dot command
|
339
208
|
file = _format(@_args.first) # allows for variables
|
340
|
-
|
209
|
+
check_file_exists(file)
|
341
210
|
@parent.process_file(file)
|
342
211
|
_optional_blank_line
|
343
212
|
end
|
344
213
|
|
345
|
-
def
|
346
|
-
@_args = [file]
|
347
|
-
_include
|
348
|
-
end
|
349
|
-
|
350
|
-
def inherit
|
214
|
+
def inherit(args = nil, body = nil)
|
351
215
|
file = @_args.first
|
352
216
|
upper = "../#{file}"
|
353
|
-
|
217
|
+
got_upper, got_file = File.exist?(upper), File.exist?(file)
|
218
|
+
good = got_upper || got_file
|
354
219
|
_error!("File #{file} not found (local or parent)") unless good
|
355
220
|
|
356
|
-
@parent.process_file(upper) if
|
357
|
-
@parent.process_file(file) if
|
221
|
+
@parent.process_file(upper) if got_upper
|
222
|
+
@parent.process_file(file) if got_file
|
358
223
|
_optional_blank_line
|
359
224
|
end
|
360
225
|
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
#
|
368
|
-
|
369
|
-
|
370
|
-
def _mixin(name)
|
371
|
-
@_args = [name]
|
372
|
-
mixin
|
226
|
+
def mixin(args = nil, body = nil)
|
227
|
+
name = @_args.first # Expect a module name
|
228
|
+
return if @_mixins.include?(name)
|
229
|
+
@_mixins << name
|
230
|
+
mod = Livetext::ParseMixin.get_module(name) # FIXME??
|
231
|
+
self.extend(mod)
|
232
|
+
init = "init_#{name}"
|
233
|
+
self.send(init) if self.respond_to? init
|
234
|
+
_optional_blank_line
|
373
235
|
end
|
374
236
|
|
375
|
-
def
|
237
|
+
def icanhaz(args = nil, body = nil)
|
376
238
|
name = @_args.first # Expect a module name
|
377
|
-
file = "#{Plugins}/" + name.downcase + ".rb"
|
378
239
|
return if @_mixins.include?(name)
|
379
|
-
file = "./#{name}.rb" unless File.exist?(file)
|
380
|
-
if File.exist?(file)
|
381
|
-
# Just keep going...
|
382
|
-
else
|
383
|
-
if File.dirname(File.expand_path(".")) != "/"
|
384
|
-
Dir.chdir("..") { mixin }
|
385
|
-
return
|
386
|
-
else
|
387
|
-
raise "No such mixin '#{name}'"
|
388
|
-
# STDERR.puts "No such mixin '#{name}'"
|
389
|
-
# puts @body
|
390
|
-
# exit!
|
391
|
-
end
|
392
|
-
end
|
393
|
-
|
394
240
|
@_mixins << name
|
395
|
-
|
396
|
-
|
397
|
-
string = "module ::#{modname}; #{meths}\nend"
|
398
|
-
|
399
|
-
eval(string)
|
400
|
-
newmod = Object.const_get("::" + modname)
|
401
|
-
self.extend(newmod)
|
241
|
+
mod = Livetext::Handler::ICanHaz.get_module(name) # FIXME??
|
242
|
+
self.extend(mod)
|
402
243
|
init = "init_#{name}"
|
403
244
|
self.send(init) if self.respond_to? init
|
404
245
|
_optional_blank_line
|
405
246
|
end
|
406
247
|
|
407
|
-
def
|
248
|
+
def import(args = nil, body = nil)
|
249
|
+
name = @_args.first # Expect a module name
|
250
|
+
return if @_mixins.include?(name)
|
251
|
+
@_mixins << name
|
252
|
+
mod = Livetext::ParseImport.get_module(name)
|
253
|
+
parse.use_import(name)
|
254
|
+
_optional_blank_line
|
255
|
+
end
|
256
|
+
|
257
|
+
def copy(args = nil, body = nil)
|
408
258
|
file = @_args.first
|
409
|
-
|
259
|
+
check_file_exists(file)
|
410
260
|
_out grab_file(file)
|
411
261
|
_optional_blank_line
|
412
262
|
end
|
413
263
|
|
414
|
-
def r
|
264
|
+
def r(args = nil, body = nil)
|
415
265
|
_out @_data.chomp # No processing at all
|
416
266
|
end
|
417
267
|
|
418
|
-
def raw
|
268
|
+
def raw(args = nil, body = nil)
|
419
269
|
# No processing at all (terminate with __EOF__)
|
420
|
-
_raw_body {|
|
270
|
+
_raw_body {|line| _out line } # no formatting
|
421
271
|
end
|
422
272
|
|
423
|
-
def debug
|
424
|
-
|
425
|
-
self._debug = true
|
426
|
-
self._debug = false if arg == "off"
|
273
|
+
def debug(args = nil, body = nil)
|
274
|
+
self._debug = onoff(@_args.first)
|
427
275
|
end
|
428
276
|
|
429
|
-
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
|
277
|
+
def passthru(args = nil, body = nil)
|
278
|
+
# FIXME - add check for args size? (helpers)
|
279
|
+
@_nopass = ! onoff(_args.first)
|
438
280
|
end
|
439
281
|
|
440
|
-
def nopass
|
282
|
+
def nopass(args = nil, body = nil)
|
441
283
|
@_nopass = true
|
442
284
|
end
|
443
285
|
|
444
|
-
def para
|
445
|
-
# FIXME - add check for args size (helpers)
|
446
|
-
|
447
|
-
case onoff
|
448
|
-
when nil; @_nopara = false
|
449
|
-
when "on"; @_nopara = false
|
450
|
-
when "off"; @_nopara = true
|
451
|
-
else _error!("Unknown arg '#{onoff}'")
|
452
|
-
end
|
286
|
+
def para(args = nil, body = nil)
|
287
|
+
# FIXME - add check for args size? (helpers)
|
288
|
+
@_nopara = ! onoff(_args.first)
|
453
289
|
end
|
454
290
|
|
455
|
-
def nopara
|
291
|
+
def nopara(args = nil, body = nil)
|
456
292
|
@_nopara = true
|
457
293
|
end
|
458
294
|
|
459
|
-
def heading
|
295
|
+
def heading(args = nil, body = nil)
|
460
296
|
_print "<center><font size=+1><b>"
|
461
297
|
_print @_data.chomp
|
462
298
|
_print "</b></font></center>"
|
463
299
|
end
|
464
300
|
|
465
|
-
def newpage
|
301
|
+
def newpage(args = nil, body = nil)
|
466
302
|
_out '<p style="page-break-after:always;"></p>'
|
467
303
|
_out "<p/>"
|
468
304
|
end
|
469
305
|
|
470
|
-
def
|
471
|
-
|
472
|
-
|
473
|
-
def mono
|
474
|
-
_out "<pre>"
|
475
|
-
_body(true) {|line| _out line }
|
476
|
-
_out "</pre>"
|
477
|
-
_optional_blank_line
|
478
|
-
end
|
479
|
-
|
480
|
-
def dlist
|
481
|
-
delim = _args.first
|
482
|
-
_out "<dl>"
|
483
|
-
_body do |line|
|
484
|
-
line = _format(line)
|
485
|
-
term, defn = line.split(delim)
|
486
|
-
_out "<dt>#{term}</dt>"
|
487
|
-
_out "<dd>#{defn}</dd>"
|
306
|
+
def mono(args = nil, body = nil)
|
307
|
+
wrap ":pre" do
|
308
|
+
_body(true) {|line| _out line }
|
488
309
|
end
|
489
|
-
|
310
|
+
_optional_blank_line
|
490
311
|
end
|
491
312
|
|
492
|
-
def
|
313
|
+
def dlist(args = nil, body = nil)
|
493
314
|
delim = _args.first
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
315
|
+
wrap(:dl) do
|
316
|
+
_body do |line|
|
317
|
+
line = _format(line)
|
318
|
+
term, defn = line.split(delim)
|
319
|
+
_out wrapped(term, :dt)
|
320
|
+
_out wrapped(defn, :dd)
|
321
|
+
end
|
501
322
|
end
|
502
|
-
_out "</table>"
|
503
323
|
end
|
504
324
|
|
505
|
-
def link
|
325
|
+
def link(args = nil, body = nil)
|
506
326
|
url = _args.first
|
507
327
|
text = _args[2..-1].join(" ")
|
508
328
|
_out "<a style='text-decoration: none' href='#{url}'>#{text}</a>"
|
509
329
|
end
|
510
330
|
|
511
|
-
def xtable # Borrowed from bookish - FIXME
|
331
|
+
def xtable(args = nil, body = nil) # Borrowed from bookish - FIXME
|
512
332
|
title = @_data.chomp
|
513
333
|
delim = " :: "
|
514
334
|
_out "<br><center><table width=90% cellpadding=5>"
|
@@ -518,35 +338,33 @@ EOS
|
|
518
338
|
line = _format(line)
|
519
339
|
line.gsub!(/\n+/, "<br>")
|
520
340
|
cells = line.split(delim)
|
521
|
-
wide = cells.map {|
|
341
|
+
wide = cells.map {|cell| cell.length }
|
522
342
|
maxw = [0] * cells.size
|
523
343
|
maxw = maxw.map.with_index {|x, i| [x, wide[i]].max }
|
524
344
|
end
|
525
|
-
|
345
|
+
|
526
346
|
sum = maxw.inject(0, :+)
|
527
347
|
maxw.map! {|x| (x/sum*100).floor }
|
528
|
-
|
348
|
+
|
529
349
|
lines.each do |line|
|
530
350
|
cells = line.split(delim)
|
531
|
-
|
532
|
-
|
533
|
-
_out " <td valign=top>#{cell}</td>"
|
351
|
+
wrap :tr do
|
352
|
+
cells.each {|cell| _out " <td valign=top>#{cell}</td>" }
|
534
353
|
end
|
535
|
-
_out "</tr>"
|
536
354
|
end
|
537
355
|
_out "</table></center>"
|
538
356
|
end
|
539
357
|
|
540
|
-
def image
|
358
|
+
def image(args = nil, body = nil)
|
541
359
|
name = @_args[0]
|
542
360
|
_out "<img src='#{name}'></img>"
|
543
361
|
end
|
544
362
|
|
545
|
-
def br
|
546
|
-
|
363
|
+
def br(args = nil, body = nil)
|
364
|
+
num = _args.first || "1"
|
547
365
|
out = ""
|
548
|
-
|
366
|
+
num.to_i.times { out << "<br>" }
|
549
367
|
_out out
|
550
368
|
end
|
551
369
|
|
552
|
-
end
|
370
|
+
end
|