livetext 0.9.44 → 0.9.45

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: 77c132b3f86809adfbbed149564227c061911a51bc57124fdd17ed9fb67bae55
4
- data.tar.gz: dc92358a343e8096f7e982005585fa9633d8860f6fe569e0db61bc40a764bd73
3
+ metadata.gz: 2b37a1a3e7407f6425178e5013641f1df43ec03a4aeac69936bfa1b4b000a9d5
4
+ data.tar.gz: e7ecf71a35779e59c21d2e013996cfcaa21554d99eddb8f5c89a91edd7b3e1bd
5
5
  SHA512:
6
- metadata.gz: e8ec2c7c373c5587c1a492c0cd183bb6143c16a59ed49084fcc11294ed48e05c3e076ad48f03de56a5b60f2bad828629f54c086e51b8785e4eb6b39b6366bb7f
7
- data.tar.gz: e129c8269d51269f635b4a4995abe568cdbd0b1aa61060986ffa34528157d79ae4a455a88d309010085928d8897204fadff094f79a94bb0d89aa9a83edd4903d
6
+ metadata.gz: 103265f837aceed3e5452d8c73d50d91077ca0191b0eebc30f78e1b230e566c841560372c258d45f687131257041abb1aa189af76521181ec22973441e5cc548
7
+ data.tar.gz: 75029926a177ca59d984dc564a693091b0518a9d91563a8d754092b5fceca0e6867ebd96d1709c45b225a4c57687b2b2d4bfc97dc6b734457f31bd15b048529a
data/bin/livetext CHANGED
@@ -115,7 +115,7 @@ def parse_command_line
115
115
  STDERR.puts "Command line - #{arg.inspect} is unknown"
116
116
  end
117
117
  end
118
- @live.dump if success
118
+ @live.api.dump if success
119
119
  rescue => err
120
120
  STDERR.puts "Unexpected error! #{err.inspect}\n#{err.backtrace.join("\n")}"
121
121
  end
@@ -1,3 +1,51 @@
1
+ private def whence(back = 0)
2
+ file, line, inmeth = caller[back].split(":")
3
+ meth = inmeth[4..-2]
4
+ [file, line, meth]
5
+ end
6
+
7
+ private def display(file, line, meth, msg)
8
+ puts "--- #{meth} #{line} in #{file}"
9
+ puts "::: " + msg if msg
10
+ end
11
+
12
+ def checkpoint(msg = nil)
13
+ file, line, meth = whence(1)
14
+ display(file, line, meth, msg)
15
+ end
16
+
17
+ def checkpoint?(msg = nil) # with sleep 3
18
+ file, line, meth = whence(1)
19
+ display(file, line, meth, msg)
20
+ end
21
+
22
+ def checkpoint!(msg = nil) # with pause
23
+ file, line, meth = whence(1)
24
+ display(file, line, meth, msg)
25
+ print "::: Pause..."
26
+ gets
27
+ end
28
+
29
+ def warning(err)
30
+ file, line, meth = whence(2) # 2 = skip rescue
31
+ puts "Error in #{meth} in #{file} (non-fatal?)"
32
+ puts " err = #{err.inspect}"
33
+ puts " #{err.backtrace[0]}" if err.respond_to?(:backtrace)
34
+ puts
35
+ end
36
+
37
+ def fatal(err)
38
+ file, line, meth = whence(2) # 2 = skip rescue
39
+ puts "Error in #{meth} in #{file}"
40
+ puts "WTF??"
41
+ puts " err = #{err.inspect}"
42
+ if err.respond_to?(:backtrace)
43
+ context = err.backtrace.map {|x| " " + x + "\n" }
44
+ puts context
45
+ end
46
+ abort "Terminated."
47
+ end
48
+
1
49
 
2
50
  # More later?
3
51
 
@@ -16,3 +64,13 @@ end
16
64
  make_exception(:EndWithoutOpening, "Error: found .end with no opening command")
17
65
  make_exception(:UnknownMethod, "Error: name '%1' is unknown")
18
66
  make_exception(:NoSuchFile, "Error: can't find file '%1' (method '%2')")
67
+
68
+ # Move others here? DisallowedName, etc.
69
+
70
+ make_exception(:ExpectedDotEnd, "Error: expected .end but found end of file")
71
+ make_exception(:ExpectedAlphaNum, "Error: expected an alphanumeric but foun '%1'") # parser/set.rb
72
+ make_exception(:ExpectedCommaEOS, "Error: expected comma or end of string") # parser/set.rb
73
+
74
+
75
+
76
+
@@ -2,7 +2,6 @@
2
2
  module GlobalHelpers
3
3
 
4
4
  def check_disallowed(name)
5
- api.tty "GLOBAL cdis"
6
5
  raise DisallowedName(name) if disallowed?(name)
7
6
  end
8
7
 
@@ -17,8 +17,8 @@ module Livetext::Helpers
17
17
  return graceful_error(err) if self.respond_to?(:graceful_error)
18
18
  return self.parent.graceful_error(err) if self.respond_to?(:parent)
19
19
  raise err
20
- rescue => myerr
21
- TTY.puts "--- Warning: friendly_error #{myerr.inspect}"
20
+ # rescue => myerr
21
+ # TTY.puts "--- Warning: friendly_error #{myerr.inspect}"
22
22
  end
23
23
 
24
24
  def escape_html(string)
@@ -75,7 +75,10 @@ module Livetext::Helpers
75
75
  ## FIXME process_file[!] should call process[_text] ?
76
76
 
77
77
  def process_file(fname, btrace=false)
78
- graceful_error FileNotFound(fname) unless File.exist?(fname)
78
+ unless File.exist?(fname)
79
+ api.dump
80
+ raise FileNotFound(fname)
81
+ end
79
82
  setfile(fname)
80
83
  text = File.readlines(fname)
81
84
  enum = text.each
@@ -107,7 +110,7 @@ module Livetext::Helpers
107
110
  end
108
111
  success
109
112
  rescue => err
110
- STDERR.puts "ERROR: #{err}\n#{err.backtrace.join("\n")}"
113
+ STDERR.puts "ERROR: #{err.inspect}\n#{err.backtrace.join("\n")}"
111
114
  exit
112
115
  end
113
116
 
@@ -186,8 +189,9 @@ module Livetext::Helpers
186
189
  def grab_file(fname)
187
190
  File.read(fname)
188
191
  rescue
189
- ::STDERR.puts "Can't find #{fname.inspect} \n "
190
- return nil
192
+ graceful_error NoSuchFile(fname)
193
+ # ::STDERR.puts "Can't find #{fname.inspect} \n "
194
+ # return nil
191
195
  end
192
196
 
193
197
  def search_upward(file)
@@ -212,6 +216,7 @@ module Livetext::Helpers
212
216
  end
213
217
 
214
218
  def include_file(file)
219
+ api.data = file
215
220
  api.args = [file]
216
221
  dot_include
217
222
  end
@@ -253,5 +258,18 @@ module Livetext::Helpers
253
258
  api.setvar(:File, file)
254
259
  end
255
260
 
261
+ # def dump(file = nil) # not a dot command!
262
+ # file ||= ::STDOUT
263
+ # TTY.puts "--- Writing body (#{@body.size} bytes)" if @body
264
+ # file.puts @body
265
+ # rescue => err
266
+ # TTY.puts "#dump had an error: #{err.inspect}"
267
+ # end
268
+
269
+ def graceful_error(err, msg = nil)
270
+ api.dump
271
+ STDERR.puts msg if msg
272
+ raise err
273
+ end
256
274
  end
257
275
 
data/lib/livetext/more.rb CHANGED
@@ -10,7 +10,21 @@ class Livetext
10
10
 
11
11
  def initialize(hash = {})
12
12
  @vars = {}
13
- hash.each_pair {|k, v| @vars[k.to_sym] = v }
13
+ hash.each_pair do |k, v|
14
+ sym = k.to_sym
15
+ str = k.to_s
16
+ @vars[sym] = v
17
+ @vars[str] = v
18
+ end
19
+ end
20
+
21
+ def inspect
22
+ syms = @vars.keys.select {|x| x.is_a? Symbol }
23
+ out = "\nVariables:"
24
+ syms.each do |sym|
25
+ out << " #{sym}: #{@vars[sym].inspect}\n"
26
+ end
27
+ out
14
28
  end
15
29
 
16
30
  def [](var)
@@ -84,19 +98,6 @@ class Livetext
84
98
  @save_location = where # delegate
85
99
  end
86
100
 
87
- def dump(file = nil) # not a dot command!
88
- file ||= ::STDOUT
89
- file.puts @body
90
- rescue => err
91
- TTY.puts "#dump had an error: #{err.inspect}"
92
- end
93
-
94
- def graceful_error(err, msg = nil)
95
- dump
96
- STDERR.puts msg if msg
97
- raise err
98
- end
99
-
100
101
  def self.customize(mix: [], call: [], vars: {})
101
102
  obj = self.new
102
103
  mix = Array(mix)
@@ -126,13 +127,25 @@ class Livetext
126
127
  @_outdir = "."
127
128
  @no_puts = output.nil?
128
129
  @body = ""
129
- @main = Processor.new(self, output)
130
+ @main = Processor.new(self, output) # nil = make @main its own parent??
130
131
  @indentation = [0]
131
132
  @_vars = Livetext::Vars
132
133
  @api = UserAPI.new(self)
133
134
  initial_vars
134
135
  end
135
136
 
137
+ def inspect
138
+ "Livetext:\n" +
139
+ " source = #{@source.inspect}\n" +
140
+ " mixins = #{@_mixins.inspect}\n" +
141
+ " import = #{@_mixins.inspect}\n" +
142
+ " main = (not shown)\n" +
143
+ " indent = #{@indentation.inspect}\n" +
144
+ " vars = #{@_vars.inspect}\n" +
145
+ " api = (not shown)\n" +
146
+ " body = (#{@body.size} bytes)"
147
+ end
148
+
136
149
  def api
137
150
  @api
138
151
  end
@@ -181,7 +194,9 @@ class Livetext
181
194
  def xform_file(file, vars: nil)
182
195
  Livetext::Vars.replace(vars) unless vars.nil?
183
196
  @_vars.replace(vars) unless vars.nil?
197
+ # checkpoint! "Calling process_file..."
184
198
  self.process_file(file)
199
+ # checkpoint! "...returned"
185
200
  self.body
186
201
  end
187
202
 
@@ -26,7 +26,7 @@ class Processor
26
26
  attr_reader :parent, :sources
27
27
 
28
28
  def initialize(parent, output = nil)
29
- @parent = parent
29
+ @parent = parent || self
30
30
  # STDERR.puts "PARENT.api = #{parent.api.inspect}"
31
31
  @parent.api ||= Livetext::UserAPI.new(@parent)
32
32
  @nopass = false
@@ -65,7 +65,6 @@ class Processor
65
65
 
66
66
  def disallowed?(name)
67
67
  flag = Disallowed.include?(name.to_sym)
68
- # api.tty "disa name = #{name.inspect} flag = #{flag}"
69
68
  flag
70
69
  end
71
70
 
@@ -95,4 +94,6 @@ class Processor
95
94
  @sources.pop
96
95
  nil
97
96
  end
97
+
98
+
98
99
  end
@@ -179,39 +179,6 @@ module Livetext::Standard
179
179
  api.optional_blank_line
180
180
  end
181
181
 
182
- =begin
183
- Filename: foobar
184
- get_globals - 1 - transforming /private/tmp/.blogs/views/foobar/data/global.lt3
185
-
186
- >> variables: fdir = /private/tmp/.blogs/views/foobar/data/
187
- fname = ../settings/view.txt
188
- path = /private/tmp/.blogs/views/foobar/data/../settings/view.txt
189
-
190
- rpath = /private/tmp/.blogs/views/foobar/settings/view.txt
191
- path = /private/tmp/.blogs/views/foobar/settings/view.txt
192
- dir = /private/tmp/.blogs/views/foobar/settings
193
- base = view.txt
194
-
195
- >> variables: fdir = /private/tmp/.blogs/views/foobar/data/
196
- fname = ../settings/recent.txt
197
- path = /private/tmp/.blogs/views/foobar/data/../settings/recent.txt
198
- rpath = /private/tmp/.blogs/views/foobar/settings/recent.txt
199
- path = /private/tmp/.blogs/views/foobar/settings/recent.txt
200
- dir = /private/tmp/.blogs/views/foobar/settings
201
- base = recent.txt
202
-
203
- >> variables: fdir = /private/tmp/.blogs/views/foobar/data/
204
- fname = ../settings/publish.txt
205
- path = /private/tmp/.blogs/views/foobar/data/../settings/publish.txt
206
- rpath = /private/tmp/.blogs/views/foobar/settings/publish.txt
207
- path = /private/tmp/.blogs/views/foobar/settings/publish.txt
208
- dir = /private/tmp/.blogs/views/foobar/settings
209
- base = publish.txt
210
-
211
- get_globals - 2
212
-
213
- =end
214
-
215
182
  def variables(args = nil, body = nil)
216
183
  prefix = api.args[0]
217
184
  fname = api.args[1]
@@ -221,7 +188,7 @@ get_globals - 2
221
188
  path0 = fdir + fname
222
189
  # puts ">> variables: fdir = #{fdir} fname = #{fname} path = #{path0}"
223
190
  pname = Pathname.new(path0)
224
- rpath = pname.realpath(pname)
191
+ rpath = pname.realpath
225
192
  path, dir, base = rpath.to_s, rpath.dirname.to_s, rpath.basename.to_s
226
193
  # puts " rpath = #{rpath} path = #{path} dir = #{dir} base = #{base}"
227
194
  dok, fok = Dir.exist?(dir), File.exist?(path)
@@ -235,13 +202,7 @@ get_globals - 2
235
202
  api.setvars(pairs)
236
203
  api.optional_blank_line
237
204
  rescue => err
238
- puts "Error in #{__method__} in #{__FILE__}
239
- puts " #{err.inspect}"
240
- if err.respond_to?(:backtrace)
241
- context = err.backtrace.map {|x| " " + x}.join("\n")
242
- puts context
243
- end
244
- abort "\nTerminated."
205
+ fatal(err)
245
206
  end
246
207
 
247
208
  def heredoc(args = nil, body = nil)
@@ -25,6 +25,14 @@ class Livetext::UserAPI
25
25
  @live.api
26
26
  end
27
27
 
28
+ def dump(file = nil) # not a dot command!
29
+ file ||= ::STDOUT
30
+ # TTY.puts "--- Writing body (#{@live.body.size} bytes)"
31
+ file.puts @live.body
32
+ rescue => err
33
+ TTY.puts "#dump had an error: #{err.inspect}"
34
+ end
35
+
28
36
  def html
29
37
  @html
30
38
  end
@@ -34,9 +42,9 @@ class Livetext::UserAPI
34
42
  end
35
43
 
36
44
  def include_file(file)
45
+ # checkpoint "DATA = #{file.inspect}"
37
46
  api.data = file
38
47
  api.args = [file]
39
- STDERR.puts "incfile: #{api.methods.sort.inspect}\n "
40
48
  api.dot_include
41
49
  end
42
50
 
@@ -191,11 +199,13 @@ STDERR.puts "incfile: #{api.methods.sort.inspect}\n "
191
199
  end
192
200
 
193
201
  def puts(*args)
194
- @live.output.puts *args
202
+ # @live.output.puts *args
203
+ @live.api.out *args
195
204
  end
196
205
 
197
206
  def print(*args)
198
- @live.output.print *args
207
+ # @live.output.print *args
208
+ @live.api.out! *args
199
209
  end
200
210
 
201
211
  def debug=(val)
@@ -2,5 +2,5 @@
2
2
  # Defining VERSION
3
3
 
4
4
  class Livetext
5
- VERSION = "0.9.44"
5
+ VERSION = "0.9.45"
6
6
  end
data/lib/livetext.rb CHANGED
@@ -12,7 +12,8 @@ require_relative 'livetext/userapi'
12
12
  require_relative 'livetext/formatter'
13
13
  require_relative 'livetext/processor'
14
14
  require_relative 'livetext/helpers'
15
+ require_relative 'livetext/more'
16
+
15
17
  require_relative 'livetext/handler'
16
18
 
17
- require_relative 'livetext/more'
18
19
 
data/test/snapshots.rb CHANGED
@@ -1,11 +1,11 @@
1
- require 'simplecov' # These two lines must go first
2
- SimpleCov.use_merging(true)
3
- SimpleCov.start do
4
- puts "SimpleCov: Snapshots"
5
- add_filter "/test/"
6
- enable_coverage :branch
7
- primary_coverage :branch
8
- end
1
+ # require 'simplecov' # These two lines must go first
2
+ # SimpleCov.use_merging(true)
3
+ # SimpleCov.start do
4
+ # puts "SimpleCov: Snapshots"
5
+ # add_filter "/test/"
6
+ # enable_coverage :branch
7
+ # primary_coverage :branch
8
+ # end
9
9
 
10
10
  require 'minitest/autorun'
11
11
 
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.44
4
+ version: 0.9.45
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-19 00:00:00.000000000 Z
11
+ date: 2024-05-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A smart text processor extensible in Ruby
14
14
  email: rubyhacker@gmail.com