livetext 0.9.36 → 0.9.38

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: 2dceb322a5f44e776bab9ed9113c7c7a4adf29eff271be81a613c72a081a2d51
4
- data.tar.gz: 70576d3a39fccbe7f3285ddca930f79400b8d770ef600d043e2b3690f173ba23
3
+ metadata.gz: dd459c3fa75665b383b8056baa8af5ee9bae77a3abcaeba153b11c422b2f0418
4
+ data.tar.gz: 6f3674f4f5f5408e1b7fbffe45631ebbc0c43abbc624f1ba6ade1232e33d10f3
5
5
  SHA512:
6
- metadata.gz: 8d91e26a1721ce60ca41ff49a323df2e4ef0a365b0b4eec9b224cbef8381e48b6ab4f3c0bb63e74ada905efb101c69a33e021f521420abe56927b16a46e02091
7
- data.tar.gz: fa718856dcbb75bb4f60f49f31638041158b815335ba9df3680c2ca0b117a2584d66921e06dae30b266f3104a465f826904a797e3e1a546960d75d6dc79d9d4b
6
+ metadata.gz: 49baee92ae2d7a5ef1337ef98258e416014c954a07d5574f697def625c41e06f7cdaa297ca6cc9a88f3cb3dc4f7c58b589aab889f9bb30d67ba4bf583a52c4f7
7
+ data.tar.gz: 6bff41c9c3128a5de6a58f1e81985e35ec3563acbdc133f24427e21c86aca2b475ac0dc1da7967b6e10f92203beab44750ae2ae47bb36a164dfddc62b506c5b9
@@ -127,7 +127,7 @@ module Livetext::Helpers
127
127
  retval = @main.send(name) # , *args) # was 125
128
128
  retval
129
129
  rescue => err
130
- graceful_error(err)
130
+ graceful_error(err) # , "#{__method__}: name = #{name}")
131
131
  end
132
132
 
133
133
  def handle_dotcmd(line, indent = 0)
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,68 +74,69 @@ 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
95
95
  line = lines.next
96
96
  line = api.format(line)
97
- str = line[0] == " " ? line : wrapped(line, :li)
97
+ str = line[0] == " " ? line : html.tag(:li, line)
98
98
  api.out str
99
99
  end
100
100
  end
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(arg=nil)
121
- data = arg || api.args.join(" ")
120
+ def say(args = nil, body = nil)
121
+ data = args || api.args.join(" ")
122
122
  str = api.format(data)
123
- TTY.puts "(say) #{str}"
123
+ TTY.puts str
124
124
  api.optional_blank_line
125
125
  end
126
126
 
127
- def banner
127
+ def banner(args = nil, body = nil)
128
128
  str = api.format(api.data)
129
129
  num = str.length
130
130
  decor = "-"*num + "\n"
131
- puts decor + str + "\n" + decor
131
+ api.tty decor + str + "\n" + decor
132
+ api.optional_blank_line
132
133
  end
133
134
 
134
- def quit
135
+ def quit(args = nil, body = nil)
135
136
  @output.close
136
137
  end
137
138
 
138
- def cleanup
139
+ def cleanup(args = nil, body = nil)
139
140
  api.args.each do |item|
140
141
  cmd = ::File.directory?(item) ? "rm -f #{item}/*" : "rm #{item}"
141
142
  system(cmd)
@@ -143,7 +144,7 @@ module Livetext::Standard
143
144
  api.optional_blank_line
144
145
  end
145
146
 
146
- def dot_def
147
+ def dot_def(args = nil, body = nil)
147
148
  name = api.args[0]
148
149
  check_disallowed(name)
149
150
  # Difficult to avoid eval here
@@ -154,7 +155,7 @@ module Livetext::Standard
154
155
  api.optional_blank_line
155
156
  end
156
157
 
157
- def set
158
+ def set(args = nil, body = nil)
158
159
  line = api.args.join(" ") # data.chomp
159
160
  pairs = Livetext::ParseSet.new(line).parse
160
161
  api.setvars(pairs)
@@ -163,7 +164,7 @@ module Livetext::Standard
163
164
 
164
165
  # FIXME really these should be one method...
165
166
 
166
- def variables! # cwd, not FileDir - weird, fix later
167
+ def variables!(args = nil, body = nil) # cwd, not FileDir - weird, fix later
167
168
  prefix = api.args[0]
168
169
  file = api.args[1]
169
170
  prefix = nil if prefix == "-" # FIXME dumb hack
@@ -178,7 +179,7 @@ module Livetext::Standard
178
179
  api.optional_blank_line
179
180
  end
180
181
 
181
- def variables
182
+ def variables(args = nil, body = nil)
182
183
  prefix = api.args[0]
183
184
  file = api.args[1]
184
185
  prefix = nil if prefix == "-" # FIXME dumb hack
@@ -193,7 +194,7 @@ module Livetext::Standard
193
194
  api.optional_blank_line
194
195
  end
195
196
 
196
- def heredoc
197
+ def heredoc(args = nil, body = nil)
197
198
  var = api.args[0]
198
199
  text = api.body.join("\n")
199
200
  rhs = ""
@@ -207,7 +208,7 @@ module Livetext::Standard
207
208
  api.optional_blank_line
208
209
  end
209
210
 
210
- def seek # like include, but search upward as needed
211
+ def seek(args = nil, body = nil) # like include, but search upward as needed
211
212
  file = api.args.first
212
213
  file = search_upward(file)
213
214
  check_file_exists(file)
@@ -215,14 +216,14 @@ module Livetext::Standard
215
216
  api.optional_blank_line
216
217
  end
217
218
 
218
- def dot_include # dot command
219
+ def dot_include(args = nil, body = nil) # dot command
219
220
  file = api.expand_variables(api.args.first) # allows for variables
220
221
  check_file_exists(file)
221
222
  @parent.process_file(file)
222
223
  api.optional_blank_line
223
224
  end
224
225
 
225
- def inherit
226
+ def inherit(args = nil, body = nil)
226
227
  file = api.args.first
227
228
  upper = "../#{file}"
228
229
  got_upper, got_file = File.exist?(upper), File.exist?(file)
@@ -234,7 +235,7 @@ module Livetext::Standard
234
235
  api.optional_blank_line
235
236
  end
236
237
 
237
- def mixin
238
+ def mixin(args = nil, body = nil)
238
239
  name = api.args.first # Expect a module name
239
240
  @mixins ||= []
240
241
  return if @mixins.include?(name)
@@ -246,7 +247,7 @@ module Livetext::Standard
246
247
  api.optional_blank_line
247
248
  end
248
249
 
249
- def import
250
+ def import(args = nil, body = nil)
250
251
  name = api.args.first # Expect a module name
251
252
  @imports ||= []
252
253
  return if @imports.include?(name)
@@ -258,7 +259,7 @@ module Livetext::Standard
258
259
  api.optional_blank_line
259
260
  end
260
261
 
261
- def copy
262
+ def copy(args = nil, body = nil)
262
263
  file = api.args.first
263
264
  ok = check_file_exists(file)
264
265
 
@@ -268,87 +269,87 @@ module Livetext::Standard
268
269
  [ok, file]
269
270
  end
270
271
 
271
- def r
272
+ def r(args = nil, body = nil)
272
273
  # FIXME api.data is broken
273
274
  # api.out api.data # No processing at all
274
275
  api.out api.args.join(" ")
275
276
  api.optional_blank_line
276
277
  end
277
278
 
278
- def raw
279
+ def raw(args = nil, body = nil)
279
280
  # No processing at all (terminate with __EOF__)
280
281
  api.raw_body {|line| api.out line } # no formatting
281
282
  api.optional_blank_line
282
283
  end
283
284
 
284
- def debug
285
+ def debug(args = nil, body = nil)
285
286
  @debug = onoff(api.args.first)
286
287
  api.optional_blank_line
287
288
  end
288
289
 
289
- def passthru
290
+ def passthru(args = nil, body = nil)
290
291
  # FIXME - add check for args size? (helpers)
291
292
  @nopass = ! onoff(api.args.first)
292
293
  api.optional_blank_line
293
294
  end
294
295
 
295
- def nopass
296
+ def nopass(args = nil, body = nil)
296
297
  @nopass = true
297
298
  api.optional_blank_line
298
299
  end
299
300
 
300
- def para
301
+ def para(args = nil, body = nil)
301
302
  # FIXME - add check for args size? (helpers)
302
303
  @nopara = ! onoff(api.args.first)
303
304
  api.optional_blank_line
304
305
  end
305
306
 
306
- def nopara
307
+ def nopara(args = nil, body = nil)
307
308
  @nopara = true
308
309
  api.optional_blank_line
309
310
  end
310
311
 
311
- def heading
312
+ def heading(args = nil, body = nil)
312
313
  api.print "<center><font size=+1><b>"
313
314
  api.print api.data
314
315
  api.print "</b></font></center>"
315
316
  api.optional_blank_line
316
317
  end
317
318
 
318
- def newpage
319
+ def newpage(args = nil, body = nil)
319
320
  api.out '<p style="page-break-after:always;"></p>'
320
321
  api.out "<p/>"
321
322
  api.optional_blank_line
322
323
  end
323
324
 
324
- def mono
325
+ def mono(args = nil, body = nil)
325
326
  html.wrap ":pre" do
326
327
  api.body(true) {|line| api.out line }
327
328
  end
328
329
  api.optional_blank_line
329
330
  end
330
331
 
331
- def dlist
332
+ def dlist(args = nil, body = nil)
332
333
  delim = api.args.first
333
334
  html.wrap(:dl) do
334
335
  api.body do |line|
335
336
  line = api.format(line)
336
337
  term, defn = line.split(delim)
337
- api.out wrapped(term, :dt)
338
- api.out wrapped(defn, :dd)
338
+ api.out html.tag(:dt, term)
339
+ api.out html.tag(:dd, defn)
339
340
  end
340
341
  end
341
342
  api.optional_blank_line
342
343
  end
343
344
 
344
- def link
345
+ def link(args = nil, body = nil)
345
346
  url = api.args.first
346
347
  text = api.args[2..-1].join(" ")
347
348
  api.out "<a style='text-decoration: none' href='#{url}'>#{text}</a>"
348
349
  api.optional_blank_line
349
350
  end
350
351
 
351
- def xtable # Borrowed from bookish - FIXME
352
+ def xtable(args = nil, body = nil) # Borrowed from bookish - FIXME
352
353
  title = api.data
353
354
  delim = " :: "
354
355
  api.out "<br><center><table width=90% cellpadding=5>"
@@ -378,7 +379,7 @@ module Livetext::Standard
378
379
  api.optional_blank_line
379
380
  end
380
381
 
381
- def image
382
+ def image(args = nil, body = nil)
382
383
  name, wide, high = api.args
383
384
  geom = ""
384
385
  geom = "width=#{wide} height=#{high}" if wide || high
@@ -386,7 +387,7 @@ module Livetext::Standard
386
387
  api.optional_blank_line
387
388
  end
388
389
 
389
- def br
390
+ def br(args = nil, body = nil)
390
391
  num = api.args.first || "1"
391
392
  str = ""
392
393
  num.to_i.times { str << "<br>" }
@@ -394,7 +395,7 @@ module Livetext::Standard
394
395
  api.optional_blank_line
395
396
  end
396
397
 
397
- def reflection # strictly experimental!
398
+ def reflection(args = nil, body = nil) # strictly experimental!
398
399
  list = self.methods
399
400
  obj = Object.instance_methods
400
401
  diff = (list - obj).sort
@@ -2,5 +2,5 @@
2
2
  # Defining VERSION
3
3
 
4
4
  class Livetext
5
- VERSION = "0.9.36"
5
+ VERSION = "0.9.38"
6
6
  end
@@ -1,3 +1,32 @@
1
+ require 'fileutils'
2
+
3
+ def epub(args = nil, body = nil)
4
+ api.tty "======== Entering epub"
5
+ out = api.format(api.args[0])
6
+ src = api.args[1]
7
+ api.tty "======== epub: src = #{src}"
8
+ @cover = api.args[2]
9
+ if ::File.directory?(src)
10
+ files = ::Dir["#{src}/*"].grep /\.html$/
11
+ files = files.sort # why is this necessary now?
12
+ cmd = "cat #{files.join(' ')} >TEMP.html"
13
+ system(cmd)
14
+ else
15
+ raise "Not supported yet"
16
+ end
17
+
18
+ cmd = "ebook-convert "
19
+ cmd << "TEMP.html #{out}.epub "
20
+ cmd << "--cover #@cover " if @cover
21
+ system(cmd)
22
+
23
+ system("links -dump TEMP.html >/tmp/links.out")
24
+ str = `wc -w /tmp/links.out`
25
+ nw = str.split[0]
26
+ puts "Approx words: #{nw}"
27
+ # ::FileUtils.rm("TEMP.html")
28
+ end
29
+
1
30
  def hardbreaks(args = nil, body = nil)
2
31
  @hard = false
3
32
  @hard = true unless api.args.first == "off"
@@ -15,9 +44,12 @@ end
15
44
 
16
45
  # These are duplicated. Remove safely
17
46
 
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
47
+ def h1(args = nil, body = nil); api.out html.tag(:h1, api.data); return true; end
48
+ def h2(args = nil, body = nil); api.out html.tag(:h2, api.data); return true; end
49
+ def h3(args = nil, body = nil); api.out html.tag(:h3, api.data); return true; end
50
+ def h4(args = nil, body = nil); api.out html.tag(:h4, api.data); return true; end
51
+ def h5(args = nil, body = nil); api.out html.tag(:h5, api.data); return true; end
52
+ def h6(args = nil, body = nil); api.out html.tag(:h6, api.data); return true; end
21
53
 
22
54
  def alpha_columns(args = nil, body = nil)
23
55
  n = api.args.first.to_i # FIXME: what if it's missing?
@@ -71,7 +103,7 @@ def figure(args = nil, body = nil)
71
103
  api.optional_blank_line
72
104
  end
73
105
 
74
- def chapter(args = nil, body = nil)
106
+ def xchapterN(args = nil, body = nil)
75
107
  @chapter = api.args.first.to_i
76
108
  @sec = @sec2 = 0
77
109
  title = api.data.split(" ",2)[1]
@@ -81,13 +113,12 @@ def chapter(args = nil, body = nil)
81
113
  api.out "<title>#{@chapter}. #{title}</title>"
82
114
  api.out <<-HTML
83
115
  <h2>Chapter #{@chapter}</h2>
84
- <h1>#{title}</h1>
85
-
116
+ <h1>#{title}</h1>\n
86
117
  HTML
87
118
  api.optional_blank_line
88
119
  end
89
120
 
90
- def chapterN(args = nil, body = nil)
121
+ def chapter(args = nil, body = nil)
91
122
  @chapter += 1
92
123
  @sec = @sec2 = 0
93
124
  title = api.data # .split(" ",2)[1]
@@ -98,8 +129,7 @@ def chapterN(args = nil, body = nil)
98
129
  api.out "<title>#{@chapter}. #{title}</title>"
99
130
  api.out <<-HTML
100
131
  <h2>Chapter #{@chapter}</h2>
101
- <h1>#{title}</h1>
102
-
132
+ <h1>#{title}</h1>\n
103
133
  HTML
104
134
  api.optional_blank_line
105
135
  end
@@ -115,8 +145,8 @@ def sec(args = nil, body = nil)
115
145
  api.out "<h3>#@section #{title}</h3>\n"
116
146
  api.optional_blank_line
117
147
  rescue => err
118
- api.tty "#{err}\n#{err.backtrace}"
119
- ::STDERR.puts "#{err}\n#{err.backtrace}"
148
+ api.tty "#{err}\n#{err.backtrace.join("\n")}"
149
+ ::STDERR.puts "#{err}\n#{err.backtrace.join("\n")}"
120
150
  exit
121
151
  end
122
152
 
@@ -295,23 +325,23 @@ rescue => err
295
325
  exit
296
326
  end
297
327
 
298
- def init_bookish
328
+ def init_booktool
329
+ @_file_num = 0
299
330
  @toc_file = "toc.tmp"
300
331
  @toc = ::File.new(@toc_file, "w")
301
332
  @chapter = -1
302
333
  end
303
334
 
304
- ################### custom.rb
305
-
335
+ ###########
306
336
 
307
- def outdir
337
+ def outdir(args = nil, body = nil)
308
338
  @_outdir = api.args.first
309
339
  # @output = STDOUT
310
340
  @output = nil
311
341
  api.optional_blank_line
312
342
  end
313
343
 
314
- def outdir! # FIXME ?
344
+ def outdir!(args = nil, body = nil) # FIXME ?
315
345
  @_outdir = api.args.first
316
346
  raise "No output directory specified" if @_outdir.nil?
317
347
  raise "No output directory specified" if @_outdir.empty?
@@ -327,12 +357,12 @@ def _append(name)
327
357
  end
328
358
 
329
359
 
330
- def append
360
+ def append(args = nil, body = nil)
331
361
  file = api.args[0]
332
362
  _append(file)
333
363
  end
334
364
 
335
- def close_output
365
+ def close_output(args = nil, body = nil)
336
366
  return if @output == STDOUT
337
367
  @_outdir ||= "."
338
368
  @output.puts "<meta charset='UTF-8'>\n\n"
@@ -343,16 +373,17 @@ def close_output
343
373
  end
344
374
 
345
375
  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
376
+ *title = args # _next_output(tag, num)
377
+ title = title.join(" ")
378
+ slug = _slug(title)
379
+ @_file_num += 1
380
+ fname = "#{'%03d' % @_file_num}-#{slug}.html"
381
+ fname
352
382
  end
353
383
 
354
- def next_output
355
- name = _prep_next_output(api.args)
384
+ def next_output(args = nil, body = nil)
385
+ args ||= api.args
386
+ fname = _prep_next_output(args)
356
387
  @_outdir ||= "."
357
388
  unless @output.nil?
358
389
  @output.puts "<meta charset='UTF-8'>\n\n"
@@ -360,12 +391,12 @@ def next_output
360
391
  @parent.body = ""
361
392
  @output.close unless @output == STDOUT
362
393
  end
363
- fname = @_outdir + "/" + name
394
+ fname = @_outdir + "/" + fname
364
395
  @output = File.open(fname, "w")
365
396
  api.optional_blank_line
366
397
  end
367
398
 
368
- def output
399
+ def output(args = nil, body = nil)
369
400
  name = api.args.first
370
401
  _debug "Redirecting output to: #{name}"
371
402
  # _output(name)
@@ -378,7 +409,7 @@ def output
378
409
  @output = File.open(fname, "w") #; STDERR.puts "---- @out = #{@output.inspect}"
379
410
  end
380
411
 
381
- def columns
412
+ def columns(args = nil, body = nil)
382
413
  api.out "<table border=1><tr><td valign=top><br>\n"
383
414
  api.body.to_a.each do |line|
384
415
  if line.start_with?("##col")
@@ -392,7 +423,7 @@ def columns
392
423
  api.out "<br>\n</td></tr></table>"
393
424
  end
394
425
 
395
- def quote
426
+ def quote(args = nil, body = nil)
396
427
  api.out "<blockquote>"
397
428
  lines = api.body.to_a
398
429
  # STDERR.puts "-----------------------------------------------------"
@@ -86,7 +86,7 @@ def self.pyg_finalize(code, lexer=:elixir)
86
86
  lang = api.args.empty? ? :elixir : api.args.first.to_sym # ruby or elixir
87
87
  api.args = []
88
88
  lines = api.body(true) # .to_a # raw
89
- result = send(lang, lines)
89
+ result = send("format_#{lang}", lines)
90
90
  api.out result
91
91
  api.out "\n"
92
92
  api.optional_blank_line
@@ -94,14 +94,6 @@ def self.pyg_finalize(code, lexer=:elixir)
94
94
  STDERR.puts "fragment Error: #{__method__} err = #{err}\n#{err.backtrace.join("\n")}"
95
95
  end
96
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
-
105
97
  def code # FIXME ?
106
98
  text = ""
107
99
  api.body {|line| api.out " " + line }
@@ -138,26 +130,7 @@ end
138
130
  File.write("#{dir}/elixir.css", css)
139
131
  end
140
132
 
141
-
142
- def format_ruby(source, theme = "Github", back = "black")
143
- # theme/back not used now
144
- formatter = Rouge::Formatters::HTML.new
145
- lexer = Rouge::Lexers::Ruby.new
146
- body = formatter.format(lexer.lex(source))
147
- text = "<div class=rb_highlight>#{body}</div>"
148
- text
149
- end
150
-
151
- def format_elixir(source, theme = "Github", back = "black")
152
- # theme/back not used now
153
- formatter = Rouge::Formatters::HTML.new
154
- lexer = Rouge::Lexers::Elixir.new
155
- body = formatter.format(lexer.lex(source))
156
- text = "<div class=ex_highlight>#{body}</div>"
157
- text
158
- end
159
-
160
- def xruby
133
+ def ruby(args = nil, body = nil)
161
134
  file = api.args.first
162
135
  code = nil
163
136
  if file.nil?
@@ -171,7 +144,7 @@ end
171
144
  api.out html
172
145
  end
173
146
 
174
- def xelixir
147
+ def elixir(args = nil, body = nil)
175
148
  file = api.args.first
176
149
  code = nil
177
150
  if file.nil?
@@ -184,7 +157,29 @@ end
184
157
  api.out html
185
158
  end
186
159
 
187
- def ruby(lines)
160
+ def format_ruby(lines, theme = "Github", back = "black")
161
+ # theme/back not used now
162
+ source = lines
163
+ source = source.join("\n") if source.is_a?(Array)
164
+ formatter = Rouge::Formatters::HTML.new
165
+ lexer = Rouge::Lexers::Ruby.new
166
+ body = formatter.format(lexer.lex(source))
167
+ text = "<div class=rb_highlight>#{body}</div>"
168
+ text
169
+ end
170
+
171
+ def format_elixir(lines, theme = "Github", back = "black")
172
+ # theme/back not used now
173
+ source = lines
174
+ source = source.join("\n") if source.is_a?(Array)
175
+ formatter = Rouge::Formatters::HTML.new
176
+ lexer = Rouge::Lexers::Elixir.new
177
+ body = formatter.format(lexer.lex(source))
178
+ text = "<div class=ex_highlight>#{body}</div>"
179
+ text
180
+ end
181
+
182
+ def __ruby(lines)
188
183
  theme = :Github # default
189
184
  source = lines.join("\n")
190
185
  formatter = Rouge::Formatters::HTML.new
@@ -214,7 +209,7 @@ rescue => err
214
209
  end
215
210
 
216
211
 
217
- def elixir(lines)
212
+ def __elixir(lines)
218
213
  theme = :Github # default
219
214
  source = lines.join("\n")
220
215
  formatter = Rouge::Formatters::HTML.new
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.36
4
+ version: 0.9.38
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-08 00:00:00.000000000 Z
11
+ date: 2023-03-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A smart text processor extensible in Ruby
14
14
  email: rubyhacker@gmail.com
@@ -52,13 +52,12 @@ files:
52
52
  - lib/livetext/userapi.rb
53
53
  - lib/livetext/version.rb
54
54
  - livetext.gemspec
55
- - plugin/bookish.rb
55
+ - plugin/booktool.rb
56
56
  - plugin/bootstrap_menu.rb
57
- - plugin/calibre.rb
57
+ - plugin/codetool.rb
58
58
  - plugin/livemagick.rb
59
59
  - plugin/markdown.rb
60
60
  - plugin/misc/navbar.rb
61
- - plugin/pyggish.rb
62
61
  - plugin/tutorial.rb
63
62
  - test/all.rb
64
63
  - test/extra/README.txt
data/plugin/calibre.rb DELETED
@@ -1,26 +0,0 @@
1
- require 'fileutils'
2
-
3
- def epub!(args = nil, body = nil)
4
- out = api.format(api.args[0])
5
- src = api.args[1]
6
- @cover = api.args[2]
7
- if ::File.directory?(src)
8
- files = ::Dir["#{src}/*"].grep /\.html$/
9
- files = files.sort # why is this necessary now?
10
- cmd = "cat #{files.join(' ')} >TEMP.html"
11
- system(cmd)
12
- else
13
- raise "Not supported yet"
14
- end
15
-
16
- cmd = "ebook-convert "
17
- cmd << "TEMP.html #{out}.epub "
18
- cmd << "--cover #@cover " if @cover
19
- system(cmd)
20
-
21
- system("links -dump TEMP.html >/tmp/links.out")
22
- str = `wc -w /tmp/links.out`
23
- nw = str.split[0]
24
- puts "Approx words: #{nw}"
25
- # ::FileUtils.rm("TEMP.html")
26
- end