livetext 0.8.72 → 0.8.73

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: 1bedb942f052436ccaec81e8f14ac61e4dacce9d7911b4bb3ee3c63a76a5e680
4
- data.tar.gz: 39f7227e5e9f06a3be455b0f4cc0f64573b751fa0893912a9cf81edbca2d6a9d
3
+ metadata.gz: 11a401c968f4dc90a9f9ba1fa0ef1afd8ef678f4067f55fb7830d092d8d44856
4
+ data.tar.gz: 82d4dee17fd2c7cbfc441c1fb0626e94ae382b028a50a6feb3c40219be0046bb
5
5
  SHA512:
6
- metadata.gz: 7ea613b9204fdc8f8190540a51e023bd26ec26e3bee675c6ab48a597a408a3e0b7769e2b703a10095cb2bf9909e7cf30fcb261b3d8368641f1128562ad1089b2
7
- data.tar.gz: 8cdf9980c22d8bfead5853fe7b3e8f849826f2c1b6c798ff93d652489f61bb4ef03d65ddab179b8941542d5fe3a857667f62c2477a0529671219dbf8945806ae
6
+ metadata.gz: 8756eb6c73ba416da0674a255ef0106eed222a1b8dabb6aa4c867a2e1c3a085d919bf7b4984aa404a4a5fa4e80f070467fadbac2a5604f28e8b17166c9b781c2
7
+ data.tar.gz: c846b970b0af22e0160c8503366969dccac7e195177e958ee86cf3384f8b87f787511f507e1a85ad4198d21bb57ba7bdfd72c0858f91f4021c195f3f17f2b168
@@ -1,4 +1,5 @@
1
1
  class FormatLine
2
+
2
3
  EOL = :eol
3
4
  Alpha = /[a-z]/
4
5
  Alpha2 = /[a-z0-9_]/
@@ -49,8 +50,8 @@ class FormatLine
49
50
  self.send("func_" + name.to_s, param)
50
51
  else
51
52
  fobj = ::Livetext::Functions.new
52
- ::Livetext::Functions.param = param # is this screwed up???
53
- ::Livetext::Functions.context = @context # is this screwed up???
53
+ ::Livetext::Functions.param = param # is this
54
+ ::Livetext::Functions.context = @context # screwed up???
54
55
  fobj.send(name)
55
56
  end
56
57
  end
@@ -65,6 +66,9 @@ class FormatLine
65
66
  @fname, @param = "", ""
66
67
  end
67
68
 
69
+ # FIXME Much of this should be done via CSS
70
+ # FIXME In particular, strike is deprecated.
71
+
68
72
  def bold
69
73
  d0, d1 = SimpleFormats[:b]
70
74
  @buffer << "#{d0}#@substr#{d1}"
@@ -98,10 +102,11 @@ class FormatLine
98
102
  @fname = ""
99
103
  @vname = ""
100
104
  @param = ""
105
+
106
+ # FIXME - refactor, generalize, clarify
101
107
 
102
108
  loop do # starting state
103
109
  char = peek
104
- # puts "char = #{char.inspect}"
105
110
  case char
106
111
  when "\\"
107
112
  char = skip
@@ -31,11 +31,6 @@ class Livetext::Functions # Functions will go here... user-def AND pre-def??
31
31
  "<br>"*n
32
32
  end
33
33
 
34
- # def asset
35
- # param = self.class.param
36
- # # FIXME how should this work?
37
- # end
38
-
39
34
  def yt
40
35
  param = self.class.param
41
36
  "https://www.youtube.com/watch?v=#{param}"
@@ -1,19 +1,17 @@
1
1
  class Livetext
2
- VERSION = "0.8.72"
2
+ VERSION = "0.8.73"
3
3
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
4
4
  end
5
5
 
6
- $Livetext = Livetext
7
-
8
6
  require 'fileutils'
9
7
 
10
-
11
8
  $: << Livetext::Path
12
9
 
13
10
  require 'functions'
14
11
  require 'userapi'
15
12
  require 'standard'
16
13
  require 'formatline'
14
+ require 'processor'
17
15
 
18
16
  Plugins = File.expand_path(File.join(File.dirname(__FILE__), "../plugin"))
19
17
 
@@ -26,81 +24,13 @@ class Livetext
26
24
  attr_accessor :no_puts
27
25
  attr_accessor :body
28
26
 
27
+ # FIXME - phase out stupid 'parameters' method
28
+
29
29
  class << self
30
30
  attr_accessor :parameters # from outside world (process_text)
31
31
  attr_accessor :output # both bad solutions?
32
32
  end
33
33
 
34
- class Processor
35
- include Livetext::Standard
36
- include Livetext::UserAPI
37
-
38
- Disallowed = [:nil?, :===, :=~, :!~, :eql?, :hash, :<=>,
39
- :class, :singleton_class, :clone, :dup, :taint, :tainted?,
40
- :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?,
41
- :to_s, :inspect, :methods, :singleton_methods, :protected_methods,
42
- :private_methods, :public_methods, :instance_variables,
43
- :instance_variable_get, :instance_variable_set,
44
- :instance_variable_defined?, :remove_instance_variable,
45
- :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send,
46
- :respond_to?, :extend, :display, :method, :public_method,
47
- :singleton_method, :define_singleton_method, :object_id, :to_enum,
48
- :enum_for, :pretty_inspect, :==, :equal?, :!, :!=, :instance_eval,
49
- :instance_exec, :__send__, :__id__, :__binding__]
50
-
51
- def initialize(parent, output = nil)
52
- @parent = parent
53
- @_nopass = false
54
- @_nopara = false
55
- # Meh?
56
- @output = ::Livetext.output = (output || File.open("/dev/null", "w"))
57
- @sources = []
58
- end
59
-
60
- def output=(io)
61
- @output = io
62
- end
63
-
64
- def _error!(err, abort=true, trace=false)
65
- where = @sources.last || @save_location
66
- STDERR.puts "Error: #{err} (at #{where[1]} line #{where[2]})"
67
- STDERR.puts err.backtrace if trace && err.respond_to?(:backtrace)
68
- exit if abort
69
- end
70
-
71
- def _disallowed?(name)
72
- Disallowed.include?(name.to_sym)
73
- end
74
-
75
- def source(enum, file, line)
76
- @sources.push([enum, file, line])
77
- end
78
-
79
- def peek_nextline
80
- @sources.last[0].peek
81
- rescue StopIteration
82
- @sources.pop
83
- nil
84
- end
85
-
86
- def nextline
87
- return nil if @sources.empty?
88
- line = @sources.last[0].next
89
- @sources.last[2] += 1
90
- line
91
- rescue StopIteration
92
- @sources.pop
93
- nil
94
- end
95
-
96
- def grab_file(fname)
97
- File.read(fname)
98
- end
99
-
100
- end
101
-
102
- ####
103
-
104
34
  Space = " "
105
35
 
106
36
  def initialize(output = ::STDOUT)
@@ -129,27 +59,10 @@ class Livetext
129
59
  end
130
60
  end
131
61
 
132
- # def transform_line(line, context=nil)
133
- # context ||= binding
134
- # @context = context
135
- # sigil = "." # Can't change yet
136
- # nomarkup = true
137
- # # FIXME inefficient
138
- # scomment = rx(sigil, Livetext::Space) # apply these in order
139
- # sname = rx(sigil)
140
- # if line =~ scomment
141
- # handle_scomment(line)
142
- # elsif line =~ sname
143
- # handle_sname(line)
144
- # else
145
- # @body << line
146
- # end
147
- # result
148
- # end
149
-
150
62
  def process(text)
151
63
  enum = text.each_line
152
- @main.source(enum, "STDIN", 0)
64
+ front = text.match(/.*?\n/).to_a.first.chomp
65
+ @main.source(enum, "STDIN: '#{front}...'", 0)
153
66
  loop do
154
67
  line = @main.nextline
155
68
  break if line.nil?
@@ -160,7 +73,8 @@ class Livetext
160
73
  def transform(text)
161
74
  @output = ::Livetext.output
162
75
  enum = text.each_line
163
- @main.source(enum, "STDIN", 0)
76
+ front = text.match(/.*?\n/).to_a.first.chomp
77
+ @main.source(enum, "STDIN: '#{front}...'", 0)
164
78
  loop do
165
79
  line = @main.nextline
166
80
  break if line.nil?
@@ -169,11 +83,14 @@ class Livetext
169
83
  @body
170
84
  end
171
85
 
86
+ ## FIXME don't need process *and* process_text
87
+
172
88
  def process_text(text)
173
89
  text = text.split("\n") if text.is_a? String
174
90
  enum = text.each
175
91
  @backtrace = false
176
- @main.source(enum, "(text)", 0)
92
+ front = text.match(/.*?\n/).to_a.first.chomp
93
+ @main.source(enum, "(text): '#{front}...'", 0)
177
94
  loop do
178
95
  line = @main.nextline
179
96
  break if line.nil?
@@ -186,11 +103,14 @@ class Livetext
186
103
  puts err.backtrace.join("\n")
187
104
  end
188
105
 
106
+ ## FIXME process_file[!] should call process[_text]
107
+
189
108
  def process_file(fname, context=nil)
190
109
  context ||= binding
191
110
  @context = context
192
111
  raise "No such file '#{fname}' to process" unless File.exist?(fname)
193
- enum = File.readlines(fname).each
112
+ text = File.readlines(fname)
113
+ enum = text.each
194
114
  @backtrace = false
195
115
  @main.source(enum, fname, 0)
196
116
  loop do
@@ -223,10 +143,7 @@ class Livetext
223
143
  def handle_scomment(line, sigil=".")
224
144
  end
225
145
 
226
- def _get_name(line, sigil=".")
227
- name, data = line.split(" ", 2)
228
- name = name[1..-1] # chop off sigil
229
- @main.data = data
146
+ def _check_name(name)
230
147
  @main._error! "Name '#{name}' is not permitted" if @main._disallowed?(name)
231
148
  name = "_def" if name == "def"
232
149
  name = "_include" if name == "include"
@@ -234,13 +151,22 @@ class Livetext
234
151
  name
235
152
  end
236
153
 
154
+ def _get_name(line, sigil=".")
155
+ name, data = line.split(" ", 2)
156
+ name = name[1..-1] # chop off sigil
157
+ @main.data = data
158
+ name = _check_name(name)
159
+ end
160
+
237
161
  def handle_sname(line, sigil=".")
238
162
  name = _get_name(line, sigil)
239
- unless @main.respond_to?(name)
163
+ result = nil
164
+ if @main.respond_to?(name)
165
+ result = @main.send(name)
166
+ else
240
167
  @main._error! "Name '#{name}' is unknown"
241
168
  return
242
169
  end
243
- result = @main.send(name)
244
170
  result
245
171
  rescue => err
246
172
  @main._error!(err)
@@ -0,0 +1,71 @@
1
+ class Livetext
2
+
3
+ class Processor
4
+ include Livetext::Standard
5
+ include Livetext::UserAPI
6
+
7
+ Disallowed = [:nil?, :===, :=~, :!~, :eql?, :hash, :<=>,
8
+ :class, :singleton_class, :clone, :dup, :taint, :tainted?,
9
+ :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?,
10
+ :to_s, :inspect, :methods, :singleton_methods, :protected_methods,
11
+ :private_methods, :public_methods, :instance_variables,
12
+ :instance_variable_get, :instance_variable_set,
13
+ :instance_variable_defined?, :remove_instance_variable,
14
+ :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send,
15
+ :respond_to?, :extend, :display, :method, :public_method,
16
+ :singleton_method, :define_singleton_method, :object_id, :to_enum,
17
+ :enum_for, :pretty_inspect, :==, :equal?, :!, :!=, :instance_eval,
18
+ :instance_exec, :__send__, :__id__, :__binding__]
19
+
20
+ def initialize(parent, output = nil)
21
+ @parent = parent
22
+ @_nopass = false
23
+ @_nopara = false
24
+ # Meh?
25
+ @output = ::Livetext.output = (output || File.open("/dev/null", "w"))
26
+ @sources = []
27
+ end
28
+
29
+ def output=(io)
30
+ @output = io
31
+ end
32
+
33
+ def _error!(err, abort=true, trace=false)
34
+ where = @sources.last || @save_location
35
+ STDERR.puts "Error: #{err} (at #{where[1]} line #{where[2]})"
36
+ STDERR.puts err.backtrace if trace && err.respond_to?(:backtrace)
37
+ exit if abort
38
+ end
39
+
40
+ def _disallowed?(name)
41
+ Disallowed.include?(name.to_sym)
42
+ end
43
+
44
+ def source(enum, file, line)
45
+ @sources.push([enum, file, line])
46
+ end
47
+
48
+ def peek_nextline
49
+ @sources.last[0].peek
50
+ rescue StopIteration
51
+ @sources.pop
52
+ nil
53
+ end
54
+
55
+ def nextline
56
+ return nil if @sources.empty?
57
+ line = @sources.last[0].next
58
+ @sources.last[2] += 1
59
+ line
60
+ rescue StopIteration
61
+ @sources.pop
62
+ nil
63
+ end
64
+
65
+ def grab_file(fname)
66
+ File.read(fname)
67
+ end
68
+
69
+ end
70
+
71
+ end
@@ -206,18 +206,17 @@ module Livetext::Standard
206
206
  def copy
207
207
  file = @_args.first
208
208
  _check_existence(file, "No such file '#{file}' to copy")
209
- @output.puts grab_file(file)
209
+ _out grab_file(file)
210
210
  _optional_blank_line
211
211
  end
212
212
 
213
213
  def r
214
- # STDERR.puts "@_data = #{@_data.inspect}"
215
- _puts @_data # No processing at all
214
+ _out @_data # No processing at all
216
215
  end
217
216
 
218
217
  def raw
219
218
  # No processing at all (terminate with __EOF__)
220
- _puts _raw_body
219
+ _out _raw_body
221
220
  end
222
221
 
223
222
  def debug
@@ -263,57 +262,55 @@ module Livetext::Standard
263
262
  end
264
263
 
265
264
  def newpage
266
- _puts '<p style="page-break-after:always;"></p>'
267
- _puts "<p/>"
265
+ _out '<p style="page-break-after:always;"></p>'
266
+ _out "<p/>"
268
267
  end
269
268
 
270
269
  def invoke(str)
271
270
  end
272
271
 
273
272
  def mono
274
- _puts "<pre>"
275
- _body(true) {|line| puts line }
276
- _puts "</pre>"
273
+ _out "<pre>"
274
+ _body(true) {|line| _out line }
275
+ _out "</pre>"
277
276
  _optional_blank_line
278
277
  end
279
278
 
280
279
  def dlist
281
280
  delim = _args.first
282
- _puts "<dl>"
281
+ _out "<dl>"
283
282
  _body do |line|
284
283
  line = _formatting(line)
285
284
  term, defn = line.split(delim)
286
- _puts "<dt>#{term}</dt>"
287
- _puts "<dd>#{defn}</dd>"
285
+ _out "<dt>#{term}</dt>"
286
+ _out "<dd>#{defn}</dd>"
288
287
  end
289
- _puts "</dl>"
288
+ _out "</dl>"
290
289
  end
291
290
 
292
291
  def old_dlist
293
292
  delim = _args.first
294
- _puts "<table>"
293
+ _out "<table>"
295
294
  _body do |line|
296
295
  line = _formatting(line)
297
296
  term, defn = line.split(delim)
298
- _puts "<tr>"
299
- _puts "<td width=3%><td width=10%>#{term}</td><td>#{defn}</td>"
300
- _puts "</tr>"
297
+ _out "<tr>"
298
+ _out "<td width=3%><td width=10%>#{term}</td><td>#{defn}</td>"
299
+ _out "</tr>"
301
300
  end
302
- _puts "</table>"
301
+ _out "</table>"
303
302
  end
304
303
 
305
304
  def link
306
305
  url = _args.first
307
306
  text = _args[2..-1].join(" ")
308
- _puts "<a href='#{url}'>#{text}</a>"
307
+ _out "<a href='#{url}'>#{text}</a>"
309
308
  end
310
309
 
311
310
  def xtable # Borrowed from bookish - FIXME
312
- # @table_num ||= 0
313
- # @table_num += 1
314
311
  title = @_data
315
312
  delim = " :: "
316
- _puts "<br><center><table border=1 width=90% cellpadding=5>"
313
+ _out "<br><center><table border=1 width=90% cellpadding=5>"
317
314
  lines = _body(true)
318
315
  maxw = nil
319
316
  lines.each do |line|
@@ -330,23 +327,20 @@ module Livetext::Standard
330
327
 
331
328
  lines.each do |line|
332
329
  cells = line.split(delim)
333
- _puts "<tr>"
330
+ _out "<tr>"
334
331
  cells.each.with_index do |cell, i|
335
- _puts " <td valign=top>#{cell}</td>"
332
+ _out " <td valign=top>#{cell}</td>"
336
333
  end
337
- _puts "</tr>"
334
+ _out "</tr>"
338
335
  end
339
- _puts "</table></center>"
340
- # @toc << "#{_nbsp(8)}<b>Table #@chapter.#@table_num</b> #{title}<br>"
341
- # _next_output(_slug("table_#{title}"))
342
- # _puts "<b>Table #@chapter.#@table_num &nbsp;&nbsp; #{title}</b></center><br>"
336
+ _out "</table></center>"
343
337
  end
344
338
 
345
339
  def br
346
340
  n = _args.first || "1"
347
341
  out = ""
348
342
  n.to_i.times { out << "<br>" }
349
- _puts out
343
+ _out out
350
344
  end
351
345
 
352
346
  end
@@ -105,9 +105,7 @@ module Livetext::UserAPI
105
105
 
106
106
  def _passthru(line, context = nil)
107
107
  return if @_nopass
108
- # p [@_nopara, line]
109
108
  _out "<p>" if line == "\n" and ! @_nopara
110
- # _out "<p>" if line == "" and ! @_nopara
111
109
  _formatting(line, context)
112
110
  _out line
113
111
  end
@@ -145,7 +145,7 @@ def ruby
145
145
 
146
146
  _process_code(code)
147
147
  html = _colorize(code, :ruby)
148
- @output.puts "\n#{html}\n "
148
+ _out "\n#{html}\n "
149
149
  end
150
150
 
151
151
  def elixir
@@ -159,7 +159,7 @@ def elixir
159
159
 
160
160
  _process_code(code)
161
161
  html = _colorize(code, :elixir)
162
- @output.puts "\n#{html}\n "
162
+ _out "\n#{html}\n "
163
163
  end
164
164
 
165
165
  def fragment
@@ -176,12 +176,12 @@ def fragment
176
176
  text ||= "ERROR IN HIGHLIGHTER"
177
177
  _debug "text = \n#{text.inspect}\n-----"
178
178
  # PygmentFix.pyg_finalize(text, lexer)
179
- @output.puts text + "\n<br>"
179
+ _out text + "\n<br>"
180
180
  end
181
181
 
182
182
  def code # FIXME ?
183
183
  text = ""
184
- _body {|line| @output.puts " " + line }
184
+ _body {|line| _out " " + line }
185
185
  end
186
186
 
187
187
  def mono
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.8.72
4
+ version: 0.8.73
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-16 00:00:00.000000000 Z
11
+ date: 2019-04-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A smart text processor extensible in Ruby
14
14
  email: rubyhacker@gmail.com
@@ -23,6 +23,7 @@ files:
23
23
  - lib/formatline.rb
24
24
  - lib/functions.rb
25
25
  - lib/livetext.rb
26
+ - lib/processor.rb
26
27
  - lib/standard.rb
27
28
  - lib/userapi.rb
28
29
  - livetext.gemspec