livetext 0.9.46 → 0.9.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05c23cb9790ecbd684af4888ff8237bcf0aa792462bb1da1d183d18b786ab462
4
- data.tar.gz: c0adc17493388b920557b09029213ab558fa43df3c6a7c23dce75d54c38fc298
3
+ metadata.gz: 91574e23cbcbe19d5c06d7c1fbbe8fbbe33ca29b06511da502b532bbb28519c6
4
+ data.tar.gz: 553612fc90e8a6f3676158c3e98997415d0b568fb811fc9d273f8a2ae47478b0
5
5
  SHA512:
6
- metadata.gz: a8717d55d1775c6947b79f008d6a01a64b5e3c084e936b79f7faa243b7776233734fb3e56518ac249faf95bf5b86cbfcde006b50e449762b6bb96788b8c84ec0
7
- data.tar.gz: d552b53c1b82e5b650d65a9e49e45bdf80447ecc0a4af0a290e9d6415979ef71dd3c4da35ca6b1cacff42c062c4e7896613ce05175b0040147e00a349c8ecb3d
6
+ metadata.gz: 909f58be5cd6ee9d11262bb7213d2fab733d379ac678953c0e0225486cdc7a24152b8f5e5b208f2522bf4ea629abd9597c14b3cce1988b19c89b3b92d96f729b
7
+ data.tar.gz: e6e9aaec3cba4d466601d9b4d2f2d96bbb3c3697640684d96c23d70b41843d6a5674a4f41e659355df45a72c59842f7e91df44c76455a430425836db17f1e8e7
@@ -2,59 +2,8 @@
2
2
  # Class Livetext reopened (top level).
3
3
 
4
4
  class Livetext
5
-
6
5
  include Helpers
7
6
 
8
- class Variables
9
- attr_reader :vars
10
-
11
- def initialize(hash = {})
12
- @vars = {}
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
28
- end
29
-
30
- def [](var)
31
- @vars[var.to_sym]
32
- end
33
-
34
- def []=(var, value)
35
- @vars[var.to_sym] = value
36
- end
37
-
38
- def get(var)
39
- @vars[var.to_sym] || "[#{var} is undefined]"
40
- end
41
-
42
- def set(var, value)
43
- @vars[var.to_sym] = value.to_s
44
- end
45
-
46
- def setvars(pairs)
47
- pairs = pairs.to_a if pairs.is_a?(Hash)
48
- pairs.each do |var, value|
49
- api.setvar(var, value)
50
- end
51
- end
52
-
53
- def to_a
54
- @vars.to_a
55
- end
56
- end
57
-
58
7
  Vars = Variables.new
59
8
 
60
9
  TTY = ::File.open("/dev/tty", "w")
@@ -98,7 +47,7 @@ class Livetext
98
47
  @save_location = where # delegate
99
48
  end
100
49
 
101
- def initialize(output = ::STDOUT)
50
+ def initialize(output = ::STDOUT) # Livetext
102
51
  @source = nil
103
52
  @_mixins = []
104
53
  @_imports = []
@@ -123,8 +72,6 @@ class Livetext
123
72
  end
124
73
  call.each {|cmd| obj.main.send(cmd[1..-1]) } # ignores leading dot, no param
125
74
  obj.api.setvars(vars)
126
- # puts "------ init: obj = "
127
- # p obj
128
75
  obj
129
76
  end
130
77
 
@@ -10,16 +10,19 @@
10
10
  end
11
11
 
12
12
  def checkpoint(msg = nil)
13
+ return unless ENV['LIVETEXT_DEBUG'] == "true"
13
14
  file, line, meth = whence(1)
14
15
  display(file, line, meth, msg)
15
16
  end
16
17
 
17
18
  def checkpoint?(msg = nil) # with sleep 3
19
+ return unless ENV['LIVETEXT_DEBUG'] == "true"
18
20
  file, line, meth = whence(1)
19
21
  display(file, line, meth, msg)
20
22
  end
21
23
 
22
24
  def checkpoint!(msg = nil) # with pause
25
+ return unless ENV['LIVETEXT_DEBUG'] == "true"
23
26
  file, line, meth = whence(1)
24
27
  display(file, line, meth, msg)
25
28
  print "::: Pause..."
@@ -71,6 +74,3 @@ make_exception(:ExpectedDotEnd, "Error: expected .end but found end of file")
71
74
  make_exception(:ExpectedAlphaNum, "Error: expected an alphanumeric but foun '%1'") # parser/set.rb
72
75
  make_exception(:ExpectedCommaEOS, "Error: expected comma or end of string") # parser/set.rb
73
76
 
74
-
75
-
76
-
@@ -8,7 +8,9 @@ class Livetext::Expansion
8
8
  Lbrack = "\\["
9
9
  Colon = ":"
10
10
 
11
- def initialize(instance)
11
+ Formatter = ::Livetext::Formatter
12
+
13
+ def initialize(instance) # Livetext::Expansion
12
14
  @live = instance
13
15
  end
14
16
 
@@ -1,14 +1,6 @@
1
- module Formatter
1
+ module Livetext::Formatter
2
2
 
3
- ## Hmmm...
4
- #
5
- # Double: b, i, t, s
6
- # Single: bits
7
- # Brackt: bits
8
- #
9
-
10
-
11
- def self.format(str)
3
+ def self.format(str) # FIXME - unneeded?
12
4
  str = str.chomp
13
5
  s2 = Double.process(str.chomp)
14
6
  s3 = Bracketed.process(s2)
@@ -16,188 +8,195 @@ module Formatter
16
8
  s4
17
9
  end
18
10
 
19
- class Delimited
20
- def initialize(str, marker, tag)
21
- @str, @marker, @tag = str.dup, marker, tag
22
- @buffer = ""
23
- @cdata = ""
24
- @state = :INITIAL
25
- end
11
+ ## Hmmm...
12
+ #
13
+ # Double: b, i, t, s
14
+ # Single: bits
15
+ # Brackt: bits
16
+ #
26
17
 
27
- def status(where)
28
- if $debug
29
- STDERR.printf "%-11s %-7s #{@marker.inspect} \n #{' '*11} state = %-8s str = %-20s buffer = %-20s cdata = %-20s\n",
30
- where, self.class, @state, @str.inspect, @buffer.inspect, @cdata.inspect
31
- end
32
- end
18
+ end
33
19
 
34
- def front
35
- @str[0]
36
- end
20
+ class Livetext::Formatter::Delimited
21
+ def initialize(str, marker, tag) # Delimited
22
+ @str, @marker, @tag = str.dup, marker, tag
23
+ @buffer = ""
24
+ @cdata = ""
25
+ @state = :INITIAL
26
+ end
37
27
 
38
- def grab(n=1)
39
- char = @str.slice!(0..(n-1)) # grab n chars
40
- char
28
+ def status(where)
29
+ if $debug
30
+ STDERR.printf "%-11s %-7s #{@marker.inspect} \n #{' '*11} state = %-8s str = %-20s buffer = %-20s cdata = %-20s\n",
31
+ where, self.class, @state, @str.inspect, @buffer.inspect, @cdata.inspect
41
32
  end
33
+ end
42
34
 
43
- def grab_terminator
44
- @state = :LOOPING
45
- # goes onto buffer by default
46
- # Don't? what if searching for space_marker?
47
- # @buffer << grab
48
- end
35
+ def front
36
+ @str[0]
37
+ end
49
38
 
50
- def eol?
51
- @str.empty?
52
- end
39
+ def grab(n=1)
40
+ char = @str.slice!(0..(n-1)) # grab n chars
41
+ char
42
+ end
53
43
 
54
- def space?
55
- front == " "
56
- end
44
+ def grab_terminator
45
+ @state = :LOOPING
46
+ # goes onto buffer by default
47
+ # Don't? what if searching for space_marker?
48
+ # @buffer << grab
49
+ end
57
50
 
58
- def escape?
59
- front == "\\"
60
- end
51
+ def eol?
52
+ @str.empty?
53
+ end
61
54
 
62
- def terminated?
63
- space? # Will be overridden except in Single
64
- end
55
+ def space?
56
+ front == " "
57
+ end
65
58
 
66
- def marker?
67
- @str.start_with?(@marker)
68
- end
59
+ def escape?
60
+ front == "\\"
61
+ end
69
62
 
70
- def space_marker?
71
- @str.start_with?(" " + @marker)
72
- end
63
+ def terminated?
64
+ space? # Will be overridden except in Single
65
+ end
73
66
 
74
- def wrap(text)
75
- if text.empty?
76
- result = @marker
77
- result = "" if @marker[1] == "["
78
- return result
79
- end
80
- "<#{@tag}>#{text}</#{@tag}>"
67
+ def marker?
68
+ @str.start_with?(@marker)
69
+ end
70
+
71
+ def space_marker?
72
+ @str.start_with?(" " + @marker)
73
+ end
74
+
75
+ def wrap(text)
76
+ if text.empty?
77
+ result = @marker
78
+ result = "" if @marker[1] == "["
79
+ return result
81
80
  end
82
-
83
- def initial
84
- n = @marker.length
85
- case
86
- when escape?
87
- grab # backslash
88
- @buffer << grab # char
89
- when space_marker?
90
- @buffer << grab # append the space
91
- grab(n) # eat the marker
92
- @state = :CDATA
93
- when marker?
94
- grab(n) # Eat the marker
95
- @state = :CDATA
96
- when eol?
97
- @state = :FINAL
98
- else
99
- @state = :BUFFER
100
- end
81
+ "<#{@tag}>#{text}</#{@tag}>"
82
+ end
83
+
84
+ def initial
85
+ n = @marker.length
86
+ case
87
+ when escape?
88
+ grab # backslash
89
+ @buffer << grab # char
90
+ when space_marker?
91
+ @buffer << grab # append the space
92
+ grab(n) # eat the marker
93
+ @state = :CDATA
94
+ when marker?
95
+ grab(n) # Eat the marker
96
+ @state = :CDATA
97
+ when eol?
98
+ @state = :FINAL
99
+ else
100
+ @state = :BUFFER
101
101
  end
102
+ end
102
103
 
103
- def buffer
104
- @buffer << grab
105
- @state = :LOOPING
106
- end
104
+ def buffer
105
+ @buffer << grab
106
+ @state = :LOOPING
107
+ end
107
108
 
108
- def cdata
109
- case
110
- when eol?
111
- if @cdata.empty?
112
- @buffer << @marker unless @marker[1] == "["
113
- else
114
- @buffer << wrap(@cdata)
115
- end
116
- @state = :FINAL
117
- when terminated?
118
- @buffer << wrap(@cdata)
119
- grab_terminator # "*a *b" case???
120
- @cdata = ""
121
- @state = :LOOPING
109
+ def cdata
110
+ case
111
+ when eol?
112
+ if @cdata.empty?
113
+ @buffer << @marker unless @marker[1] == "["
122
114
  else
123
- @cdata << grab
124
- @state = :CDATA
125
- end
126
- end
127
-
128
- def looping
129
- n = @marker.length
130
- case
131
- when escape?
132
- grab # backslash
133
- @buffer << grab # char
134
- when space_marker?
135
- @buffer << grab # append the space
136
- grab(n) # eat the marker
137
- @state = :CDATA
138
- when eol?
139
- @state = :FINAL
140
- else # includes marker not preceded by space!
141
- @buffer << grab
115
+ @buffer << wrap(@cdata)
142
116
  end
117
+ @state = :FINAL
118
+ when terminated?
119
+ @buffer << wrap(@cdata)
120
+ grab_terminator # "*a *b" case???
121
+ @cdata = ""
122
+ @state = :LOOPING
123
+ else
124
+ @cdata << grab
125
+ @state = :CDATA
143
126
  end
127
+ end
144
128
 
145
- def handle
146
- loop do
147
- break if @state == :FINAL
148
- meth = @state.downcase
149
- send(meth)
150
- end
151
- return @buffer
129
+ def looping
130
+ n = @marker.length
131
+ case
132
+ when escape?
133
+ grab # backslash
134
+ @buffer << grab # char
135
+ when space_marker?
136
+ @buffer << grab # append the space
137
+ grab(n) # eat the marker
138
+ @state = :CDATA
139
+ when eol?
140
+ @state = :FINAL
141
+ else # includes marker not preceded by space!
142
+ @buffer << grab
152
143
  end
144
+ end
153
145
 
154
- def self.process(str)
155
- bold = self.new(str, "*", "b")
156
- sb = bold.handle
157
- # return sb
158
- ital = self.new(sb, "_", "i")
159
- si = ital.handle
160
- code = self.new(si, "`", "tt")
161
- sc = code.handle
162
- stri = self.new(sc, "~", "strike")
163
- si = stri.handle
164
- si
146
+ def handle
147
+ loop do
148
+ break if @state == :FINAL
149
+ meth = @state.downcase
150
+ send(meth)
165
151
  end
152
+ return @buffer
166
153
  end
167
154
 
168
- class Single < Delimited
169
- # Yeah, this one is that simple
155
+ def self.process(str)
156
+ bold = self.new(str, "*", "b")
157
+ sb = bold.handle
158
+ # return sb
159
+ ital = self.new(sb, "_", "i")
160
+ si = ital.handle
161
+ code = self.new(si, "`", "tt")
162
+ sc = code.handle
163
+ stri = self.new(sc, "~", "strike")
164
+ si = stri.handle
165
+ si
170
166
  end
167
+ end
171
168
 
172
- class Double < Delimited
173
- def initialize(str, sigil, tag)
174
- super
175
- # Convention: marker is "**", sigil is "*"
176
- @marker = sigil + sigil
177
- end
169
+ class Livetext::Formatter::Single < Livetext::Formatter::Delimited
170
+ # Yeah, this one is that simple
171
+ end
178
172
 
179
- def terminated?
180
- terms = [" ", ".", ","]
181
- terms.include?(front)
182
- end
173
+ class Livetext::Formatter::Double < Livetext::Formatter::Delimited
174
+ def initialize(str, sigil, tag) # Double
175
+ super
176
+ # Convention: marker is "**", sigil is "*"
177
+ @marker = sigil + sigil
183
178
  end
184
179
 
185
- class Bracketed < Delimited
186
- def initialize(str, sigil, tag)
187
- super
188
- # Convention: marker is "*[", sigil is "*"
189
- @marker = sigil + "["
190
- end
180
+ def terminated?
181
+ terms = [" ", ".", ","]
182
+ terms.include?(front)
183
+ end
184
+ end
191
185
 
192
- def terminated?
193
- front == "]" || eol?
194
- end
186
+ class Livetext::Formatter::Bracketed < Livetext::Formatter::Delimited
187
+ def initialize(str, sigil, tag) # Bracketed
188
+ super
189
+ # Convention: marker is "*[", sigil is "*"
190
+ @marker = sigil + "["
191
+ end
195
192
 
196
- def grab_terminator
197
- @state = :LOOPING
198
- grab
199
- end
193
+ def terminated?
194
+ front == "]" || eol?
200
195
  end
201
196
 
197
+ def grab_terminator
198
+ @state = :LOOPING
199
+ grab
200
+ end
202
201
  end
203
202
 
@@ -19,7 +19,7 @@ class Livetext::Functions
19
19
  "\b"
20
20
  end
21
21
 
22
- # FIXME Function parameters need to be fixed...
22
+ # FIXME Function parameters need to be fixed...
23
23
 
24
24
  def isqrt(param = nil) # "integer square root" - Just for testing
25
25
  arg = num = param # Takes any number
@@ -1,5 +1,5 @@
1
1
 
2
- module GlobalHelpers
2
+ module Livetext::GlobalHelpers
3
3
 
4
4
  def check_disallowed(name)
5
5
  raise DisallowedName(name) if disallowed?(name)
@@ -5,11 +5,11 @@ require_relative '../helpers'
5
5
 
6
6
  class Livetext::Handler::Import
7
7
  include Livetext::Helpers
8
- include GlobalHelpers
8
+ include Livetext::GlobalHelpers
9
9
 
10
10
  attr_reader :file
11
11
 
12
- def initialize(name)
12
+ def initialize(name) # Livetext::Handler::Import
13
13
  @name = name
14
14
  @file = find_file(name)
15
15
  end
@@ -5,11 +5,11 @@ require_relative '../helpers'
5
5
 
6
6
  class Livetext::Handler::Mixin
7
7
  include Livetext::Helpers
8
- include GlobalHelpers
8
+ include Livetext::GlobalHelpers
9
9
 
10
10
  attr_reader :file
11
11
 
12
- def initialize(name, parent)
12
+ def initialize(name, parent) # Livetext::Handler::Mixin
13
13
  @name = name
14
14
  @file = find_file(name, ".rb", "plugin")
15
15
  parent.graceful_error FileNotFound(name) if @file.nil?
@@ -2,9 +2,7 @@
2
2
  require_relative 'global_helpers'
3
3
  require_relative 'expansion'
4
4
 
5
-
6
5
  module Livetext::Helpers
7
-
8
6
  Space = " "
9
7
  Sigil = "." # Can't change yet
10
8
 
@@ -75,6 +73,7 @@ module Livetext::Helpers
75
73
  ## FIXME process_file[!] should call process[_text] ?
76
74
 
77
75
  def process_file(fname, btrace=false)
76
+ checkpoint "fname = #{fname.inspect}"
78
77
  unless File.exist?(fname)
79
78
  api.dump
80
79
  raise FileNotFound(fname)
@@ -127,6 +126,7 @@ module Livetext::Helpers
127
126
  api.data = data0.dup # should permit _ in function names at least
128
127
  args0 = data0.split
129
128
  api.args = args0.dup
129
+ checkpoint "name = #{name} args = #{args0.inspect}"
130
130
  retval = @main.send(name) # , *args) # was 125
131
131
  retval
132
132
  rescue => err
@@ -258,14 +258,6 @@ module Livetext::Helpers
258
258
  api.setvar(:File, file)
259
259
  end
260
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
261
  def graceful_error(err, msg = nil)
270
262
  api.dump
271
263
  STDERR.puts msg if msg
data/lib/livetext/html.rb CHANGED
@@ -1,39 +1,6 @@
1
+ class Livetext::HTML
1
2
 
2
- # module HTMLHelper
3
- #
4
- # def wrapped(str, *tags) # helper
5
- # open, close = open_close_tags(*tags)
6
- # open + str + close
7
- # end
8
- #
9
- # def wrapped!(str, tag, **extras) # helper
10
- # open, close = open_close_tags(tag)
11
- # extras.each_pair do |name, value|
12
- # open.sub!(">", " #{name}='#{value}'>")
13
- # end
14
- # open + str + close
15
- # end
16
- #
17
- # def wrap(*tags) # helper
18
- # open, close = open_close_tags(*tags)
19
- # api.out open
20
- # yield
21
- # api.out close
22
- # end
23
- #
24
- # def open_close_tags(*tags)
25
- # open, close = "", ""
26
- # tags.each do |tag|
27
- # open << "<#{tag}>"
28
- # close.prepend("</#{tag}>")
29
- # end
30
- # [open, close]
31
- # end
32
- # end
33
-
34
- class HTML
35
-
36
- def initialize(api)
3
+ def initialize(api) # HTML
37
4
  raise "API is nil!" unless api
38
5
  @api = api
39
6
  @indent = 0
@@ -6,7 +6,7 @@ make_exception(:ExpectedString, "Error: expected a string")
6
6
 
7
7
  class Livetext::ParseGeneral < StringParser
8
8
 
9
- def initialize(str)
9
+ def initialize(str) # Livetext::ParseGeneral
10
10
  super
11
11
  end
12
12
 
@@ -10,7 +10,7 @@ class Livetext::ParseSet < StringParser
10
10
  self.new(str).parse
11
11
  end
12
12
 
13
- def initialize(line)
13
+ def initialize(line) # Livetext::ParseSet
14
14
  super
15
15
  end
16
16
 
@@ -2,7 +2,7 @@ class StringParser
2
2
 
3
3
  attr_reader :line, :eos, :i, :len
4
4
 
5
- def initialize(line)
5
+ def initialize(line) # StringParser
6
6
  raise NilValue if line.nil?
7
7
  raise ExpectedString unless String === line
8
8
  @line = line
@@ -1,4 +1,4 @@
1
- # Reopening for paths... do differently?
1
+ # Reopening for paths... do differently? FIXME
2
2
 
3
3
  class Livetext
4
4
  def self.get_path(dir = "")
@@ -23,7 +23,7 @@ class Processor
23
23
 
24
24
  attr_reader :parent, :sources
25
25
 
26
- def initialize(parent, output = nil)
26
+ def initialize(parent, output = nil) # Processor
27
27
  @parent = parent || self
28
28
  # STDERR.puts "PARENT.api = #{parent.api.inspect}"
29
29
  @parent.api ||= Livetext::UserAPI.new(@parent)
@@ -35,7 +35,7 @@ class Processor
35
35
  @indentation = @parent.indentation
36
36
  @_mixins = []
37
37
  @_imports = []
38
- @html = HTML.new(@parent.api)
38
+ @html = Livetext::HTML.new(@parent.api)
39
39
  end
40
40
 
41
41
  def api
@@ -85,6 +85,4 @@ class Processor
85
85
  @sources.pop
86
86
  nil
87
87
  end
88
-
89
-
90
88
  end
@@ -3,10 +3,19 @@ require_relative 'parser/string' # FIXME eh, should fix this
3
3
  # Class Livetext skeleton (top level).
4
4
 
5
5
  class Livetext
6
+ class Variables
7
+ end
8
+
6
9
  module Handler
7
10
  end
8
11
 
9
- module ParsingConstants
12
+ module Formatter
13
+ end
14
+
15
+ class HTML
16
+ end
17
+
18
+ class ParsingConstants
10
19
  end
11
20
 
12
21
  class LineParser < StringParser
@@ -1,4 +1,3 @@
1
-
2
1
  require 'pathname' # For _seek - remove later??
3
2
 
4
3
  require_relative 'parser' # nested requires
@@ -9,12 +8,9 @@ make_exception(:ExpectedOnOff, "Error: expected 'on' or 'off'")
9
8
  make_exception(:DisallowedName, "Error: name '%1' is invalid")
10
9
  make_exception(:FileNotFound, "Error: file '%1' not found")
11
10
 
12
-
13
11
  # Module Standard comprises most of the standard or "common" methods.
14
12
 
15
13
  module Livetext::Standard
16
-
17
- # include HTMLHelper
18
14
  include Livetext::Helpers
19
15
 
20
16
  TTY = ::File.open("/dev/tty", "w")
@@ -74,6 +70,8 @@ module Livetext::Standard
74
70
  return true
75
71
  end
76
72
 
73
+ # FIXME - move these to a single universal place in code
74
+
77
75
  def h1(args = nil, body = nil); api.out html.tag(:h1, cdata: api.data); return true; end
78
76
  def h2(args = nil, body = nil); api.out html.tag(:h2, cdata: api.data); return true; end
79
77
  def h3(args = nil, body = nil); api.out html.tag(:h3, cdata: api.data); return true; end
@@ -258,7 +256,7 @@ module Livetext::Standard
258
256
  def dot_include(args = nil, body = nil) # dot command
259
257
  file = api.expand_variables(api.args.first) # allows for variables
260
258
  check_file_exists(file)
261
- # checkpoint "====== self.methods = #{self.methods.sort.inspect}"
259
+ checkpoint
262
260
  @parent.process_file(file)
263
261
  api.optional_blank_line
264
262
  end
@@ -4,8 +4,7 @@ require_relative 'html'
4
4
  # Encapsulate the UserAPI as a class
5
5
 
6
6
  class Livetext::UserAPI
7
-
8
- include ::Livetext::Standard
7
+ include ::Livetext::Standard # FIXME - feels wonky?
9
8
 
10
9
  KBD = File.new("/dev/tty", "r")
11
10
  TTY = File.new("/dev/tty", "w")
@@ -14,10 +13,10 @@ class Livetext::UserAPI
14
13
 
15
14
  attr_accessor :data, :args
16
15
 
17
- def initialize(live)
16
+ def initialize(live) # Livetext::UserAPI
18
17
  @live = live
19
18
  @vars = live.vars
20
- @html = HTML.new(self)
19
+ @html = Livetext::HTML.new(self)
21
20
  @expander = Livetext::Expansion.new(live)
22
21
  end
23
22
 
@@ -45,7 +44,7 @@ class Livetext::UserAPI
45
44
  # checkpoint "DATA = #{file.inspect}"
46
45
  api.data = file
47
46
  api.args = [file]
48
- api.dot_include
47
+ dot_include
49
48
  end
50
49
 
51
50
  def expand_variables(str)
@@ -215,6 +214,5 @@ class Livetext::UserAPI
215
214
  def debug(*args)
216
215
  TTY.puts *args if @live.debug
217
216
  end
218
-
219
217
  end
220
218
 
@@ -0,0 +1,50 @@
1
+ class Livetext::Variables # FIXME - split out into file as Livetext::Variables
2
+ attr_reader :vars
3
+
4
+ def initialize(hash = {}) # Livetext::Variables
5
+ @vars = {}
6
+ hash.each_pair do |k, v|
7
+ sym = k.to_sym
8
+ str = k.to_s
9
+ @vars[sym] = v
10
+ @vars[str] = v
11
+ end
12
+ end
13
+
14
+ def inspect
15
+ syms = @vars.keys.select {|x| x.is_a? Symbol }
16
+ out = "\nVariables:"
17
+ syms.each do |sym|
18
+ out << " #{sym}: #{@vars[sym].inspect}\n"
19
+ end
20
+ out
21
+ end
22
+
23
+ def [](var)
24
+ @vars[var.to_sym]
25
+ end
26
+
27
+ def []=(var, value)
28
+ @vars[var.to_sym] = value
29
+ end
30
+
31
+ def get(var)
32
+ @vars[var.to_sym] || "[#{var} is undefined]"
33
+ end
34
+
35
+ def set(var, value)
36
+ @vars[var.to_sym] = value.to_s
37
+ end
38
+
39
+ def setvars(pairs)
40
+ pairs = pairs.to_a if pairs.is_a?(Hash)
41
+ pairs.each do |var, value|
42
+ api.setvar(var, value)
43
+ end
44
+ end
45
+
46
+ def to_a
47
+ @vars.to_a
48
+ end
49
+ end
50
+
@@ -2,5 +2,5 @@
2
2
  # Defining VERSION
3
3
 
4
4
  class Livetext
5
- VERSION = "0.9.46"
5
+ VERSION = "0.9.48"
6
6
  end
data/lib/livetext.rb CHANGED
@@ -1,19 +1,21 @@
1
1
 
2
- require_relative 'livetext/skeleton'
3
- require_relative 'livetext/version'
4
- require_relative 'livetext/paths'
2
+ if !defined?(Livetext)
3
+ require_relative 'livetext/skeleton'
4
+ require_relative 'livetext/version'
5
+ require_relative 'livetext/helpers'
6
+ require_relative 'livetext/variables'
7
+ require_relative 'livetext/core'
8
+ require_relative 'livetext/formatter'
9
+ require_relative 'livetext/paths'
5
10
 
6
- require_relative 'livetext/reopen'
7
-
8
- require_relative 'livetext/errors'
9
- require_relative 'livetext/standard'
10
- require_relative 'livetext/functions'
11
- require_relative 'livetext/userapi'
12
- require_relative 'livetext/formatter'
13
- require_relative 'livetext/processor'
14
- require_relative 'livetext/helpers'
15
- require_relative 'livetext/more'
16
-
17
- require_relative 'livetext/handler'
11
+ require_relative 'livetext/reopen'
18
12
 
13
+ require_relative 'livetext/errors'
14
+ require_relative 'livetext/standard'
15
+ require_relative 'livetext/functions'
16
+ require_relative 'livetext/userapi'
17
+ # require_relative 'livetext/formatter'
18
+ require_relative 'livetext/processor'
19
19
 
20
+ require_relative 'livetext/handler'
21
+ end
data/test/all.rb CHANGED
@@ -5,5 +5,8 @@
5
5
  # add_filter "/test/"
6
6
  # end
7
7
 
8
+ # FIXME - this file is broken - path issues
9
+
8
10
  require_relative 'unit/all'
11
+
9
12
  require_relative 'snapshots' # snapshots
@@ -11,6 +11,7 @@ The tests here include:
11
11
  double.txt Double sigil (see Formatting below)
12
12
  bracketed.txt Bracketed sigil (see Formatting below)
13
13
 
14
+ NOTE: These are moved under test/unit/ now.
14
15
 
15
16
  Variables:
16
17
  ----------
@@ -5,11 +5,19 @@ Testing heredocs (used in a table)
5
5
 
6
6
  <center><table width=90% cellpadding=5>
7
7
  <tr>
8
- <td valign=top>This is <br>only <br>a test.<br></td>
9
- <td valign=top>This is <br>just <br>some <br>random text.<br></td>
8
+ <td valign=top>This is <br><br>
9
+ only <br><br>
10
+ a test.<br></td>
11
+ <td valign=top>This is <br><br>
12
+ just <br><br>
13
+ some <br><br>
14
+ random text.<br></td>
10
15
  </tr>
11
16
  <tr>
12
- <td valign=top>And so<br>is this.<br></td>
13
- <td valign=top>This is <br>row 2<br>col 2<br></td>
17
+ <td valign=top>And so<br><br>
18
+ is this.<br></td>
19
+ <td valign=top>This is <br><br>
20
+ row 2<br><br>
21
+ col 2<br></td>
14
22
  </tr>
15
23
  </table></center>
@@ -0,0 +1,15 @@
1
+ Testing heredocs (used in a table)
2
+ <p>
3
+
4
+ <br>
5
+
6
+ <center><table width=90% cellpadding=5>
7
+ <tr>
8
+ <td valign=top>This is <br>only <br>a test.<br></td>
9
+ <td valign=top>This is <br>just <br>some <br>random text.<br></td>
10
+ </tr>
11
+ <tr>
12
+ <td valign=top>And so<br>is this.<br></td>
13
+ <td valign=top>This is <br>row 2<br>col 2<br></td>
14
+ </tr>
15
+ </table></center>
data/test/snapshots.rb CHANGED
@@ -132,7 +132,7 @@ class TestingLivetext < MiniTest::Test
132
132
  @included - @excluded
133
133
  end
134
134
 
135
- def initialize(base, assertion = nil)
135
+ def initialize(base, assertion = nil) # Testing::Livetext
136
136
  @assertion = assertion
137
137
  @base = base
138
138
  @errors = false
data/test/unit/all.rb CHANGED
@@ -2,3 +2,10 @@
2
2
  require_relative 'standard'
3
3
  require_relative 'parser' # nested
4
4
  require_relative 'html'
5
+
6
+ require_relative 'single'
7
+ require_relative 'double'
8
+ require_relative 'bracketed'
9
+ require_relative 'variables'
10
+ require_relative 'functions'
11
+
data/test/unit/html.rb CHANGED
@@ -12,7 +12,7 @@ class TestingLivetext < MiniTest::Test
12
12
 
13
13
  def test_wrapped
14
14
  live = Livetext.new
15
- html = HTML.new(live.api)
15
+ html = Livetext::HTML.new(live.api)
16
16
  str = "nothing much"
17
17
  assert_equal html.tag(:b, cdata: str), "<b>#{str}</b>"
18
18
  assert_equal html.tag(:b, :i, cdata: str), "<b><i>#{str}</i></b>"
@@ -23,7 +23,7 @@ class TestingLivetext < MiniTest::Test
23
23
 
24
24
  def test_wrapped_extra
25
25
  live = Livetext.new
26
- html = HTML.new(live.api)
26
+ html = Livetext::HTML.new(live.api)
27
27
  str = "nothing much"
28
28
  assert_equal html.tag(:td, cdata: str, valign: :top),
29
29
  "<td valign='top'>#{str}</td>"
@@ -7,7 +7,6 @@ require 'livetext'
7
7
  # Just another testing class. Chill.
8
8
 
9
9
  class TestingLivetextSingle < MiniTest::Test
10
-
11
10
  def setup
12
11
  @live = Livetext.new
13
12
  end
@@ -131,11 +130,9 @@ class TestingLivetextSingle < MiniTest::Test
131
130
  def test_single_013_escaped_marker_is_ignored
132
131
  # Escaped marker is ignored
133
132
  # No special initialization
134
- src = "\\\\*escaped"
133
+ src = '\\' + "*escaped" # Note single quote
135
134
  exp = "*escaped"
136
135
  actual = @live.api.format(src)
137
136
  check_match(exp, actual)
138
137
  end
139
-
140
-
141
138
  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.9.46
4
+ version: 0.9.48
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-24 00:00:00.000000000 Z
11
+ date: 2024-05-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A smart text processor extensible in Ruby
14
14
  email: rubyhacker@gmail.com
@@ -26,8 +26,8 @@ files:
26
26
  - imports/markdown.rb
27
27
  - imports/pyggish.rb
28
28
  - imports/tutorial.rb
29
- - lib/cmdargs.rb
30
29
  - lib/livetext.rb
30
+ - lib/livetext/core.rb
31
31
  - lib/livetext/errors.rb
32
32
  - lib/livetext/expansion.rb
33
33
  - lib/livetext/formatter.rb
@@ -38,7 +38,6 @@ files:
38
38
  - lib/livetext/handler/mixin.rb
39
39
  - lib/livetext/helpers.rb
40
40
  - lib/livetext/html.rb
41
- - lib/livetext/more.rb
42
41
  - lib/livetext/parser.rb
43
42
  - lib/livetext/parser/general.rb
44
43
  - lib/livetext/parser/set.rb
@@ -50,6 +49,7 @@ files:
50
49
  - lib/livetext/skeleton.rb
51
50
  - lib/livetext/standard.rb
52
51
  - lib/livetext/userapi.rb
52
+ - lib/livetext/variables.rb
53
53
  - lib/livetext/version.rb
54
54
  - livetext.gemspec
55
55
  - plugin/booktool.rb
@@ -61,16 +61,11 @@ files:
61
61
  - plugin/tutorial.rb
62
62
  - test/all.rb
63
63
  - test/extra/README.txt
64
- - test/extra/bracketed.rb
65
64
  - test/extra/bracketed.txt
66
- - test/extra/double.rb
67
65
  - test/extra/double.txt
68
- - test/extra/functions.rb
69
66
  - test/extra/functions.txt
70
- - test/extra/single.rb
71
67
  - test/extra/single.txt
72
68
  - test/extra/testgen.rb
73
- - test/extra/variables.rb
74
69
  - test/extra/variables.txt
75
70
  - test/snapshots.rb
76
71
  - test/snapshots/basic_formatting/expected-error.txt
@@ -186,11 +181,15 @@ files:
186
181
  - test/snapshots/subset.txt
187
182
  - test/snapshots/table_with_heredocs/expected-error.txt
188
183
  - test/snapshots/table_with_heredocs/expected-output.txt
184
+ - test/snapshots/table_with_heredocs/old-exp-out.txt
189
185
  - test/snapshots/table_with_heredocs/source.lt3
190
186
  - test/snapshots/var_into_func/expected-error.txt
191
187
  - test/snapshots/var_into_func/expected-output.txt
192
188
  - test/snapshots/var_into_func/source.lt3
193
189
  - test/unit/all.rb
190
+ - test/unit/bracketed.rb
191
+ - test/unit/double.rb
192
+ - test/unit/functions.rb
194
193
  - test/unit/html.rb
195
194
  - test/unit/parser.rb
196
195
  - test/unit/parser/all.rb
@@ -198,8 +197,10 @@ files:
198
197
  - test/unit/parser/mixin.rb
199
198
  - test/unit/parser/set.rb
200
199
  - test/unit/parser/string.rb
200
+ - test/unit/single.rb
201
201
  - test/unit/standard.rb
202
202
  - test/unit/stringparser.rb
203
+ - test/unit/variables.rb
203
204
  homepage: https://github.com/Hal9000/livetext
204
205
  licenses:
205
206
  - Ruby
data/lib/cmdargs.rb DELETED
@@ -1,106 +0,0 @@
1
-
2
- require_relative 'livetext'
3
-
4
- =begin
5
- Weird concepts to understand here...
6
-
7
- 1. A Livetext dot-command (flush left) usually looks like:
8
- .foobar
9
-
10
- 2. A dot-command (left-indented) usually looks like:
11
- $.foobar
12
-
13
- 3. More generally, it may have any number of parameters (0, 1, ...)
14
- .redirect somefile.txt append
15
-
16
- 4. Variables and functions *can* appear (rare in practice??)
17
- .redirect somefile$my_suffix $$my_mode
18
-
19
- 5. A trailing # comment may appear
20
- a. Stripped... saved in #raw ? #data ? #comment ? elsewhere?
21
- b. NOT the "dot" as a comment!
22
-
23
- 6. .foobar # This here is a comment
24
-
25
- 7. #data accessor returns all data on the .foo line...
26
- a. ...After the initial space
27
- b. ...Including later spaces
28
- c. Including comment??
29
- d. .foo This is o n l y a test.
30
- # #data returns: "This is o n l y a test."
31
- e. What about formatting???
32
- f. What about: comments? variables? functions?
33
-
34
- 8. Some commands have NO body while others have an OPTIONAL or REQUIRED body
35
- a. Assume .cmd1 definition forbids a body (then a body is an error)
36
- .cmd1 # may NOT have a body
37
- b. Assume .cmd2 definition PERMITS a body
38
- .cmd2 # may or MAY NOT have body/.end
39
- c. Assume .cmd3 definition REQUIRES a body
40
- .cmd3 # REQUIRES a body/.end
41
- . stuff...
42
- .end
43
-
44
- 9. Inside a body:
45
- a. Leading dot has no special meaning (though the associated method may parse it!)
46
- b. BUG? Currently leading dot is a comment INSIDE a body?
47
- c. No leading char is special (though the associated method may parse it!)
48
- d. No trailing #-comments (though the associated method may parse it!)
49
- e. ?? We should or shouldn't look for variables/functions? or make it an option?
50
- f. .end may naturally not be used (but see .raw where it may)
51
-
52
- 10. The args accessor is a simple array of strings
53
- a. there is also raw_args (without variables/functions, etc.)
54
- b. Much of this HAS NOT been thought through yet!
55
-
56
- =end
57
-
58
- class Livetext::CmdData
59
-
60
- attr_reader :data, :args, :nargs, :arity, :comment, :raw # , ...?
61
-
62
- def initialize(data, body: false, arity: :N) # FIXME maybe just add **options ??
63
- # arity: (num) fixed number 0 or more
64
- # :N arbitrary number
65
- # n1..n2 range
66
- # body: true => this command has a body + .end
67
- # how raw is raw?
68
- # remove comment - always/sometimes/never?
69
- # interpolate - always/sometimes/never?
70
- # interpolate inside body??
71
- @data = data.dup # comment? vars? funcs?
72
- @raw = data.dup # comment? vars? funcs?
73
- @args = data.split # simple array
74
- @nargs = nargs # not really "needed"
75
- check_num_args(nargs)
76
- # @varfunc = Livetext.interpolate(data.dup)
77
- end
78
-
79
- def check_num_args(num)
80
- num_range = /(\d{0,2})(\.\.)(\d{0,2})/ # Not "really" right...
81
- min, max = 0, 9999
82
- mdata = num_range.match(@nargs).to_a
83
- bad_args = nil
84
- case
85
- when @nargs == ":N" # arbitrary
86
- # max already set
87
- when mdata[2] == ".." # range: 4..6 1.. ..4
88
- vmin, vmax = mdata.values_at(1, 2)
89
- min = Integer(vmin) unless vmin.empty?
90
- max = Integer(vmax) unless vmax.empty?
91
- min, max = Integer(min), Integer(max)
92
- when %r[^\d+$] =~ num
93
- min = max = Integer(num) # can raise error
94
- else
95
- raise "Invalid value or range '#{num.inspect}'"
96
- end
97
-
98
- bad_args = @args.size.between?(min, max)
99
- raise "Expected #{num} args but found #{@args.size}!" if bad_args
100
- end
101
-
102
- def strip_comments(str)
103
- str.sub!(/ # .*/, "")
104
- end
105
-
106
- end
File without changes
File without changes
File without changes
File without changes