livetext 0.6.8 → 0.6.9

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: 941adaa3e54331bd76d20b4af2e8d34efb956f6e
4
- data.tar.gz: 7b9f26b201ef3aa3264f1ddf3c7402ddb8e29b66
3
+ metadata.gz: 6e46bad5eb2f6ef4b055c2f2a0b5b86582cc54f6
4
+ data.tar.gz: 150f82d63567a4199e8cdba23c57bc14c589486e
5
5
  SHA512:
6
- metadata.gz: b464efdb73781affec9be9b62e4d98865951a50ba61ce0657be2f476f9b878e550a4a551a24079fdd97435878c29051601d327e2f665877c3687d0e75255b5a6
7
- data.tar.gz: f1a712645a73e293f657604a15a0dd47714dbd197a495f3da710eaa45d0850133d395e30aff64d80b08d2f79603cbead5e978daa9b7746f75b0b9e168849fbfb
6
+ metadata.gz: 495ff531811abbdae1c034f49584a7074505f644edeb18d12d1c33cf3c1d05ff9b47bd0e3f3f38cb569c66a41803a192fc646420c922e41ebc3a879d36a30027
7
+ data.tar.gz: 88d0f3742a2585ad1eb291cdb64491262ffdd943fb8068361236f97db3b63df87f8375b1dbabc6fcb900ea13928313d62b7b27c90fd066a7aaf7e89eacc69b4d
data/bin/livetext CHANGED
@@ -5,7 +5,8 @@ require_relative '../lib/livetext'
5
5
  def handle_ltx(src)
6
6
  abort "Unknown file extension" unless src =~ /.ltx$/
7
7
 
8
- Livetext.process_file(src)
8
+ x = Livetext.new
9
+ x.process_file(src)
9
10
  end
10
11
 
11
12
  # Main
data/dsl/bookish.rb CHANGED
@@ -128,6 +128,27 @@ def subsec
128
128
  _puts "<h3>#@subsec #{@_data}</h3>\n"
129
129
  end
130
130
 
131
+ def table2
132
+ title = _data
133
+ wide = "90"
134
+ extra = _args[2]
135
+ delim = " :: "
136
+ _puts "<br><center><table border=1 width=#{wide}% cellpadding=5>"
137
+ lines = _body
138
+ lines.map! {|line| _formatting(line) }
139
+
140
+ lines.each do |line|
141
+ cells = line.split(delim)
142
+ percent = (100/cells.size.to_f).round
143
+ _puts "<tr>"
144
+ cells.each {|cell| _puts " <td width=#{percent}% #{extra}>#{cell}</td>" }
145
+ _puts "</tr>"
146
+ end
147
+ _puts "</table></center><br><br>"
148
+
149
+ _optional_blank_line
150
+ end
151
+
131
152
  def table
132
153
  @table_num ||= 0
133
154
  @table_num += 1
data/dsl/pyggish.rb CHANGED
@@ -164,7 +164,7 @@ def elixir
164
164
  end
165
165
 
166
166
  def fragment
167
- # debug
167
+ debug
168
168
  lexer = @_args.empty? ? :elixir : @_args.first.to_sym # ruby or elixir
169
169
  _debug "-- fragment: lexer = #{lexer.inspect}"
170
170
  code = ""
data/lib/livetext.rb CHANGED
@@ -8,7 +8,7 @@ require_relative "#{Plugins}/pyggish"
8
8
 
9
9
 
10
10
  class Livetext
11
- VERSION = "0.6.8"
11
+ VERSION = "0.6.9"
12
12
 
13
13
  Space = " "
14
14
 
@@ -25,11 +25,17 @@ class Livetext
25
25
  :enum_for, :pretty_inspect, :==, :equal?, :!, :!=, :instance_eval,
26
26
  :instance_exec, :__send__, :__id__, :__binding__]
27
27
 
28
- class << self
29
- attr_reader :main
28
+ class Functions # Functions will go here... user-def AND pre-def??
29
+ def date
30
+ Time.now.strftime("%F")
31
+ end
32
+
33
+ def time
34
+ Time.now.strftime("%F")
35
+ end
30
36
  end
31
37
 
32
- def self.handle_line(line, sigil=".")
38
+ def handle_line(line, sigil=".")
33
39
  nomarkup = true
34
40
  # FIXME inefficient
35
41
  scomment = rx(sigil, Livetext::Space) # apply these in order
@@ -39,18 +45,18 @@ class Livetext
39
45
  elsif line =~ sname
40
46
  handle_sname(line)
41
47
  else
42
- @main._passthru(line)
48
+ _passthru(line)
43
49
  end
44
50
  end
45
51
 
46
- def self.peek_nextline
52
+ def peek_nextline
47
53
  @sources.last[0].peek
48
54
  rescue StopIteration
49
55
  @sources.pop
50
56
  nil
51
57
  end
52
58
 
53
- def self.nextline
59
+ def nextline
54
60
  return nil if @sources.empty?
55
61
  line = @sources.last[0].next
56
62
  @sources.last[2] += 1
@@ -60,10 +66,9 @@ class Livetext
60
66
  nil
61
67
  end
62
68
 
63
- def self.process_file(fname)
64
- @sources ||= []
69
+ def process_file(fname)
65
70
  enum = File.readlines(fname).each
66
- @main ||= Livetext.new(enum)
71
+ _check_existence(fname, "No such file '#{fname}' to process")
67
72
  @sources.push [enum, fname, 0]
68
73
  loop do
69
74
  line = nextline
@@ -72,78 +77,58 @@ class Livetext
72
77
  end
73
78
  end
74
79
 
75
- def self.grab_file(fname)
80
+ def grab_file(fname)
76
81
  File.read(fname)
77
82
  end
78
83
 
79
- def self.rx(str, space=nil)
84
+ def rx(str, space=nil)
80
85
  Regexp.compile("^" + Regexp.escape(str) + "#{space}")
81
86
  end
82
87
 
83
- def self.handle_scomment(line, sigil=".")
88
+ def handle_scomment(line, sigil=".")
84
89
  end
85
90
 
86
- def self._disallowed?(name)
91
+ def _disallowed?(name)
87
92
  Livetext::Disallowed.include?(name.to_sym)
88
93
  end
89
94
 
90
- def self._get_name(line, sigil=".")
91
- blank = line.index(" ") || -1 # line.index("\n")
92
- name = line[1..(blank-1)]
93
- abort "#{@main.where}: Name '#{name}' is not permitted" if _disallowed?(name)
94
- @main._data = line[(blank+1)..-1]
95
+ def _get_name(line, sigil=".")
96
+ name, @_data = line.split(" ", 2)
97
+ name = name[1..-1] # chop off sigil
98
+ @_args = @_data.split
99
+ _error! "Name '#{name}' is not permitted" if _disallowed?(name)
95
100
  name = "_def" if name == "def"
96
101
  name = "_include" if name == "include"
97
- abort "#{@main.where}: mismatched 'end'" if name == "end"
102
+ _error! "Mismatched 'end'" if name == "end"
98
103
  name
99
104
  end
100
105
 
101
- def self.handle_sname(line, sigil=".")
106
+ def handle_sname(line, sigil=".")
102
107
  name = _get_name(line, sigil=".")
103
- unless @main.respond_to?(name)
104
- raise "'#{name}' is unknown"
108
+ unless self.respond_to?(name)
109
+ _error! "Name '#{name}' is unknown"
105
110
  return
106
111
  end
107
- @main.send(name)
112
+ self.send(name)
108
113
  rescue => err
109
- STDERR.puts "ERROR on #{@sources.last[1]} line #{@sources.last[2]} : #{err}"
110
- exit
114
+ _error!(err)
111
115
  end
112
116
 
113
- class Functions # Functions will go here... user-def AND pre-def??
114
- def date
115
- Time.now.strftime("%F")
116
- end
117
-
118
- def time
119
- Time.now.strftime("%F")
120
- end
121
-
122
- def basename
123
- file = ::Livetext.main.file
124
- ::File.basename(file, ".*")
117
+ # include ::Livetext::Helpers
118
+ def _error!(err, abort=true, trace=false)
119
+ STDERR.puts "Error: #{err} (at #{@sources.last[1]} line #{@sources.last[2]})"
120
+ STDERR.puts err.backtrace if trace
121
+ exit if abort
125
122
  end
126
- end
127
123
 
128
- # include ::Livetext::Helpers
129
- def _check_existence(file)
130
- raise "No such file found" unless File.exist?(file)
124
+ def _check_existence(file, msg)
125
+ _error! msg unless File.exist?(file)
131
126
  end
132
127
 
133
128
  def _source
134
129
  @input
135
130
  end
136
131
 
137
- def _data=(str)
138
- str ||= ""
139
- @_data = str
140
- @_args = str.split
141
- end
142
-
143
- def _data
144
- @_data
145
- end
146
-
147
132
  def _args
148
133
  if block_given?
149
134
  @_args.each {|arg| yield arg }
@@ -153,7 +138,7 @@ end
153
138
  end
154
139
 
155
140
  def _optional_blank_line
156
- @line = ::Livetext.nextline if ::Livetext.peek_nextline =~ /^ *$/
141
+ @line = nextline if peek_nextline =~ /^ *$/
157
142
  end
158
143
 
159
144
  def _comment?(str, sigil=".")
@@ -177,7 +162,7 @@ end
177
162
  def _raw_body(tag = "__EOF__", sigil = ".")
178
163
  lines = []
179
164
  loop do
180
- @line = ::Livetext.nextline
165
+ @line = nextline
181
166
  break if @line.chomp.strip == tag
182
167
  lines << @line
183
168
  end
@@ -192,7 +177,7 @@ end
192
177
  def _body(sigil=".")
193
178
  lines = []
194
179
  loop do
195
- @line = ::Livetext.nextline # no chomp needed
180
+ @line = nextline
196
181
  break if _end?(@line, sigil)
197
182
  next if _comment?(@line, sigil)
198
183
  lines << @line
@@ -303,33 +288,35 @@ end
303
288
  end
304
289
 
305
290
  # include ::Livetext::Standard
291
+
306
292
  def comment
307
293
  junk = _body # do nothing with contents
308
294
  end
309
295
 
310
296
  def shell
311
- cmd = _data
297
+ cmd = @_data
312
298
  _errout("Running: #{cmd}")
313
299
  system(cmd)
314
300
  end
315
301
 
316
302
  def func
317
- fname = @_args[0] # FIXME: don't permit 'initialize' (others?)
303
+ funcname = @_args[0]
304
+ _error! "Illegal name '#{funcname}'" if _disallowed?(funcname)
318
305
  func_def = <<-EOS
319
- def #{fname}
306
+ def #{funcname}
320
307
  #{_body!}
321
308
  end
322
309
  EOS
323
- ::Livetext::Functions.class_eval func_def
310
+ Livetext::Functions.class_eval func_def
324
311
  end
325
312
 
326
313
  def shell!
327
- cmd = _data
314
+ cmd = @_data
328
315
  system(cmd)
329
316
  end
330
317
 
331
318
  def errout
332
- TTY.puts _data
319
+ TTY.puts @_data
333
320
  end
334
321
 
335
322
  def say
@@ -410,13 +397,14 @@ end
410
397
  end
411
398
 
412
399
  def _def
413
- name = _args[0]
400
+ name = @_args[0]
414
401
  str = "def #{name}\n"
402
+ raise "Illegal name '#{name}'" if _disallowed?(name)
415
403
  str += _body!
416
404
  str += "end\n"
417
405
  eval str
418
406
  rescue => err
419
- STDERR.puts "Syntax error in definition:\n#{err}\n#$!"
407
+ _error!(err)
420
408
  end
421
409
 
422
410
  def nopass
@@ -424,7 +412,7 @@ end
424
412
  end
425
413
 
426
414
  def set
427
- assigns = _data.chomp.split(/, */)
415
+ assigns = @_data.chomp.split(/, */)
428
416
  assigns.each do |a|
429
417
  var, val = a.split("=")
430
418
  val = val[1..-2] if val[0] == ?" and val[-1] == ?"
@@ -435,13 +423,14 @@ end
435
423
  end
436
424
 
437
425
  def _include
438
- file = _args.first
439
- ::Livetext.process_file(file)
426
+ file = @_args.first
427
+ _check_existence(file, "No such include file '#{file}'")
428
+ process_file(file)
440
429
  _optional_blank_line
441
430
  end
442
431
 
443
432
  def include! # FIXME huh?
444
- file = _args.first
433
+ file = @_args.first
445
434
  return unless File.exist?(file)
446
435
 
447
436
  lines = process_file(file)
@@ -450,32 +439,33 @@ end
450
439
  end
451
440
 
452
441
  def mixin
453
- name = _args.first # Expect a module name
442
+ name = @_args.first # Expect a module name
454
443
  file = "#{Plugins}/" + name.downcase + ".rb"
455
444
  return if @_mixins.include?(name)
456
445
  file = "./#{name}.rb" unless File.exist?(file)
457
- _check_existence(file)
446
+ _check_existence(file, "No such mixin '#{name}'")
458
447
 
459
448
  @_mixins << name
460
- meths = ::Livetext.grab_file(file)
449
+ meths = grab_file(file)
461
450
  modname = name.gsub("/","_").capitalize
462
451
  string = "module ::#{modname}\n#{meths}\nend"
463
452
  eval(string)
464
453
  newmod = Object.const_get("::" + modname)
465
- Livetext.main.extend(newmod)
454
+ self.extend(newmod)
466
455
  init = "init_#{name}"
467
456
  self.send(init) if self.respond_to? init
468
457
  _optional_blank_line
469
458
  end
470
459
 
471
460
  def copy
472
- file = _args.first
473
- @output.puts ::Livetext.grab_file(file)
461
+ file = @_args.first
462
+ _check_existence(file, "No such file '#{file}' to copy")
463
+ @output.puts grab_file(file)
474
464
  _optional_blank_line
475
465
  end
476
466
 
477
467
  def r
478
- _puts _data # No processing at all
468
+ _puts @_data # No processing at all
479
469
  end
480
470
 
481
471
  def raw
@@ -484,7 +474,7 @@ end
484
474
  end
485
475
 
486
476
  def debug
487
- arg = _args.first
477
+ arg = @_args.first
488
478
  self._debug = true
489
479
  self._debug = false if arg == "off"
490
480
  end
@@ -495,7 +485,7 @@ end
495
485
 
496
486
  def heading
497
487
  _print "<center><font size=+1><b>"
498
- _print _data
488
+ _print @_data
499
489
  _print "</b></font></center>"
500
490
  end
501
491
 
@@ -530,6 +520,7 @@ end
530
520
  @vars = {}
531
521
  @_mixins = []
532
522
  @source_files = []
523
+ @sources = []
533
524
  @_outdir = "."
534
525
  @_file_num = 0
535
526
  @_nopass = false
@@ -538,10 +529,6 @@ end
538
529
  @lnum = 0
539
530
  end
540
531
 
541
- def where
542
- "Line #@lnum of #@file"
543
- end
544
-
545
532
  # def method_missing(name, *args)
546
533
  # ::TTY.puts "MM: #{name}"
547
534
  # name = "_def" if name.to_s == "def"
@@ -561,6 +548,7 @@ end
561
548
  end
562
549
 
563
550
  if $0 == __FILE__
564
- Livetext.process_file(ARGV[0] || STDIN)
551
+ x = Livetext.new
552
+ x.process_file(ARGV[0] || STDIN)
565
553
  end
566
554
 
data/test/test.rb CHANGED
@@ -40,6 +40,10 @@ class TestingLiveText < MiniTest::Test
40
40
 
41
41
  def test_error_line_num; external_files end
42
42
  def test_error_inc_line_num; external_files end
43
+ def test_error_invalid_name; external_files end
44
+ def test_error_no_such_mixin; external_files end
45
+ def test_error_no_such_inc; external_files end
46
+ def test_error_no_such_copy; external_files end
43
47
 
44
48
  def test_simple_vars; external_files end
45
49
  def test_more_complex_vars; external_files 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.6.8
4
+ version: 0.6.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-13 00:00:00.000000000 Z
11
+ date: 2017-03-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A smart text processor extensible in Ruby
14
14
  email: rubyhacker@gmail.com
@@ -102,8 +102,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  requirements: []
104
104
  rubyforge_project:
105
- rubygems_version: 2.2.2
105
+ rubygems_version: 2.4.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: