livetext 0.9.13 → 0.9.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/README.lt3 +2 -2
  3. data/imports/bookish.rb +288 -0
  4. data/imports/calibre.rb +28 -0
  5. data/imports/livemagick.rb +133 -0
  6. data/imports/markdown.rb +44 -0
  7. data/imports/markdown_importable.rb +46 -0
  8. data/imports/pyggish.rb +204 -0
  9. data/imports/tutorial.rb +95 -0
  10. data/lib/cmdargs.rb +93 -0
  11. data/lib/errors.rb +4 -2
  12. data/lib/formatline.rb +56 -83
  13. data/lib/functions.rb +1 -1
  14. data/lib/handler/icanhaz.rb +35 -0
  15. data/lib/handler.rb +1 -0
  16. data/lib/helpers.rb +177 -4
  17. data/lib/livetext.rb +20 -139
  18. data/lib/parser/file.rb +8 -0
  19. data/lib/parser/general.rb +1 -1
  20. data/lib/parser/import.rb +1 -3
  21. data/lib/parser/mixin.rb +22 -30
  22. data/lib/parser/set.rb +35 -26
  23. data/lib/parser/string.rb +19 -4
  24. data/lib/processor.rb +2 -12
  25. data/lib/standard.rb +73 -107
  26. data/lib/userapi.rb +1 -4
  27. data/livetext.gemspec +2 -1
  28. data/plugin/bookish.rb +26 -22
  29. data/plugin/calibre.rb +1 -1
  30. data/plugin/livemagick.rb +10 -10
  31. data/plugin/markdown.rb +13 -11
  32. data/plugin/pyggish.rb +94 -84
  33. data/plugin/tutorial.rb +10 -5
  34. data/test/snapshots/OMIT.txt +11 -0
  35. data/test/snapshots/clusion.txt +84 -0
  36. data/test/snapshots/error_inc_line_num/match-error.txt +1 -0
  37. data/test/snapshots/error_invalid_name/match-error.txt +1 -0
  38. data/test/snapshots/error_line_num/match-error.txt +1 -0
  39. data/test/snapshots/error_mismatched_end/expected-output.txt +0 -2
  40. data/test/snapshots/error_mismatched_end/match-error.txt +1 -0
  41. data/test/snapshots/error_missing_end/match-error.txt +1 -0
  42. data/test/snapshots/error_no_such_copy/match-error.txt +1 -0
  43. data/test/snapshots/error_no_such_copy/source.lt3 +0 -1
  44. data/test/snapshots/error_no_such_inc/match-error.txt +1 -0
  45. data/test/snapshots/error_no_such_mixin/match-error.txt +1 -0
  46. data/test/snapshots/icanhaz/expected-output.txt +5 -0
  47. data/test/snapshots/icanhaz/match-error.txt +1 -0
  48. data/test/snapshots/icanhaz/simple_import.rb +5 -0
  49. data/test/snapshots/{error_no_such_mixin/actual-output.txt → icanhaz/source.lt3} +3 -4
  50. data/test/snapshots/{error_invalid_name/actual-output.txt → icanhaz2/expected-error.txt} +0 -0
  51. data/test/snapshots/icanhaz2/expected-output.txt +6 -0
  52. data/test/snapshots/icanhaz2/simple_canhaz.rb +5 -0
  53. data/test/snapshots/icanhaz2/source.lt3 +6 -0
  54. data/test/snapshots/predef_vars/match-output.txt +6 -0
  55. data/test/snapshots/{error_no_such_copy/actual-output.txt → simple_import/expected-error.txt} +0 -0
  56. data/test/snapshots/simple_import/expected-output.txt +7 -0
  57. data/test/snapshots/simple_import/simple_import.rb +5 -0
  58. data/test/snapshots/simple_import/source.lt3 +7 -0
  59. data/test/snapshots/simple_include/source.lt3 +0 -1
  60. data/test/snapshots.rb +103 -107
  61. data/test/unit/all.rb +1 -0
  62. data/test/unit/formatline.rb +650 -0
  63. data/test/unit/parser/general.rb +21 -21
  64. data/test/unit/parser/importable.rb +1 -1
  65. data/test/unit/parser/mixin.rb +2 -2
  66. data/test/unit/parser/set.rb +19 -12
  67. data/test/unit/parser/string.rb +14 -14
  68. data/test/unit/parser.rb +2 -0
  69. metadata +37 -46
  70. data/test/formatting.rb +0 -103
  71. data/test/snapshots/error_inc_line_num/actual-error.txt +0 -1
  72. data/test/snapshots/error_inc_line_num/actual-output.txt +0 -13
  73. data/test/snapshots/error_inc_line_num/expected-err-line1match.txt +0 -1
  74. data/test/snapshots/error_inc_line_num/out-sdiff.txt +0 -14
  75. data/test/snapshots/error_invalid_name/actual-error.txt +0 -10
  76. data/test/snapshots/error_invalid_name/expected-err-line1match.txt +0 -1
  77. data/test/snapshots/error_invalid_name/out-sdiff.txt +0 -6
  78. data/test/snapshots/error_line_num/actual-error.txt +0 -1
  79. data/test/snapshots/error_line_num/actual-output.txt +0 -5
  80. data/test/snapshots/error_line_num/expected-err-line1match.txt +0 -1
  81. data/test/snapshots/error_line_num/out-sdiff.txt +0 -6
  82. data/test/snapshots/error_mismatched_end/actual-error.txt +0 -1
  83. data/test/snapshots/error_mismatched_end/actual-output.txt +0 -8
  84. data/test/snapshots/error_mismatched_end/expected-err-line1match.txt +0 -1
  85. data/test/snapshots/error_mismatched_end/out-sdiff.txt +0 -9
  86. data/test/snapshots/error_missing_end/actual-error.txt +0 -1
  87. data/test/snapshots/error_missing_end/actual-output.txt +0 -5
  88. data/test/snapshots/error_missing_end/expected-err-line1match.txt +0 -1
  89. data/test/snapshots/error_missing_end/out-sdiff.txt +0 -6
  90. data/test/snapshots/error_name_not_permitted/OLD-exp-out +0 -4
  91. data/test/snapshots/error_no_such_copy/actual-error.txt +0 -10
  92. data/test/snapshots/error_no_such_copy/expected-err-line1match.txt +0 -1
  93. data/test/snapshots/error_no_such_copy/out-sdiff.txt +0 -5
  94. data/test/snapshots/error_no_such_inc/actual-error.txt +0 -10
  95. data/test/snapshots/error_no_such_inc/actual-output.txt +0 -0
  96. data/test/snapshots/error_no_such_inc/expected-err-line1match.txt +0 -1
  97. data/test/snapshots/error_no_such_inc/out-sdiff.txt +0 -6
  98. data/test/snapshots/error_no_such_mixin/actual-error.txt +0 -1
  99. data/test/snapshots/error_no_such_mixin/expected-err-line1match.txt +0 -1
  100. data/test/snapshots/error_no_such_mixin/out-sdiff.txt +0 -12
  101. data/test/snapshots/lines.txt +0 -124
  102. data/test/snapshots/predef_vars/actual-error.txt +0 -0
  103. data/test/snapshots/predef_vars/actual-output.txt +0 -6
  104. data/test/snapshots/predef_vars/expected-output.txt +0 -6
  105. data/test/snapshots/predef_vars/out-sdiff.txt +0 -7
  106. data/test/snapshots/simple_mixin/actual-error.txt +0 -2
  107. data/test/snapshots/simple_mixin/actual-output.txt +0 -4
  108. data/test/snapshots/simple_mixin/out-sdiff.txt +0 -6
  109. data/test/unit/parse_misc.rb +0 -60
  110. data/test/unit/parse_set.rb +0 -157
data/lib/parser/string.rb CHANGED
@@ -5,14 +5,13 @@ class StringParser
5
5
  def initialize(line)
6
6
  raise NilValue if line.nil?
7
7
  raise ExpectedString unless String === line
8
- # raise NullString if line.empty?
9
8
  @line = line
10
9
  @len = @line.length
11
10
  @eos = @len == 0 ? true : false
12
11
  @i = 0
13
12
  end
14
13
 
15
- def next
14
+ def grab
16
15
  return nil if @eos
17
16
  char = @line[@i]
18
17
  @i += 1
@@ -20,6 +19,19 @@ class StringParser
20
19
  char
21
20
  end
22
21
 
22
+ def ungrab
23
+ @i -= 1 # FIXME what about eos...?
24
+ end
25
+
26
+ def next!
27
+ @line[@i + 1]
28
+ end
29
+
30
+ def prev
31
+ return nil if @i <= 0
32
+ @line[@i-1]
33
+ end
34
+
23
35
  def last?
24
36
  @i > @len - 1
25
37
  end
@@ -35,11 +47,14 @@ class StringParser
35
47
  end
36
48
 
37
49
  def skip_spaces
50
+ char = nil
38
51
  loop do
39
- break if peek != " "
52
+ char = peek
40
53
  break if eos?
41
- self.next
54
+ break if char != " "
55
+ grab
42
56
  end
57
+ char
43
58
  end
44
59
 
45
60
  end
data/lib/processor.rb CHANGED
@@ -40,16 +40,12 @@ class Livetext
40
40
 
41
41
  def _error!(err, raise_error=false, trace=false) # FIXME much bullshit happens here
42
42
  where = @sources.last || @save_location
43
- # puts @parent.body
44
- # puts "[lib/processor] Error: #{err}"
45
- # puts err.backtrace.join("\n") if err.respond_to?(:backtrace)
46
- STDERR.puts "Error: #{err}" # (at #{where[1]} line #{where[2]})"
43
+ STDERR.puts "Error: #{err} (at #{where[1]} line #{where[2]})"
47
44
  STDERR.puts err.backtrace if err.respond_to?(:backtrace) # && trace
48
- # raise "lib/processor error!" # FIXME
49
45
  raise GenericError.new("Error: #{err}") if raise_error
50
46
  end
51
47
 
52
- def _disallowed?(name)
48
+ def disallowed?(name)
53
49
  Disallowed.include?(name.to_sym)
54
50
  end
55
51
 
@@ -75,11 +71,5 @@ class Livetext
75
71
  @sources.pop
76
72
  nil
77
73
  end
78
-
79
- def grab_file(fname)
80
- File.read(fname)
81
- end
82
-
83
74
  end
84
-
85
75
  end
data/lib/standard.rb CHANGED
@@ -5,8 +5,8 @@ require_relative 'html'
5
5
  require_relative 'helpers'
6
6
 
7
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")
8
+ make_exception(:DisallowedName, "Error: name '%1' is invalid")
9
+ make_exception(:FileNotFound, "Error: file '%1' not found")
10
10
 
11
11
 
12
12
  # Module Standard comprises most of the standard or "common" methods.
@@ -24,13 +24,14 @@ module Livetext::Standard
24
24
 
25
25
  attr_reader :_data
26
26
 
27
- def data=(val) # FIXME this is weird, let's not do it
27
+ def data=(val) # FIXME this is weird, let's remove it soonish
28
28
  @_data = val.chomp
29
29
  @_args = val.split rescue []
30
30
  @_mixins = []
31
31
  end
32
32
 
33
- def bits # dumb name - bold, italic, teletype, striketrough
33
+ # dumb name - bold, italic, teletype, striketrough
34
+ def bits(args = nil, body = nil)
34
35
  b0, b1, i0, i1, t0, t1, s0, s1 = *@_args
35
36
  SimpleFormats[:b] = [b0, b1]
36
37
  SimpleFormats[:i] = [i0, i1]
@@ -38,23 +39,23 @@ module Livetext::Standard
38
39
  SimpleFormats[:s] = [s0, s1]
39
40
  end
40
41
 
41
- def backtrace
42
+ def backtrace(args = nil, body = nil)
42
43
  @backtrace = onoff(@_args.first)
43
44
  _optional_blank_line
44
45
  end
45
46
 
46
- def comment
47
+ def comment(args = nil, body = nil)
47
48
  _body
48
49
  _optional_blank_line
49
50
  end
50
51
 
51
- def shell
52
+ def shell(args = nil, body = nil)
52
53
  cmd = @_data.chomp
53
54
  system(cmd)
54
55
  _optional_blank_line
55
56
  end
56
57
 
57
- def func
58
+ def func(args = nil, body = nil)
58
59
  funcname = @_args[0]
59
60
  check_disallowed(funcname)
60
61
  func_def = <<~EOS
@@ -63,25 +64,24 @@ module Livetext::Standard
63
64
  end
64
65
  EOS
65
66
  _optional_blank_line
66
-
67
67
  Livetext::Functions.class_eval func_def
68
68
  end
69
69
 
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
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
76
76
 
77
- def list
77
+ def list(args = nil, body = nil)
78
78
  wrap :ul do
79
79
  _body {|line| _out wrapped(line, :li) }
80
80
  end
81
81
  _optional_blank_line
82
82
  end
83
83
 
84
- def list!
84
+ def list!(args = nil, body = nil)
85
85
  wrap(:ul) do
86
86
  lines = _body.each # enumerator
87
87
  loop do
@@ -94,49 +94,49 @@ module Livetext::Standard
94
94
  _optional_blank_line
95
95
  end
96
96
 
97
- def shell!
97
+ def shell!(args = nil, body = nil)
98
98
  cmd = @_data.chomp
99
99
  system(cmd)
100
100
  _optional_blank_line
101
101
  end
102
102
 
103
- def errout
103
+ def errout(args = nil, body = nil)
104
104
  STDERR.puts @_data.chomp
105
105
  _optional_blank_line
106
106
  end
107
107
 
108
- def ttyout
108
+ def ttyout(args = nil, body = nil)
109
109
  TTY.puts @_data.chomp
110
110
  _optional_blank_line
111
111
  end
112
112
 
113
- def say
113
+ def say(args = nil, body = nil)
114
114
  str = _format(@_data.chomp)
115
115
  TTY.puts str
116
116
  _optional_blank_line
117
117
  end
118
118
 
119
- def banner
119
+ def banner(args = nil, body = nil)
120
120
  str = _format(@_data.chomp)
121
- num = str.length - 1
121
+ num = str.length
122
122
  decor = "-"*num + "\n"
123
123
  puts decor + str + "\n" + decor
124
124
  end
125
125
 
126
- def quit
126
+ def quit(args = nil, body = nil)
127
127
  puts @body
128
128
  @body = ""
129
129
  @output.close
130
130
  end
131
131
 
132
- def cleanup
132
+ def cleanup(args = nil, body = nil)
133
133
  @_args.each do |item|
134
134
  cmd = ::File.directory?(item) ? "rm -f #{item}/*" : "rm #{item}"
135
135
  system(cmd)
136
136
  end
137
137
  end
138
138
 
139
- def _def
139
+ def dot_def(args = nil, body = nil)
140
140
  name = @_args[0]
141
141
  str = "def #{name}\n"
142
142
  check_disallowed(name)
@@ -144,17 +144,17 @@ module Livetext::Standard
144
144
  str << _body(true).join("\n")
145
145
  str << "\nend\n"
146
146
  eval str
147
- # rescue => err
148
- # _error!(err)
149
147
  end
150
148
 
151
- def set
149
+ def set(args = nil, body = nil)
152
150
  line = _data.chomp
153
151
  pairs = Livetext::ParseSet.new(line).parse
154
152
  set_variables(pairs)
155
153
  end
156
154
 
157
- def variables! # cwd, not FileDir - weird, fix later
155
+ # FIXME really these should be one method...
156
+
157
+ def variables!(args = nil, body = nil) # cwd, not FileDir - weird, fix later
158
158
  prefix = _args[0]
159
159
  file = _args[1]
160
160
  prefix = nil if prefix == "-" # FIXME dumb hack
@@ -164,11 +164,11 @@ module Livetext::Standard
164
164
  else
165
165
  lines = _body
166
166
  end
167
- pairs = Livetext::ParseMisc.parse_vars(prefix, lines)
167
+ pairs = Livetext::ParseGeneral.parse_vars(prefix, lines)
168
168
  set_variables(pairs)
169
169
  end
170
170
 
171
- def variables
171
+ def variables(args = nil, body = nil)
172
172
  prefix = _args[0]
173
173
  file = _args[1]
174
174
  prefix = nil if prefix == "-" # FIXME dumb hack
@@ -178,11 +178,11 @@ module Livetext::Standard
178
178
  else
179
179
  lines = _body
180
180
  end
181
- pairs = Livetext::ParseMisc.parse_vars(prefix, lines)
181
+ pairs = Livetext::ParseGeneral.parse_vars(prefix, lines)
182
182
  set_variables(pairs)
183
183
  end
184
184
 
185
- def heredoc
185
+ def heredoc(args = nil, body = nil)
186
186
  var = @_args[0]
187
187
  text = _body.join("\n")
188
188
  rhs = ""
@@ -192,59 +192,26 @@ module Livetext::Standard
192
192
  end
193
193
  indent = @parent.indentation.last
194
194
  indented = " " * indent
195
- @parent._setvar(var, rhs.chomp)
195
+ @parent.setvar(var, rhs.chomp)
196
196
  _optional_blank_line
197
197
  end
198
198
 
199
- def _seek(file)
200
- value = nil
201
- return file if File.exist?(file)
202
-
203
- count = 1
204
- loop do
205
- front = "../" * count
206
- count += 1
207
- here = Pathname.new(front).expand_path.dirname.to_s
208
- break if here == "/"
209
- path = front + file
210
- value = path if File.exist?(path)
211
- break if value
212
- end
213
- STDERR.puts "Cannot find #{file.inspect} from #{Dir.pwd}" unless value
214
- return value
215
- rescue
216
- STDERR.puts "Can't find #{file.inspect} from #{Dir.pwd}"
217
- return nil
218
- end
219
-
220
- def seek # like include, but search upward as needed
199
+ def seek(args = nil, body = nil) # like include, but search upward as needed
221
200
  file = @_args.first
222
- file = _seek(file)
201
+ file = search_upward(file)
223
202
  check_file_exists(file)
224
203
  @parent.process_file(file)
225
204
  _optional_blank_line
226
205
  end
227
206
 
228
- def in_out # FIXME dumb name!
229
- file, dest = *@_args
230
- check_file_exists(file)
231
- @parent.process_file(file, dest)
232
- _optional_blank_line
233
- end
234
-
235
- def _include # dot command
207
+ def dot_include(args = nil, body = nil) # dot command
236
208
  file = _format(@_args.first) # allows for variables
237
209
  check_file_exists(file)
238
210
  @parent.process_file(file)
239
211
  _optional_blank_line
240
212
  end
241
213
 
242
- def _include_file(file)
243
- @_args = [file]
244
- _include
245
- end
246
-
247
- def inherit
214
+ def inherit(args = nil, body = nil)
248
215
  file = @_args.first
249
216
  upper = "../#{file}"
250
217
  got_upper, got_file = File.exist?(upper), File.exist?(file)
@@ -256,95 +223,94 @@ module Livetext::Standard
256
223
  _optional_blank_line
257
224
  end
258
225
 
259
- def mixin
226
+ def mixin(args = nil, body = nil)
260
227
  name = @_args.first # Expect a module name
261
228
  return if @_mixins.include?(name)
262
229
  @_mixins << name
263
- parse = Livetext::ParseMixin.new(name) # FIXME??
264
- file = parse.find_mixin(name)
265
- parse.use_mixin(name, file)
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
266
234
  _optional_blank_line
267
235
  end
268
236
 
269
- def import
237
+ def icanhaz(args = nil, body = nil)
270
238
  name = @_args.first # Expect a module name
271
239
  return if @_mixins.include?(name)
272
240
  @_mixins << name
273
- parse = Livetext::ParseImport.new(name)
241
+ mod = Livetext::Handler::ICanHaz.get_module(name) # FIXME??
242
+ self.extend(mod)
243
+ init = "init_#{name}"
244
+ self.send(init) if self.respond_to? init
245
+ _optional_blank_line
246
+ end
247
+
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)
274
253
  parse.use_import(name)
275
254
  _optional_blank_line
276
255
  end
277
256
 
278
- def copy
257
+ def copy(args = nil, body = nil)
279
258
  file = @_args.first
280
259
  check_file_exists(file)
281
260
  _out grab_file(file)
282
261
  _optional_blank_line
283
262
  end
284
263
 
285
- def r
264
+ def r(args = nil, body = nil)
286
265
  _out @_data.chomp # No processing at all
287
266
  end
288
267
 
289
- def raw
268
+ def raw(args = nil, body = nil)
290
269
  # No processing at all (terminate with __EOF__)
291
270
  _raw_body {|line| _out line } # no formatting
292
271
  end
293
272
 
294
- def debug
273
+ def debug(args = nil, body = nil)
295
274
  self._debug = onoff(@_args.first)
296
275
  end
297
276
 
298
- def passthru
277
+ def passthru(args = nil, body = nil)
299
278
  # FIXME - add check for args size? (helpers)
300
279
  @_nopass = ! onoff(_args.first)
301
280
  end
302
281
 
303
- def nopass
282
+ def nopass(args = nil, body = nil)
304
283
  @_nopass = true
305
284
  end
306
285
 
307
- def para
286
+ def para(args = nil, body = nil)
308
287
  # FIXME - add check for args size? (helpers)
309
288
  @_nopara = ! onoff(_args.first)
310
289
  end
311
290
 
312
- def onoff(arg) # helper
313
- arg ||= "on"
314
- raise ExpectedOnOff unless String === arg
315
- case arg.downcase
316
- when "on"
317
- return true
318
- when "off"
319
- return false
320
- else
321
- raise ExpectedOnOff
322
- end
323
- end
324
-
325
- def nopara
291
+ def nopara(args = nil, body = nil)
326
292
  @_nopara = true
327
293
  end
328
294
 
329
- def heading
295
+ def heading(args = nil, body = nil)
330
296
  _print "<center><font size=+1><b>"
331
297
  _print @_data.chomp
332
298
  _print "</b></font></center>"
333
299
  end
334
300
 
335
- def newpage
301
+ def newpage(args = nil, body = nil)
336
302
  _out '<p style="page-break-after:always;"></p>'
337
303
  _out "<p/>"
338
304
  end
339
305
 
340
- def mono
306
+ def mono(args = nil, body = nil)
341
307
  wrap ":pre" do
342
308
  _body(true) {|line| _out line }
343
309
  end
344
310
  _optional_blank_line
345
311
  end
346
312
 
347
- def dlist
313
+ def dlist(args = nil, body = nil)
348
314
  delim = _args.first
349
315
  wrap(:dl) do
350
316
  _body do |line|
@@ -356,13 +322,13 @@ module Livetext::Standard
356
322
  end
357
323
  end
358
324
 
359
- def link
325
+ def link(args = nil, body = nil)
360
326
  url = _args.first
361
327
  text = _args[2..-1].join(" ")
362
328
  _out "<a style='text-decoration: none' href='#{url}'>#{text}</a>"
363
329
  end
364
330
 
365
- def xtable # Borrowed from bookish - FIXME
331
+ def xtable(args = nil, body = nil) # Borrowed from bookish - FIXME
366
332
  title = @_data.chomp
367
333
  delim = " :: "
368
334
  _out "<br><center><table width=90% cellpadding=5>"
@@ -389,12 +355,12 @@ module Livetext::Standard
389
355
  _out "</table></center>"
390
356
  end
391
357
 
392
- def image
358
+ def image(args = nil, body = nil)
393
359
  name = @_args[0]
394
360
  _out "<img src='#{name}'></img>"
395
361
  end
396
362
 
397
- def br
363
+ def br(args = nil, body = nil)
398
364
  num = _args.first || "1"
399
365
  out = ""
400
366
  num.to_i.times { out << "<br>" }
data/lib/userapi.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative 'formatline'
4
4
 
5
5
  # UserAPI deals mostly with user-level methods.
6
+
6
7
  module Livetext::UserAPI
7
8
 
8
9
  def setvar(var, val)
@@ -94,10 +95,6 @@ module Livetext::UserAPI
94
95
  else
95
96
  lines
96
97
  end
97
- # rescue => err
98
- # str = err.inspect + "\n"
99
- # str << err.backtrace.map {|x| " " + x }.join("\n")
100
- # _error!(str)
101
98
  end
102
99
 
103
100
  def _body_text(raw=false)
data/livetext.gemspec CHANGED
@@ -15,7 +15,8 @@ Gem::Specification.new do |s|
15
15
  s.executables << "livetext"
16
16
 
17
17
  # Files...
18
- main = Find.find("bin").to_a + Find.find("lib").to_a + Find.find("plugin").to_a
18
+ main = Find.find("bin").to_a + Find.find("lib").to_a +
19
+ Find.find("plugin").to_a + Find.find("imports").to_a
19
20
  misc = %w[./README.lt3 ./README.md livetext.gemspec]
20
21
  test = Find.find("test").to_a
21
22
 
data/plugin/bookish.rb CHANGED
@@ -1,4 +1,4 @@
1
- def hardbreaks
1
+ def hardbreaks(args = nil, body = nil)
2
2
  @hard = false
3
3
  @hard = true unless @_args.first == "off"
4
4
  end
@@ -7,15 +7,17 @@ def hardbreaks?
7
7
  @hard
8
8
  end
9
9
 
10
- def credit
10
+ def credit(args = nil, body = nil)
11
11
  # really just a place marker in source
12
12
  end
13
13
 
14
+ # These are duplicated. Remove safely
15
+
14
16
  def h1; _out "<h1>#{@_data}</h1>"; end
15
17
  def h2; _out "<h2>#{@_data}</h2>"; end
16
18
  def h3; _out "<h3>#{@_data}</h3>"; end
17
19
 
18
- def alpha_columns
20
+ def alpha_columns(args = nil, body = nil)
19
21
  n = @_args.first.to_i # FIXME: what if missing?
20
22
  words = []
21
23
  _body do |line|
@@ -30,9 +32,9 @@ def alpha_columns
30
32
  _out "</table>"
31
33
  end
32
34
 
33
- def comment
34
- _body { } # ignore body
35
- end
35
+ # def comment
36
+ # _body { } # ignore body
37
+ # end
36
38
 
37
39
  def _errout(*args)
38
40
  ::STDERR.puts *args
@@ -48,12 +50,14 @@ def _slug(str)
48
50
  s2
49
51
  end
50
52
 
51
- def image
53
+
54
+ # FIXME duplicated?
55
+ def image(args = nil, body = nil)
52
56
  name = @_args[0]
53
57
  _out "<img src='#{name}'></img>"
54
58
  end
55
59
 
56
- def figure
60
+ def figure(args = nil, body = nil)
57
61
  name = @_args[0]
58
62
  num = @_args[1]
59
63
  title = @_args[2..-1].join(" ")
@@ -62,7 +66,7 @@ def figure
62
66
  _out "<center><b>Figure #{num}</b> #{title}</center>"
63
67
  end
64
68
 
65
- def chapter
69
+ def chapter(args = nil, body = nil)
66
70
  # _errout("chapter")
67
71
  @chapter = @_args.first.to_i
68
72
  @sec = @sec2 = 0
@@ -78,7 +82,7 @@ def chapter
78
82
  HTML
79
83
  end
80
84
 
81
- def chapterN
85
+ def chapterN(args = nil, body = nil)
82
86
  @chapter += 1
83
87
  @sec = @sec2 = 0
84
88
  title = @_data # .split(" ",2)[1]
@@ -94,7 +98,7 @@ def chapterN
94
98
  HTML
95
99
  end
96
100
 
97
- def sec
101
+ def sec(args = nil, body = nil)
98
102
  @sec += 1
99
103
  @sec2 = 0
100
104
  @section = "#@chapter.#@sec"
@@ -108,7 +112,7 @@ rescue => err
108
112
  exit
109
113
  end
110
114
 
111
- def subsec
115
+ def subsec(args = nil, body = nil)
112
116
  @sec2 += 1
113
117
  @subsec = "#@chapter.#@sec.#@sec2"
114
118
  title = @_data.dup
@@ -118,7 +122,7 @@ def subsec
118
122
  _out "<h3>#@subsec #{title}</h3>\n"
119
123
  end
120
124
 
121
- def definition_table
125
+ def definition_table(args = nil, body = nil)
122
126
  title = @_data
123
127
  wide = "95"
124
128
  delim = " :: "
@@ -140,7 +144,7 @@ def definition_table
140
144
  _optional_blank_line
141
145
  end
142
146
 
143
- def table2
147
+ def table2(args = nil, body = nil)
144
148
  title = @_data
145
149
  wide = "90"
146
150
  extra = _args[2]
@@ -164,7 +168,7 @@ def table2
164
168
  _optional_blank_line
165
169
  end
166
170
 
167
- def simple_table
171
+ def simple_table(args = nil, body = nil)
168
172
  title = @_data
169
173
  delim = " :: "
170
174
  _out "<table cellpadding=2>"
@@ -193,7 +197,7 @@ def simple_table
193
197
  _out "</table>"
194
198
  end
195
199
 
196
- def table
200
+ def table(args = nil, body = nil)
197
201
  @table_num ||= 0
198
202
  @table_num += 1
199
203
  title = @_data
@@ -227,7 +231,7 @@ def table
227
231
  _out "<b>Table #@chapter.#@table_num &nbsp;&nbsp; #{title}</b></center><br>"
228
232
  end
229
233
 
230
- def toc!
234
+ def toc!(args = nil, body = nil)
231
235
  _debug "Closing TOC"
232
236
  @toc.close
233
237
  rescue => err
@@ -236,7 +240,7 @@ rescue => err
236
240
  _errout "Exception: #{err.inspect}"
237
241
  end
238
242
 
239
- def toc2
243
+ def toc2(args = nil, body = nil)
240
244
  file = @_args[0]
241
245
  @toc.close
242
246
  ::File.write(file, <<-EOS)
@@ -249,24 +253,24 @@ EOS
249
253
  system("cat toc.tmp >>#{file}")
250
254
  end
251
255
 
252
- def missing
256
+ def missing(args = nil, body = nil)
253
257
  @toc << "#{_nbsp(8)}<font color=red>TBD: #@_data</font><br>"
254
258
  stuff = @_data.empty? ? "" : ": #@_data"
255
259
  _out "<br><font color=red><i>[Material missing#{stuff}]</i></font><br>\n "
256
260
  end
257
261
 
258
- def TBC
262
+ def TBC(args = nil, body = nil)
259
263
  @toc << "#{_nbsp(8)}<font color=red>To be continued...</font><br>"
260
264
  _out "<br><font color=red><i>To be continued...</i></font><br>"
261
265
  end
262
266
 
263
- def note
267
+ def note(args = nil, body = nil)
264
268
  _out "<br><font color=red><i>Note: "
265
269
  _out @_data
266
270
  _out "</i></font><br>\n "
267
271
  end
268
272
 
269
- def quote
273
+ def quote(args = nil, body = nil)
270
274
  _out "<blockquote>"
271
275
  _body {|line| _out line }
272
276
  _out "</blockquote>"