livetext 0.9.43 → 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: 2eecc4b7aec5571c91f72cdba9b7d2e3ab43c7caf3f079ba336ccc112d4a4939
4
- data.tar.gz: d3556ab21ab322f054c0aae264a8e2c833f61f1baa69bb5a965d4b418bf08c58
3
+ metadata.gz: 2b37a1a3e7407f6425178e5013641f1df43ec03a4aeac69936bfa1b4b000a9d5
4
+ data.tar.gz: e7ecf71a35779e59c21d2e013996cfcaa21554d99eddb8f5c89a91edd7b3e1bd
5
5
  SHA512:
6
- metadata.gz: 665b6c06e3f9469a7f98c1e4b6b9a7a4fad55d7a554811d4c92a63757a7ec2d44f33f4468ea2d709896d4bcc4cadb8a1a7f95fdacb2533982a552c133116bbd3
7
- data.tar.gz: 7f391f554863d8411fd3523a09029419914dd8d8df66df1ac5bc2e0186060b543977c46c9e4bbe59343cb8dfa78263c81ff876f8732811b1ed2caa33fb41f05a
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
 
@@ -15,4 +63,14 @@ end
15
63
 
16
64
  make_exception(:EndWithoutOpening, "Error: found .end with no opening command")
17
65
  make_exception(:UnknownMethod, "Error: name '%1' is unknown")
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
+
18
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)
@@ -234,9 +201,8 @@ get_globals - 2
234
201
  pairs = Livetext::ParseGeneral.parse_vars(lines, prefix: nil)
235
202
  api.setvars(pairs)
236
203
  api.optional_blank_line
237
- rescue => e
238
- puts e
239
- puts $!
204
+ rescue => err
205
+ fatal(err)
240
206
  end
241
207
 
242
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.43"
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/plugin/booktool.rb CHANGED
@@ -4,21 +4,22 @@ def mobi(args = nil, body = nil)
4
4
  out = api.format(api.args[0])
5
5
  src = api.args[1]
6
6
  @cover = api.args[2]
7
+ @name = api.args[3]
7
8
  if ::File.directory?(src)
8
9
  files = ::Dir["#{src}/*"].grep /\.html$/
9
10
  files = files.sort # why is this necessary now?
10
- cmd = "cat #{files.join(' ')} >TEMP.html"
11
+ cmd = "cat #{files.join(' ')} >#@name.html"
11
12
  system(cmd)
12
13
  else
13
14
  raise "Not supported yet"
14
15
  end
15
16
 
16
17
  cmd = "ebook-convert "
17
- cmd << "TEMP.html #{out}.mobi "
18
+ cmd << "#@name.html #{out}.mobi "
18
19
  cmd << "--cover #@cover " if @cover
19
20
  system(cmd)
20
21
 
21
- system("links -dump TEMP.html >/tmp/links.out")
22
+ system("links -dump #@name.html >/tmp/links.out")
22
23
  str = `wc -w /tmp/links.out`
23
24
  nw = str.split[0]
24
25
  end
@@ -27,21 +28,22 @@ def epub(args = nil, body = nil)
27
28
  out = api.format(api.args[0])
28
29
  src = api.args[1]
29
30
  @cover = api.args[2]
31
+ @name = api.args[3]
30
32
  if ::File.directory?(src)
31
33
  files = ::Dir["#{src}/*"].grep /\.html$/
32
34
  files = files.sort # why is this necessary now?
33
- cmd = "cat #{files.join(' ')} >TEMP.html"
35
+ cmd = "cat #{files.join(' ')} >#@name.html"
34
36
  system(cmd)
35
37
  else
36
38
  raise "Not supported yet"
37
39
  end
38
40
 
39
41
  cmd = "ebook-convert "
40
- cmd << "TEMP.html #{out}.epub "
42
+ cmd << "#@name.html #{out}.epub "
41
43
  cmd << "--cover #@cover " if @cover
42
44
  system(cmd)
43
45
 
44
- system("links -dump TEMP.html >/tmp/links.out")
46
+ system("links -dump #@name.html >/tmp/links.out")
45
47
  str = `wc -w /tmp/links.out`
46
48
  nw = str.split[0]
47
49
  puts "Approx words: #{nw}"
@@ -1,5 +1,7 @@
1
1
  require 'minitest/autorun'
2
2
 
3
+ MiniTest = Minitest unless defined?(MiniTest)
4
+
3
5
  require 'livetext'
4
6
 
5
7
  # Just another testing class. Chill.
data/test/extra/double.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'minitest/autorun'
2
2
 
3
+ MiniTest = Minitest unless defined?(MiniTest)
4
+
3
5
  require 'livetext'
4
6
 
5
7
  # Just another testing class. Chill.
@@ -1,5 +1,7 @@
1
1
  require 'minitest/autorun'
2
2
 
3
+ MiniTest = Minitest unless defined?(MiniTest)
4
+
3
5
  require 'livetext'
4
6
 
5
7
  # Just another testing class. Chill.
data/test/extra/single.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'minitest/autorun'
2
2
 
3
+ MiniTest = Minitest unless defined?(MiniTest)
4
+
3
5
  require 'livetext'
4
6
 
5
7
  # Just another testing class. Chill.
@@ -41,6 +41,8 @@ end
41
41
  output.puts <<~RUBY
42
42
  require 'minitest/autorun'
43
43
 
44
+ MiniTest = Minitest unless defined?(MiniTest)
45
+
44
46
  require 'livetext'
45
47
 
46
48
  # Just another testing class. Chill.
@@ -1,5 +1,7 @@
1
1
  require 'minitest/autorun'
2
2
 
3
+ MiniTest = Minitest unless defined?(MiniTest)
4
+
3
5
  require 'livetext'
4
6
 
5
7
  # Just another testing class. Chill.
data/test/snapshots.rb CHANGED
@@ -1,14 +1,16 @@
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
 
12
+ MiniTest = Minitest unless defined?(MiniTest)
13
+
12
14
  require_relative '../lib/livetext'
13
15
 
14
16
  =begin
data/test/unit/html.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'minitest/autorun'
2
2
 
3
+ MiniTest = Minitest unless defined?(MiniTest)
4
+
3
5
  require 'livetext'
4
6
 
5
7
  class TestingLivetext < MiniTest::Test
@@ -1,6 +1,8 @@
1
1
 
2
2
  require 'minitest/autorun'
3
3
 
4
+ MiniTest = Minitest unless defined?(MiniTest)
5
+
4
6
  require_relative '../parser' # nested
5
7
 
6
8
  ParseGeneral = ::Livetext::ParseGeneral
@@ -1,6 +1,8 @@
1
1
 
2
2
  require 'minitest/autorun'
3
3
 
4
+ MiniTest = Minitest unless defined?(MiniTest)
5
+
4
6
  require_relative '../parser' # nested
5
7
 
6
8
  class TestParseSet < MiniTest::Test
@@ -1,6 +1,8 @@
1
1
 
2
2
  require 'minitest/autorun'
3
3
 
4
+ MiniTest = Minitest unless defined?(MiniTest)
5
+
4
6
  require_relative '../parser' # nested
5
7
 
6
8
  ParseSet = ::Livetext::ParseSet
@@ -1,5 +1,7 @@
1
1
  require 'minitest/autorun'
2
2
 
3
+ MiniTest = Minitest unless defined?(MiniTest)
4
+
3
5
  require_relative '../parser' # nested
4
6
 
5
7
  class TestStringParser < MiniTest::Test
@@ -1,5 +1,7 @@
1
1
  require 'minitest/autorun'
2
2
 
3
+ MiniTest = Minitest
4
+
3
5
  require_relative '../../lib/livetext'
4
6
 
5
7
  class TestingLivetext < MiniTest::Test
@@ -1,5 +1,7 @@
1
1
  require 'minitest/autorun'
2
2
 
3
+ MiniTest = Minitest unless defined?(MiniTest)
4
+
3
5
  require_relative '../../lib/stringparser'
4
6
 
5
7
  class TestStringParser < MiniTest::Test
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.43
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-14 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