livetext 0.9.35 → 0.9.37

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb4392b3c99d41bf20385de2f5cbb25846fb9193ab303072075d0baf904912d2
4
- data.tar.gz: b7fb45dd41a63f9c2cf39afa6e8973f53a8828c1063a341ad8ecd78eb4468f96
3
+ metadata.gz: 784ac1767694b1d098d3e289082070ef3e3df0aab15766cf42105e854da31730
4
+ data.tar.gz: b6f62f1164873ec613b16067c53abc0e1b8906cacaeaae033bd5e862ca6b4bd5
5
5
  SHA512:
6
- metadata.gz: 06e2d46af57bb812baecb5afcc30147abc862df4c4a0619f0151b3b2e6db3c78d7ef7f05eb8cab1e388a7efd73d7ca67ac2143fb5fb901f0b5abcf233b9dcb86
7
- data.tar.gz: 0575eaf1bcf527c19ba6ea7ecf7d28b36c6f4dab8b4b81a57185bb9454452af4127bf60dea9a8d15039f29a7919ad7930a99e8aacf6f74ad4f55554bb9ade072
6
+ metadata.gz: 795730de451f27c2ffccf326fcc976e170ae884fef45d3bc732bb59826cc40bbff0e877d3ee3ed051fa3f20e0836ccede6668c42ba7a21ec1bf51910ebfc7a99
7
+ data.tar.gz: 1db7dfbb839a6787872df65d591b49fb36db69f9d3ddc86805d981f19266c98abcac4a8bbe8efebdf1137ec674201a3b3f4e0f09d849116acb56f390eefd8cbd
data/bin/livetext CHANGED
@@ -93,8 +93,8 @@ def parse_command_line
93
93
  end
94
94
  end
95
95
  @live.dump if success
96
- # rescue => err
97
- # STDERR.puts "Unexpected error! #{err.inspect}"
96
+ rescue => err
97
+ STDERR.puts "Unexpected error! #{err.inspect}\n#{err.backtrace.join("\n")}"
98
98
  end
99
99
 
100
100
  # Main
@@ -2,6 +2,7 @@
2
2
  require_relative 'global_helpers'
3
3
  require_relative 'expansion'
4
4
 
5
+
5
6
  module Livetext::Helpers
6
7
 
7
8
  Space = " "
@@ -98,13 +99,16 @@ module Livetext::Helpers
98
99
  when Comment
99
100
  success = handle_scomment(line)
100
101
  when DotCmd
101
- success = handle_dotcmd(line)
102
+ success = handle_dotcmd(line) # was 102
102
103
  when DollarDot
103
104
  success = handle_dollar_dot(line)
104
105
  else
105
106
  api.passthru(line) # must succeed?
106
107
  end
107
108
  success
109
+ rescue => err
110
+ STDERR.puts "ERROR: #{err}\n#{err.backtrace.join("\n")}"
111
+ exit
108
112
  end
109
113
 
110
114
  def handle_dollar_dot(line)
@@ -120,10 +124,10 @@ module Livetext::Helpers
120
124
  api.data = data0.dup # should permit _ in function names at least
121
125
  args0 = data0.split
122
126
  api.args = args0.dup
123
- retval = @main.send(name) # , *args)
127
+ retval = @main.send(name) # , *args) # was 125
124
128
  retval
125
129
  rescue => err
126
- graceful_error(err)
130
+ graceful_error(err) # , "#{__method__}: name = #{name}")
127
131
  end
128
132
 
129
133
  def handle_dotcmd(line, indent = 0)
@@ -135,7 +139,7 @@ module Livetext::Helpers
135
139
  when name == :end # special case
136
140
  graceful_error EndWithoutOpening()
137
141
  when @main.respond_to?(name)
138
- success = invoke_dotcmd(name, data)
142
+ success = invoke_dotcmd(name, data) # was 141
139
143
  else
140
144
  graceful_error UnknownMethod(name)
141
145
  end
@@ -250,3 +254,9 @@ module Livetext::Helpers
250
254
  end
251
255
 
252
256
  end
257
+
258
+ =begin
259
+ /Users/Hal/.rvm/gems/ruby-2.7.0/gems/livetext-0.9.35/lib/livetext/helpers.rb:125:in `invoke_dotcmd'
260
+ /Users/Hal/.rvm/gems/ruby-2.7.0/gems/livetext-0.9.35/lib/livetext/helpers.rb:141:in `handle_dotcmd'
261
+ /Users/Hal/.rvm/gems/ruby-2.7.0/gems/livetext-0.9.35/lib/livetext/helpers.rb:102:in `process_line'
262
+ =end
data/lib/livetext/more.rb CHANGED
@@ -91,8 +91,9 @@ class Livetext
91
91
  TTY.puts "#dump had an error: #{err.inspect}"
92
92
  end
93
93
 
94
- def graceful_error(err)
94
+ def graceful_error(err, msg = nil)
95
95
  dump
96
+ STDERR.puts msg if msg
96
97
  raise err
97
98
  end
98
99
 
@@ -44,23 +44,23 @@ module Livetext::Standard
44
44
  # end
45
45
  # end
46
46
 
47
- def backtrace
47
+ def backtrace(args = nil, body = nil)
48
48
  @backtrace = onoff(api.args.first)
49
49
  api.optional_blank_line
50
50
  end
51
51
 
52
- def comment
52
+ def comment(args = nil, body = nil)
53
53
  api.body
54
54
  api.optional_blank_line
55
55
  end
56
56
 
57
- def shell
57
+ def shell(args = nil, body = nil)
58
58
  cmd = api.data
59
59
  system(cmd)
60
60
  api.optional_blank_line
61
61
  end
62
62
 
63
- def func
63
+ def func(args = nil, body = nil)
64
64
  funcname = api.args[0]
65
65
  # check_disallowed(funcname) # should any be invalid?
66
66
  funcname = funcname.gsub(/\./, "__")
@@ -74,21 +74,21 @@ module Livetext::Standard
74
74
  return true
75
75
  end
76
76
 
77
- def h1; api.out wrapped(api.data, :h1); return true; end
78
- def h2; api.out wrapped(api.data, :h2); return true; end
79
- def h3; api.out wrapped(api.data, :h3); return true; end
80
- def h4; api.out wrapped(api.data, :h4); return true; end
81
- def h5; api.out wrapped(api.data, :h5); return true; end
82
- def h6; api.out wrapped(api.data, :h6); return true; end
77
+ def h1(args = nil, body = nil); api.out html.tag(:h1, api.data); return true; end
78
+ def h2(args = nil, body = nil); api.out html.tag(:h2, api.data); return true; end
79
+ def h3(args = nil, body = nil); api.out html.tag(:h3, api.data); return true; end
80
+ def h4(args = nil, body = nil); api.out html.tag(:h4, api.data); return true; end
81
+ def h5(args = nil, body = nil); api.out html.tag(:h5, api.data); return true; end
82
+ def h6(args = nil, body = nil); api.out html.tag(:h6, api.data); return true; end
83
83
 
84
- def list
84
+ def list(args = nil, body = nil)
85
85
  html.wrap :ul do
86
- api.body {|line| api.out wrapped(line, :li) }
86
+ api.body {|line| api.out html.tag(:li, line) }
87
87
  end
88
88
  api.optional_blank_line
89
89
  end
90
90
 
91
- def list!
91
+ def list!(args = nil, body = nil)
92
92
  html.wrap(:ul) do
93
93
  lines = api.body.each # enumerator
94
94
  loop do
@@ -101,40 +101,41 @@ module Livetext::Standard
101
101
  api.optional_blank_line
102
102
  end
103
103
 
104
- def shell!
104
+ def shell!(args = nil, body = nil)
105
105
  cmd = api.data
106
106
  system(cmd)
107
107
  api.optional_blank_line
108
108
  end
109
109
 
110
- def errout
110
+ def errout(args = nil, body = nil)
111
111
  ::STDERR.puts api.data
112
112
  api.optional_blank_line
113
113
  end
114
114
 
115
- def ttyout
115
+ def ttyout(args = nil, body = nil)
116
116
  TTY.puts api.data
117
117
  api.optional_blank_line
118
118
  end
119
119
 
120
- def say
121
- str = api.format(api.data)
122
- TTY.puts str
120
+ def say(args = nil, body = nil)
121
+ data = args || api.args.join(" ")
122
+ str = api.format(data)
123
+ TTY.puts "(say) #{str}"
123
124
  api.optional_blank_line
124
125
  end
125
126
 
126
- def banner
127
+ def banner(args = nil, body = nil)
127
128
  str = api.format(api.data)
128
129
  num = str.length
129
130
  decor = "-"*num + "\n"
130
131
  puts decor + str + "\n" + decor
131
132
  end
132
133
 
133
- def quit
134
+ def quit(args = nil, body = nil)
134
135
  @output.close
135
136
  end
136
137
 
137
- def cleanup
138
+ def cleanup(args = nil, body = nil)
138
139
  api.args.each do |item|
139
140
  cmd = ::File.directory?(item) ? "rm -f #{item}/*" : "rm #{item}"
140
141
  system(cmd)
@@ -142,7 +143,7 @@ module Livetext::Standard
142
143
  api.optional_blank_line
143
144
  end
144
145
 
145
- def dot_def
146
+ def dot_def(args = nil, body = nil)
146
147
  name = api.args[0]
147
148
  check_disallowed(name)
148
149
  # Difficult to avoid eval here
@@ -153,7 +154,7 @@ module Livetext::Standard
153
154
  api.optional_blank_line
154
155
  end
155
156
 
156
- def set
157
+ def set(args = nil, body = nil)
157
158
  line = api.args.join(" ") # data.chomp
158
159
  pairs = Livetext::ParseSet.new(line).parse
159
160
  api.setvars(pairs)
@@ -162,7 +163,7 @@ module Livetext::Standard
162
163
 
163
164
  # FIXME really these should be one method...
164
165
 
165
- def variables! # cwd, not FileDir - weird, fix later
166
+ def variables!(args = nil, body = nil) # cwd, not FileDir - weird, fix later
166
167
  prefix = api.args[0]
167
168
  file = api.args[1]
168
169
  prefix = nil if prefix == "-" # FIXME dumb hack
@@ -177,7 +178,7 @@ module Livetext::Standard
177
178
  api.optional_blank_line
178
179
  end
179
180
 
180
- def variables
181
+ def variables(args = nil, body = nil)
181
182
  prefix = api.args[0]
182
183
  file = api.args[1]
183
184
  prefix = nil if prefix == "-" # FIXME dumb hack
@@ -192,7 +193,7 @@ module Livetext::Standard
192
193
  api.optional_blank_line
193
194
  end
194
195
 
195
- def heredoc
196
+ def heredoc(args = nil, body = nil)
196
197
  var = api.args[0]
197
198
  text = api.body.join("\n")
198
199
  rhs = ""
@@ -206,7 +207,7 @@ module Livetext::Standard
206
207
  api.optional_blank_line
207
208
  end
208
209
 
209
- def seek # like include, but search upward as needed
210
+ def seek(args = nil, body = nil) # like include, but search upward as needed
210
211
  file = api.args.first
211
212
  file = search_upward(file)
212
213
  check_file_exists(file)
@@ -214,14 +215,14 @@ module Livetext::Standard
214
215
  api.optional_blank_line
215
216
  end
216
217
 
217
- def dot_include # dot command
218
+ def dot_include(args = nil, body = nil) # dot command
218
219
  file = api.expand_variables(api.args.first) # allows for variables
219
220
  check_file_exists(file)
220
221
  @parent.process_file(file)
221
222
  api.optional_blank_line
222
223
  end
223
224
 
224
- def inherit
225
+ def inherit(args = nil, body = nil)
225
226
  file = api.args.first
226
227
  upper = "../#{file}"
227
228
  got_upper, got_file = File.exist?(upper), File.exist?(file)
@@ -233,7 +234,7 @@ module Livetext::Standard
233
234
  api.optional_blank_line
234
235
  end
235
236
 
236
- def mixin
237
+ def mixin(args = nil, body = nil)
237
238
  name = api.args.first # Expect a module name
238
239
  @mixins ||= []
239
240
  return if @mixins.include?(name)
@@ -245,7 +246,7 @@ module Livetext::Standard
245
246
  api.optional_blank_line
246
247
  end
247
248
 
248
- def import
249
+ def import(args = nil, body = nil)
249
250
  name = api.args.first # Expect a module name
250
251
  @imports ||= []
251
252
  return if @imports.include?(name)
@@ -257,7 +258,7 @@ module Livetext::Standard
257
258
  api.optional_blank_line
258
259
  end
259
260
 
260
- def copy
261
+ def copy(args = nil, body = nil)
261
262
  file = api.args.first
262
263
  ok = check_file_exists(file)
263
264
 
@@ -267,67 +268,67 @@ module Livetext::Standard
267
268
  [ok, file]
268
269
  end
269
270
 
270
- def r
271
+ def r(args = nil, body = nil)
271
272
  # FIXME api.data is broken
272
273
  # api.out api.data # No processing at all
273
274
  api.out api.args.join(" ")
274
275
  api.optional_blank_line
275
276
  end
276
277
 
277
- def raw
278
+ def raw(args = nil, body = nil)
278
279
  # No processing at all (terminate with __EOF__)
279
280
  api.raw_body {|line| api.out line } # no formatting
280
281
  api.optional_blank_line
281
282
  end
282
283
 
283
- def debug
284
- self.debug = onoff(api.args.first)
284
+ def debug(args = nil, body = nil)
285
+ @debug = onoff(api.args.first)
285
286
  api.optional_blank_line
286
287
  end
287
288
 
288
- def passthru
289
+ def passthru(args = nil, body = nil)
289
290
  # FIXME - add check for args size? (helpers)
290
291
  @nopass = ! onoff(api.args.first)
291
292
  api.optional_blank_line
292
293
  end
293
294
 
294
- def nopass
295
+ def nopass(args = nil, body = nil)
295
296
  @nopass = true
296
297
  api.optional_blank_line
297
298
  end
298
299
 
299
- def para
300
+ def para(args = nil, body = nil)
300
301
  # FIXME - add check for args size? (helpers)
301
302
  @nopara = ! onoff(api.args.first)
302
303
  api.optional_blank_line
303
304
  end
304
305
 
305
- def nopara
306
+ def nopara(args = nil, body = nil)
306
307
  @nopara = true
307
308
  api.optional_blank_line
308
309
  end
309
310
 
310
- def heading
311
+ def heading(args = nil, body = nil)
311
312
  api.print "<center><font size=+1><b>"
312
313
  api.print api.data
313
314
  api.print "</b></font></center>"
314
315
  api.optional_blank_line
315
316
  end
316
317
 
317
- def newpage
318
+ def newpage(args = nil, body = nil)
318
319
  api.out '<p style="page-break-after:always;"></p>'
319
320
  api.out "<p/>"
320
321
  api.optional_blank_line
321
322
  end
322
323
 
323
- def mono
324
+ def mono(args = nil, body = nil)
324
325
  html.wrap ":pre" do
325
326
  api.body(true) {|line| api.out line }
326
327
  end
327
328
  api.optional_blank_line
328
329
  end
329
330
 
330
- def dlist
331
+ def dlist(args = nil, body = nil)
331
332
  delim = api.args.first
332
333
  html.wrap(:dl) do
333
334
  api.body do |line|
@@ -340,14 +341,14 @@ module Livetext::Standard
340
341
  api.optional_blank_line
341
342
  end
342
343
 
343
- def link
344
+ def link(args = nil, body = nil)
344
345
  url = api.args.first
345
346
  text = api.args[2..-1].join(" ")
346
347
  api.out "<a style='text-decoration: none' href='#{url}'>#{text}</a>"
347
348
  api.optional_blank_line
348
349
  end
349
350
 
350
- def xtable # Borrowed from bookish - FIXME
351
+ def xtable(args = nil, body = nil) # Borrowed from bookish - FIXME
351
352
  title = api.data
352
353
  delim = " :: "
353
354
  api.out "<br><center><table width=90% cellpadding=5>"
@@ -377,7 +378,7 @@ module Livetext::Standard
377
378
  api.optional_blank_line
378
379
  end
379
380
 
380
- def image
381
+ def image(args = nil, body = nil)
381
382
  name, wide, high = api.args
382
383
  geom = ""
383
384
  geom = "width=#{wide} height=#{high}" if wide || high
@@ -385,7 +386,7 @@ module Livetext::Standard
385
386
  api.optional_blank_line
386
387
  end
387
388
 
388
- def br
389
+ def br(args = nil, body = nil)
389
390
  num = api.args.first || "1"
390
391
  str = ""
391
392
  num.to_i.times { str << "<br>" }
@@ -393,7 +394,7 @@ module Livetext::Standard
393
394
  api.optional_blank_line
394
395
  end
395
396
 
396
- def reflection # strictly experimental!
397
+ def reflection(args = nil, body = nil) # strictly experimental!
397
398
  list = self.methods
398
399
  obj = Object.instance_methods
399
400
  diff = (list - obj).sort
@@ -2,5 +2,5 @@
2
2
  # Defining VERSION
3
3
 
4
4
  class Livetext
5
- VERSION = "0.9.35"
5
+ VERSION = "0.9.37"
6
6
  end
data/plugin/bookish.rb CHANGED
@@ -15,9 +15,12 @@ end
15
15
 
16
16
  # These are duplicated. Remove safely
17
17
 
18
- def h1; api.out "<h1>#{api.data}</h1>"; api.optional_blank_line; end
19
- def h2; api.out "<h2>#{api.data}</h2>"; api.optional_blank_line; end
20
- def h3; api.out "<h3>#{api.data}</h3>"; api.optional_blank_line; end
18
+ def h1(args = nil, body = nil); api.out html.tag(:h1, api.data); return true; end
19
+ def h2(args = nil, body = nil); api.out html.tag(:h2, api.data); return true; end
20
+ def h3(args = nil, body = nil); api.out html.tag(:h3, api.data); return true; end
21
+ def h4(args = nil, body = nil); api.out html.tag(:h4, api.data); return true; end
22
+ def h5(args = nil, body = nil); api.out html.tag(:h5, api.data); return true; end
23
+ def h6(args = nil, body = nil); api.out html.tag(:h6, api.data); return true; end
21
24
 
22
25
  def alpha_columns(args = nil, body = nil)
23
26
  n = api.args.first.to_i # FIXME: what if it's missing?
@@ -71,7 +74,7 @@ def figure(args = nil, body = nil)
71
74
  api.optional_blank_line
72
75
  end
73
76
 
74
- def chapter(args = nil, body = nil)
77
+ def xchapterN(args = nil, body = nil)
75
78
  @chapter = api.args.first.to_i
76
79
  @sec = @sec2 = 0
77
80
  title = api.data.split(" ",2)[1]
@@ -81,13 +84,12 @@ def chapter(args = nil, body = nil)
81
84
  api.out "<title>#{@chapter}. #{title}</title>"
82
85
  api.out <<-HTML
83
86
  <h2>Chapter #{@chapter}</h2>
84
- <h1>#{title}</h1>
85
-
87
+ <h1>#{title}</h1>\n
86
88
  HTML
87
89
  api.optional_blank_line
88
90
  end
89
91
 
90
- def chapterN(args = nil, body = nil)
92
+ def chapter(args = nil, body = nil)
91
93
  @chapter += 1
92
94
  @sec = @sec2 = 0
93
95
  title = api.data # .split(" ",2)[1]
@@ -98,8 +100,7 @@ def chapterN(args = nil, body = nil)
98
100
  api.out "<title>#{@chapter}. #{title}</title>"
99
101
  api.out <<-HTML
100
102
  <h2>Chapter #{@chapter}</h2>
101
- <h1>#{title}</h1>
102
-
103
+ <h1>#{title}</h1>\n
103
104
  HTML
104
105
  api.optional_blank_line
105
106
  end
@@ -115,8 +116,8 @@ def sec(args = nil, body = nil)
115
116
  api.out "<h3>#@section #{title}</h3>\n"
116
117
  api.optional_blank_line
117
118
  rescue => err
118
- api.tty "#{err}\n#{err.backtrace}"
119
- ::STDERR.puts "#{err}\n#{err.backtrace}"
119
+ api.tty "#{err}\n#{err.backtrace.join("\n")}"
120
+ ::STDERR.puts "#{err}\n#{err.backtrace.join("\n")}"
120
121
  exit
121
122
  end
122
123
 
@@ -296,22 +297,22 @@ rescue => err
296
297
  end
297
298
 
298
299
  def init_bookish
300
+ @_file_num = 0
299
301
  @toc_file = "toc.tmp"
300
302
  @toc = ::File.new(@toc_file, "w")
301
303
  @chapter = -1
302
304
  end
303
305
 
304
- ################### custom.rb
306
+ ###########
305
307
 
306
-
307
- def outdir
308
+ def outdir(args = nil, body = nil)
308
309
  @_outdir = api.args.first
309
310
  # @output = STDOUT
310
311
  @output = nil
311
312
  api.optional_blank_line
312
313
  end
313
314
 
314
- def outdir! # FIXME ?
315
+ def outdir!(args = nil, body = nil) # FIXME ?
315
316
  @_outdir = api.args.first
316
317
  raise "No output directory specified" if @_outdir.nil?
317
318
  raise "No output directory specified" if @_outdir.empty?
@@ -327,12 +328,12 @@ def _append(name)
327
328
  end
328
329
 
329
330
 
330
- def append
331
+ def append(args = nil, body = nil)
331
332
  file = api.args[0]
332
333
  _append(file)
333
334
  end
334
335
 
335
- def close_output
336
+ def close_output(args = nil, body = nil)
336
337
  return if @output == STDOUT
337
338
  @_outdir ||= "."
338
339
  @output.puts "<meta charset='UTF-8'>\n\n"
@@ -343,16 +344,19 @@ def close_output
343
344
  end
344
345
 
345
346
  def _prep_next_output(args)
346
- tag, num = args # _next_output(tag, num)
347
- @_file_num = num ? num : @_file_num + 1
348
- @_file_num = @_file_num.to_i
349
- name = "#{'%03d' % @_file_num}-#{tag}.html"
350
- api.tty "tag, num, name= #{[tag, num, name].inspect}"
351
- name
352
- end
353
-
354
- def next_output
355
- name = _prep_next_output(api.args)
347
+ *title = args # _next_output(tag, num)
348
+ title = title.join(" ")
349
+ slug = _slug(title)
350
+ api.tty "title = #{title.inspect}"
351
+ @_file_num += 1
352
+ fname = "#{'%03d' % @_file_num}-#{slug}.html"
353
+ api.tty "slug, fnum, fname= #{[slug, @_file_num, fname].inspect}"
354
+ fname
355
+ end
356
+
357
+ def next_output(args = nil, body = nil)
358
+ args ||= api.args
359
+ fname = _prep_next_output(args)
356
360
  @_outdir ||= "."
357
361
  unless @output.nil?
358
362
  @output.puts "<meta charset='UTF-8'>\n\n"
@@ -360,12 +364,12 @@ def next_output
360
364
  @parent.body = ""
361
365
  @output.close unless @output == STDOUT
362
366
  end
363
- fname = @_outdir + "/" + name
367
+ fname = @_outdir + "/" + fname
364
368
  @output = File.open(fname, "w")
365
369
  api.optional_blank_line
366
370
  end
367
371
 
368
- def output
372
+ def output(args = nil, body = nil)
369
373
  name = api.args.first
370
374
  _debug "Redirecting output to: #{name}"
371
375
  # _output(name)
@@ -378,7 +382,7 @@ def output
378
382
  @output = File.open(fname, "w") #; STDERR.puts "---- @out = #{@output.inspect}"
379
383
  end
380
384
 
381
- def columns
385
+ def columns(args = nil, body = nil)
382
386
  api.out "<table border=1><tr><td valign=top><br>\n"
383
387
  api.body.to_a.each do |line|
384
388
  if line.start_with?("##col")
@@ -392,7 +396,7 @@ def columns
392
396
  api.out "<br>\n</td></tr></table>"
393
397
  end
394
398
 
395
- def quote
399
+ def quote(args = nil, body = nil)
396
400
  api.out "<blockquote>"
397
401
  lines = api.body.to_a
398
402
  # STDERR.puts "-----------------------------------------------------"
data/plugin/pyggish.rb CHANGED
@@ -82,14 +82,26 @@ def self.pyg_finalize(code, lexer=:elixir)
82
82
  result
83
83
  end
84
84
 
85
- def fragment
85
+ def fragment(args = nil, body = nil)
86
86
  lang = api.args.empty? ? :elixir : api.args.first.to_sym # ruby or elixir
87
87
  api.args = []
88
- # TTY.puts "\n#{self.inspect}"
89
- send(lang)
88
+ lines = api.body(true) # .to_a # raw
89
+ result = send(lang, lines)
90
+ api.out result
90
91
  api.out "\n"
92
+ api.optional_blank_line
93
+ rescue => err
94
+ STDERR.puts "fragment Error: #{__method__} err = #{err}\n#{err.backtrace.join("\n")}"
91
95
  end
92
96
 
97
+ def dammit(args = nil, body = nil)
98
+ lines = api.body(true)
99
+ api.out "BODY:"
100
+ lines.each {|x| api.out x }
101
+ api.out "END BODY"
102
+ api.optional_blank_line
103
+ end
104
+
93
105
  def code # FIXME ?
94
106
  text = ""
95
107
  api.body {|line| api.out " " + line }
@@ -145,8 +157,9 @@ def self.pyg_finalize(code, lexer=:elixir)
145
157
  text
146
158
  end
147
159
 
148
- def ruby
160
+ def xruby
149
161
  file = api.args.first
162
+ code = nil
150
163
  if file.nil?
151
164
  code = " # Ruby code\n\n"
152
165
  api.body {|line| code << " " + line + "\n" }
@@ -158,15 +171,76 @@ def self.pyg_finalize(code, lexer=:elixir)
158
171
  api.out html
159
172
  end
160
173
 
161
- def elixir
174
+ def xelixir
162
175
  file = api.args.first
176
+ code = nil
163
177
  if file.nil?
164
178
  code = ""
165
179
  api.body {|line| code << " " + line + "\n" }
166
180
  else
167
181
  code = ::File.read(file)
168
182
  end
169
-
170
183
  html = format_elixir(code)
171
184
  api.out html
185
+ end
186
+
187
+ def ruby(lines)
188
+ theme = :Github # default
189
+ source = lines.join("\n")
190
+ formatter = Rouge::Formatters::HTML.new
191
+ lexer = Rouge::Lexers::Ruby.new
192
+ body = formatter.format(lexer.lex(source))
193
+
194
+ # css = Rouge::Themes.const_get(theme.to_s).render(scope: '.highlight')
195
+ # added = ".highlight { font-family: courier; white-space: pre }"
196
+
197
+ result = <<~HTML
198
+ <div class="highlight">
199
+ #{body}
200
+ </div>
201
+ <br>
202
+ HTML
203
+ return result
204
+
205
+ iheight = lines.size * 25
206
+ api.out <<~HTML
207
+ <center>
208
+ <iframe width=90% height=#{iheight} src='#{File.basename(html_file)}'></iframe>
209
+ </center>
210
+ <br>
211
+ HTML
212
+ rescue => err
213
+ STDERR.puts "Error: #{__method__} err = #{err}\n#{err.backtrace.join("\n")}"
172
214
  end
215
+
216
+
217
+ def elixir(lines)
218
+ theme = :Github # default
219
+ source = lines.join("\n")
220
+ formatter = Rouge::Formatters::HTML.new
221
+ lexer = Rouge::Lexers::Elixir.new
222
+ body = formatter.format(lexer.lex(source))
223
+
224
+ # css = Rouge::Themes.const_get(theme.to_s).render(scope: '.highlight')
225
+ # added = ".highlight { font-family: courier; white-space: pre }"
226
+
227
+ result = <<~HTML
228
+ <div class="highlight">
229
+ #{body}
230
+ </div>
231
+ <br>
232
+ HTML
233
+ return result
234
+
235
+ iheight = lines.size * 25
236
+ api.out <<~HTML
237
+ <center>
238
+ <iframe width=90% height=#{iheight} src='#{File.basename(html_file)}'></iframe>
239
+ </center>
240
+ <br>
241
+ HTML
242
+ rescue => err
243
+ STDERR.puts "Error: #{__method__} err = #{err}\n#{err.backtrace}"
244
+ end
245
+
246
+
data/test/unit/html.rb CHANGED
@@ -9,29 +9,27 @@ class TestingLivetext < MiniTest::Test
9
9
  # Same is probably true of the methods that are testing them.
10
10
 
11
11
  def test_wrapped
12
- cdata = "nothing much"
13
- assert_equal wrapped(cdata, :b), "<b>#{cdata}</b>"
14
- assert_equal wrapped(cdata, :b, :i), "<b><i>#{cdata}</i></b>"
15
-
16
- assert_equal wrapped(cdata, :table, :tr, :td),
17
- "<table><tr><td>#{cdata}</td></tr></table>"
12
+ live = Livetext.new
13
+ html = HTML.new(live.api)
14
+ str = "nothing much"
15
+ assert_equal html.tag(:b, cdata: str), "<b>#{str}</b>"
16
+ assert_equal html.tag(:b, :i, cdata: str), "<b><i>#{str}</i></b>"
17
+
18
+ assert_equal html.tag(:table, :tr, :td, cdata: str),
19
+ "<table><tr><td>#{str}</td></tr></table>"
18
20
  end
19
21
 
20
- def test_wrapped_bang
21
- cdata = "nothing much"
22
- assert_equal wrapped!(cdata, :td, valign: :top),
23
- "<td valign='top'>#{cdata}</td>"
24
- assert_equal wrapped!(cdata, :img, src: "foo.jpg"),
25
- "<img src='foo.jpg'>#{cdata}</img>"
26
- assert_equal wrapped!(cdata, :a, style: 'text-decoration: none',
22
+ def test_wrapped_extra
23
+ live = Livetext.new
24
+ html = HTML.new(live.api)
25
+ str = "nothing much"
26
+ assert_equal html.tag(:td, cdata: str, valign: :top),
27
+ "<td valign='top'>#{str}</td>"
28
+ assert_equal html.tag(:img, cdata: str, src: "foo.jpg"),
29
+ "<img src='foo.jpg'>#{str}</img>"
30
+ assert_equal html.tag(:a, cdata: str, style: 'text-decoration: none',
27
31
  href: 'foo.com'),
28
- "<a style='text-decoration: none' href='foo.com'>#{cdata}</a>"
29
- end
30
-
31
- def xtest_wrap
32
- # bogus!
33
- wrap(:ul) { 2.times {|i| _out i } }
34
- dump # puts @body
32
+ "<a style='text-decoration: none' href='foo.com'>#{str}</a>"
35
33
  end
36
34
 
37
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: livetext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.35
4
+ version: 0.9.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-07 00:00:00.000000000 Z
11
+ date: 2023-03-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A smart text processor extensible in Ruby
14
14
  email: rubyhacker@gmail.com