livetext 0.6.7 → 0.6.8

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
  SHA1:
3
- metadata.gz: 13347ab8dd844db4d4bd6b65038c3d8a57b6c102
4
- data.tar.gz: 146caebefc11e7c98604ed238c135b084c0e35ff
3
+ metadata.gz: 941adaa3e54331bd76d20b4af2e8d34efb956f6e
4
+ data.tar.gz: 7b9f26b201ef3aa3264f1ddf3c7402ddb8e29b66
5
5
  SHA512:
6
- metadata.gz: 21b01a30d65224433e06f456354882169298f96f822aa92f556303d596393bfa9244525884cd2ebc53a2d8cda777f920d4cd04e059267d3457110fa8e20a011c
7
- data.tar.gz: d57ad1df788529d5e0748eee9b01482f9c509ca246254f672ff9315eb3b441e426e0c5e8977df2e776d9f033edc6915f301b5fb2df28dcccc77ec3fdc1d1c681
6
+ metadata.gz: b464efdb73781affec9be9b62e4d98865951a50ba61ce0657be2f476f9b878e550a4a551a24079fdd97435878c29051601d327e2f665877c3687d0e75255b5a6
7
+ data.tar.gz: f1a712645a73e293f657604a15a0dd47714dbd197a495f3da710eaa45d0850133d395e30aff64d80b08d2f79603cbead5e978daa9b7746f75b0b9e168849fbfb
data/lib/livetext.rb CHANGED
@@ -6,16 +6,9 @@ TTY = ::File.open("/dev/tty", "w")
6
6
 
7
7
  require_relative "#{Plugins}/pyggish"
8
8
 
9
- class Enumerator
10
- def remaining
11
- array = []
12
- loop { array << self.next }
13
- array
14
- end
15
- end
16
9
 
17
10
  class Livetext
18
- VERSION = "0.6.7"
11
+ VERSION = "0.6.8"
19
12
 
20
13
  Space = " "
21
14
 
@@ -36,23 +29,24 @@ class Livetext
36
29
  attr_reader :main
37
30
  end
38
31
 
39
- def self.handle_line(line)
40
- # ::TTY.puts "---- hline - #{line.inspect}"
32
+ def self.handle_line(line, sigil=".")
41
33
  nomarkup = true
42
- sigil = "."
34
+ # FIXME inefficient
43
35
  scomment = rx(sigil, Livetext::Space) # apply these in order
44
36
  sname = rx(sigil)
45
- case
46
- when line =~ scomment; handle_scomment(sigil, line)
47
- when line =~ sname; handle_sname(sigil, line)
48
- else @main._passthru(line)
37
+ if line =~ scomment
38
+ handle_scomment(line)
39
+ elsif line =~ sname
40
+ handle_sname(line)
41
+ else
42
+ @main._passthru(line)
49
43
  end
50
44
  end
51
45
 
52
46
  def self.peek_nextline
53
47
  @sources.last[0].peek
54
48
  rescue StopIteration
55
- # @sources.pop # FIXME??
49
+ @sources.pop
56
50
  nil
57
51
  end
58
52
 
@@ -62,62 +56,38 @@ class Livetext
62
56
  @sources.last[2] += 1
63
57
  line
64
58
  rescue StopIteration
65
- # @sources.pop # FIXME??
66
- # retry
59
+ @sources.pop
60
+ nil
67
61
  end
68
62
 
69
- def self.process_file(fname, &block)
70
- block ||= proc {|line| handle_line(line) }
63
+ def self.process_file(fname)
71
64
  @sources ||= []
72
65
  enum = File.readlines(fname).each
73
- @main ||= Livetext::System.new(enum)
66
+ @main ||= Livetext.new(enum)
74
67
  @sources.push [enum, fname, 0]
75
68
  loop do
76
69
  line = nextline
77
70
  break if line.nil?
78
- block.call(line) # handle_line(line)
71
+ handle_line(line)
79
72
  end
80
- # @sources.pop # FIXME ?
81
73
  end
82
74
 
83
75
  def self.grab_file(fname)
84
76
  File.read(fname)
85
77
  end
86
78
 
87
- def self.handle_file(file)
88
- fname = "<<none>>"
89
- if file.is_a? String
90
- fname = file
91
- file = File.new(fname)
92
- end
93
- source = file.each_line
94
- @main = Livetext::System.new(source)
95
- @main.file = fname
96
- @main.lnum = 0
97
-
98
- loop do
99
- line = ::Livetext.nextline
100
- ::Livetext.handle_line(line)
101
- end
102
-
103
- val = @main.finalize if @main.respond_to?(:finalize)
104
- val
105
- rescue => err
106
- STDERR.puts "handle_file: #{err}"
107
- end
108
-
109
79
  def self.rx(str, space=nil)
110
80
  Regexp.compile("^" + Regexp.escape(str) + "#{space}")
111
81
  end
112
82
 
113
- def self.handle_scomment(sigil, line)
83
+ def self.handle_scomment(line, sigil=".")
114
84
  end
115
85
 
116
86
  def self._disallowed?(name)
117
87
  Livetext::Disallowed.include?(name.to_sym)
118
88
  end
119
89
 
120
- def self._get_name(sigil, line)
90
+ def self._get_name(line, sigil=".")
121
91
  blank = line.index(" ") || -1 # line.index("\n")
122
92
  name = line[1..(blank-1)]
123
93
  abort "#{@main.where}: Name '#{name}' is not permitted" if _disallowed?(name)
@@ -128,26 +98,19 @@ class Livetext
128
98
  name
129
99
  end
130
100
 
131
- def self.handle_sname(sigil, line)
132
- name = _get_name(sigil, line)
101
+ def self.handle_sname(line, sigil=".")
102
+ name = _get_name(line, sigil=".")
133
103
  unless @main.respond_to?(name)
134
104
  raise "'#{name}' is unknown"
135
105
  return
136
106
  end
137
-
138
107
  @main.send(name)
139
-
140
108
  rescue => err
141
- STDERR.puts "ERROR on #{@main.file} line #{@main.lnum} : #{err}"
142
- # STDERR.puts " self = #{self.inspect} @main = #{@main.inspect}"
143
- # STDERR.puts " sources = #{@main.source_files.inspect}"
144
- STDERR.puts err.backtrace
145
- # STDERR.puts "--- Methods = #{(@main.methods - Object.methods).sort}\n "
109
+ STDERR.puts "ERROR on #{@sources.last[1]} line #{@sources.last[2]} : #{err}"
110
+ exit
146
111
  end
147
112
 
148
- end
149
-
150
- class Livetext::Functions # Functions will go here... user-def AND pre-def??
113
+ class Functions # Functions will go here... user-def AND pre-def??
151
114
  def date
152
115
  Time.now.strftime("%F")
153
116
  end
@@ -162,8 +125,7 @@ class Livetext::Functions # Functions will go here... user-def AND pre-def??
162
125
  end
163
126
  end
164
127
 
165
- module Livetext::Helpers
166
-
128
+ # include ::Livetext::Helpers
167
129
  def _check_existence(file)
168
130
  raise "No such file found" unless File.exist?(file)
169
131
  end
@@ -233,7 +195,7 @@ module Livetext::Helpers
233
195
  @line = ::Livetext.nextline # no chomp needed
234
196
  break if _end?(@line, sigil)
235
197
  next if _comment?(@line, sigil)
236
- lines << @line # _formatting(line) # FIXME ??
198
+ lines << @line
237
199
  end
238
200
  _optional_blank_line
239
201
  if block_given?
@@ -290,20 +252,14 @@ module Livetext::Helpers
290
252
  end
291
253
 
292
254
  def _formatting(line)
293
- line = _basic_format(line, "_", "i")
294
- line = _basic_format(line, "*", "b")
295
- line = _basic_format(line, "`", "tt")
296
- line = _handle_escapes(line, "_*`")
297
- line
298
- end
299
-
300
- def OLD_formatting(line)
301
- l2 = _formatting(line)
255
+ l2 = _basic_format(line, "_", "i")
256
+ l2 = _basic_format(l2, "*", "b")
257
+ l2 = _basic_format(l2, "`", "tt")
258
+ l2 = _handle_escapes(l2, "_*`")
302
259
  line.replace(l2)
303
- return line
304
260
  end
305
261
 
306
- def _var_substitution(line) # FIXME handle functions separately later??
262
+ def _substitution(line) # FIXME handle functions separately later??
307
263
  fobj = ::Livetext::Functions.new
308
264
  @funcs = ::Livetext::Functions.instance_methods
309
265
  @funcs.each do |func|
@@ -325,8 +281,8 @@ module Livetext::Helpers
325
281
  def _passthru(line)
326
282
  return if @_nopass
327
283
  _puts "<p>" if line == "\n" and ! @_nopara
328
- OLD_formatting(line)
329
- _var_substitution(line)
284
+ _formatting(line)
285
+ _substitution(line)
330
286
  _puts line
331
287
  end
332
288
 
@@ -338,22 +294,6 @@ module Livetext::Helpers
338
294
  @output.print *args
339
295
  end
340
296
 
341
- # def peek_next_line
342
- # @sources.last[0].peek
343
- # rescue StopIteration
344
- # @sources.pop
345
- # nil
346
- # end
347
-
348
- # def _next_line
349
- # @line = @sources.last[0].next
350
- # @sources.last[2] += 1
351
- # _debug "Line: #@lnum: #@line"
352
- # @line
353
- # rescue StopIteration
354
- # nil
355
- # end
356
-
357
297
  def _debug=(val)
358
298
  @_debug = val
359
299
  end
@@ -361,10 +301,8 @@ module Livetext::Helpers
361
301
  def _debug(*args)
362
302
  TTY.puts *args if @_debug
363
303
  end
364
- end
365
-
366
- module Livetext::Standard
367
304
 
305
+ # include ::Livetext::Standard
368
306
  def comment
369
307
  junk = _body # do nothing with contents
370
308
  end
@@ -395,12 +333,12 @@ module Livetext::Standard
395
333
  end
396
334
 
397
335
  def say
398
- str = _var_substitution(_data)
336
+ str = _substitution(_data)
399
337
  _optional_blank_line
400
338
  end
401
339
 
402
340
  def banner
403
- str = _var_substitution(_data)
341
+ str = _substitution(_data)
404
342
  n = str.length - 1
405
343
  _errout "-"*n
406
344
  _errout str
@@ -498,21 +436,16 @@ module Livetext::Standard
498
436
 
499
437
  def _include
500
438
  file = _args.first
501
- ::Livetext.process_file(file) # {|line| ::Livetext.handle_line(line) }
439
+ ::Livetext.process_file(file)
502
440
  _optional_blank_line
503
441
  end
504
442
 
505
443
  def include! # FIXME huh?
506
444
  file = _args.first
507
- # _switch_file(file)
508
- existing = File.exist?(file)
509
- return if not existing
510
- lines = ::File.readlines(file)
445
+ return unless File.exist?(file)
446
+
447
+ lines = process_file(file)
511
448
  File.delete(file)
512
- lines.each {|line| _debug " inc: #{line}" }
513
- rem = @input.remaining
514
- array = lines + rem
515
- @input = array.each # FIXME .with_index
516
449
  _optional_blank_line
517
450
  end
518
451
 
@@ -535,25 +468,6 @@ module Livetext::Standard
535
468
  _optional_blank_line
536
469
  end
537
470
 
538
- def old_mixin
539
- name = _args.first
540
- file = "#{Plugins}/" + name + ".rb"
541
- return if @_mixins.include?(file)
542
- file = "./#{name}.rb" unless File.exist?(file)
543
- raise "No such file: #{name}.rb found" unless File.exist?(file)
544
-
545
- @_mixins << file
546
- # process_file(file)
547
- main = Livetext.main
548
- m0 = main.methods.reject {|x| x.to_s[0] == "_" }
549
- self.class.class_eval(::File.read(file))
550
- m1 = main.methods.reject {|x| x.to_s[0] == "_" }
551
- $meths[file] = m1 - m0
552
- init = "init_#{name}"
553
- self.send(init) if self.respond_to? init
554
- _optional_blank_line
555
- end
556
-
557
471
  def copy
558
472
  file = _args.first
559
473
  @output.puts ::Livetext.grab_file(file)
@@ -606,17 +520,7 @@ module Livetext::Standard
606
520
  _puts "</table>"
607
521
  end
608
522
 
609
- end
610
-
611
- class Livetext
612
- METHS = (Livetext::Standard.instance_methods - Object.methods).sort
613
- end
614
-
615
-
616
- class Livetext::System # < BasicObject
617
- include ::Kernel
618
- include ::Livetext::Helpers
619
- include ::Livetext::Standard
523
+ ###### Livetext
620
524
 
621
525
  attr_accessor :file, :lnum, :source_files
622
526
 
@@ -657,6 +561,6 @@ class Livetext::System # < BasicObject
657
561
  end
658
562
 
659
563
  if $0 == __FILE__
660
- Livetext.process_file(ARGV[0] || STDIN) # {|line| Livetext.handle_line(line) }
564
+ Livetext.process_file(ARGV[0] || STDIN)
661
565
  end
662
566
 
data/test/newtest CHANGED
@@ -1,10 +1,14 @@
1
- mkdir testfiles/$1
1
+ mkdir test/testfiles/$1
2
2
 
3
3
  # actual-error.txt actual-output.txt expected-error.txt expected-output.txt source.ltx
4
4
 
5
- cd testfiles/$1
5
+ cd test/testfiles/$1
6
6
 
7
7
  touch expected-output.txt expected-error.txt
8
8
 
9
- vi -O source.ltx exp expected-output.txt expected-error.txt
9
+ vi source.ltx
10
+
11
+ livetext source.ltx >expected-output.txt 2>expected-error.txt
12
+
13
+ vi -O source.ltx expected-output.txt expected-error.txt
10
14
 
data/test/test.rb CHANGED
@@ -38,6 +38,9 @@ class TestingLiveText < MiniTest::Test
38
38
  def test_comments_ignored_1; external_files end
39
39
  def test_block_comment; external_files end
40
40
 
41
+ def test_error_line_num; external_files end
42
+ def test_error_inc_line_num; external_files end
43
+
41
44
  def test_simple_vars; external_files end
42
45
  def test_more_complex_vars; external_files end
43
46
 
@@ -1,4 +1,5 @@
1
1
  Here I am
2
+ .debug
2
3
  trying to
3
4
  include
4
5
  .include simplefile.inc
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: livetext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.7
4
+ version: 0.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
@@ -102,9 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  requirements: []
104
104
  rubyforge_project:
105
- rubygems_version: 2.4.2
105
+ rubygems_version: 2.2.2
106
106
  signing_key:
107
107
  specification_version: 4
108
108
  summary: A smart processor for text
109
109
  test_files: []
110
- has_rdoc: