livetext 0.8.82 → 0.8.83

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: 7041923b573f219f9840264ca00ae087c195e8bb40740b99708f1dd997faebdd
4
- data.tar.gz: a64013d7d8e8028628bd0ef460e51dcfc98769e53fa76bcd9fb6f35f4638b468
3
+ metadata.gz: 236395813414f363d90340dc5e0977daee51ba47bc758d613ed3fa2b419e2cfd
4
+ data.tar.gz: 70c2eab78b98933073b13c95c2b4855803573731ca151a4e07faaa618233f125
5
5
  SHA512:
6
- metadata.gz: d66daf9414ba6168414d115e86d7695fe9f4f5bca8f6d04960b3c7b95dbb79f9ac1beb8a079f3c75e3501c0a67745ccd565339a6e10b41c479d499aebf3b6e57
7
- data.tar.gz: 8b2fe0da41d71a410e0b0386cf2f7b344c459f1619cde8df33729f6f63455465bf4f9d1804dc2ecb893544e62b819491fef56e8606339dfa0fe7f4a8cf4b4275
6
+ metadata.gz: 2017af970244166cdec4d15e08cf3e76fe86b1cef4f344386ff3023e78576dc6ddc245b49fe7f27f4645c67a19f154ca594758e83a21097a6c5322e2bf45a70c
7
+ data.tar.gz: dd4d20cebb6f20e660898a03817987260d134a55b00885c97306f3e4f7c2c2caccdd6e3b5017b31326eeb8973a48cc27020e9508afbd5f2b4c2e11599a110ccd
data/bin/livetext CHANGED
@@ -79,7 +79,7 @@ loop do
79
79
  lib = ARGV.shift
80
80
  system("cp #{lib} #{Livetext::Path}/../plugin/")
81
81
  when Object
82
- x.process_file(arg, @backtrace)
82
+ x.process_file(arg) # , @backtrace)
83
83
  end
84
84
  end
85
85
 
data/lib/formatline.rb CHANGED
@@ -31,20 +31,18 @@ class FormatLine
31
31
  attr_reader :out
32
32
  attr_reader :tokenlist
33
33
 
34
- def initialize(line, context=nil)
35
- context ||= binding
36
- @context = context
34
+ def initialize(line)
37
35
  @line = line
38
36
  @i = -1
39
37
  @token = Null.dup
40
38
  @tokenlist = []
41
39
  end
42
40
 
43
- def self.parse!(line, context = nil)
41
+ def self.parse!(line)
44
42
  return nil if line.nil?
45
- x = self.new(line.chomp, context)
43
+ x = self.new(line.chomp)
46
44
  t = x.tokenize(line)
47
- x.evaluate # (context)
45
+ x.evaluate
48
46
  end
49
47
 
50
48
  def tokenize(line)
@@ -71,10 +69,9 @@ class FormatLine
71
69
  @tokenlist
72
70
  end
73
71
 
74
- def self.var_func_parse(str, context = nil)
72
+ def self.var_func_parse(str)
75
73
  return nil if str.nil?
76
- x = self.new(str.chomp, context)
77
- # t = x.tokenize(line)
74
+ x = self.new(str.chomp)
78
75
  x.grab
79
76
  loop do
80
77
  case x.curr
@@ -89,9 +86,7 @@ class FormatLine
89
86
  x.grab
90
87
  end
91
88
  x.add_token(:str)
92
- # built tokenlist
93
- # x.tokenlist.each {|pair| puts " #{pair.inspect}" }
94
- x.evaluate # (context)
89
+ x.evaluate
95
90
  end
96
91
 
97
92
  def embed(sym, str)
@@ -327,9 +322,7 @@ class FormatLine
327
322
  self.send("func_" + name.to_s, param)
328
323
  else
329
324
  fobj = ::Livetext::Functions.new
330
- ::Livetext::Functions.param = param # is this
331
- ::Livetext::Functions.context = @context # screwed up???
332
- fobj.send(name)
325
+ fobj.send(name, param)
333
326
  end
334
327
  result
335
328
  end
data/lib/functions.rb CHANGED
@@ -4,40 +4,35 @@ class Livetext::Functions # Functions will go here... user-def AND pre-def??
4
4
  Formats = ::Livetext::Standard::SimpleFormats
5
5
 
6
6
  @param = nil
7
- @context = nil
8
7
 
9
8
  class << self
10
- attr_accessor :param, :context
9
+ attr_accessor :param # kill this?
11
10
  end
12
11
 
13
- def date
12
+ def date(param=nil)
14
13
  Time.now.strftime("%F")
15
14
  end
16
15
 
17
- def time
16
+ def time(param=nil)
18
17
  Time.now.strftime("%T")
19
18
  end
20
19
 
21
- def link
22
- param = self.class.param
20
+ def link(param=nil)
23
21
  text, url = param.split("|", 2) # reverse these?
24
22
  "<a href='#{url}'>#{text}</a>"
25
23
  end
26
24
 
27
- def br
28
- n = self.class.param
29
- n = "1" if n.empty?
25
+ def br(n="1")
30
26
  n = n.to_i
31
27
  "<br>"*n
32
28
  end
33
29
 
34
- def yt
30
+ def yt(param)
35
31
  param = self.class.param
36
32
  "https://www.youtube.com/watch?v=#{param}"
37
33
  end
38
34
 
39
- def simple_format(*args)
40
- param = self.class.param
35
+ def simple_format(param=nil, *args)
41
36
  param ||= "NO PARAMETER"
42
37
  pairs = Formats.values_at(*args)
43
38
  str = param.dup
@@ -47,20 +42,20 @@ class Livetext::Functions # Functions will go here... user-def AND pre-def??
47
42
  str
48
43
  end
49
44
 
50
- def b; simple_format(:b); end
51
- def i; simple_format(:i); end
52
- def t; simple_format(:t); end
53
- def s; simple_format(:s); end
54
- def bi; simple_format(:b, :i); end
55
- def bt; simple_format(:b, :t); end
56
- def bs; simple_format(:b, :s); end
57
- def it; simple_format(:i, :t); end
58
- def is; simple_format(:i, :s); end
59
- def ts; simple_format(:t, :s); end
60
- def bit; simple_format(:b, :i, :t); end
61
- def bis; simple_format(:b, :i, :s); end
62
- def bts; simple_format(:b, :t, :s); end
63
- def its; simple_format(:i, :t, :s); end
64
- def bits; simple_format(:b, :i, :t, :s); end
45
+ def b(param=nil); simple_format(param, :b); end
46
+ def i(param=nil); simple_format(param, :i); end
47
+ def t(param=nil); simple_format(param, :t); end
48
+ def s(param=nil); simple_format(param, :s); end
49
+ def bi(param=nil); simple_format(param, :b, :i); end
50
+ def bt(param=nil); simple_format(param, :b, :t); end
51
+ def bs(param=nil); simple_format(param, :b, :s); end
52
+ def it(param=nil); simple_format(param, :i, :t); end
53
+ def is(param=nil); simple_format(param, :i, :s); end
54
+ def ts(param=nil); simple_format(param, :t, :s); end
55
+ def bit(param=nil); simple_format(param, :b, :i, :t); end
56
+ def bis(param=nil); simple_format(param, :b, :i, :s); end
57
+ def bts(param=nil); simple_format(param, :b, :t, :s); end
58
+ def its(param=nil); simple_format(param, :i, :t, :s); end
59
+ def bits(param=nil); simple_format(param, :b, :i, :t, :s); end
65
60
 
66
61
  end
data/lib/livetext.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class Livetext
2
- VERSION = "0.8.82"
2
+ VERSION = "0.8.83"
3
3
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
4
4
  end
5
5
 
@@ -20,7 +20,7 @@ TTY = ::File.open("/dev/tty", "w")
20
20
  class Livetext
21
21
  Vars = {}
22
22
 
23
- attr_reader :main, :context
23
+ attr_reader :main
24
24
  attr_accessor :no_puts
25
25
  attr_accessor :body, :indentation
26
26
 
@@ -44,9 +44,22 @@ class Livetext
44
44
  @indentation = [0]
45
45
  end
46
46
 
47
- def process_line(line, context=nil)
48
- context ||= binding
49
- @context = context
47
+ def _setvar(var, val)
48
+ str, sym = var.to_s, var.to_sym
49
+ Livetext::Vars[str] = val
50
+ Livetext::Vars[sym] = val
51
+ end
52
+
53
+ def _setfile(file)
54
+ _setvar(:File, file)
55
+ _setvar(:FileDir, File.expand_path(file))
56
+ end
57
+
58
+ def _setfile!(file)
59
+ _setvar(:File, file)
60
+ end
61
+
62
+ def process_line(line)
50
63
  nomarkup = true
51
64
  # FIXME inefficient
52
65
  comment = rx(Sigil, Livetext::Space) # apply these in order
@@ -64,11 +77,12 @@ class Livetext
64
77
  handle_dotcmd(line)
65
78
  indentation.pop
66
79
  else
67
- @main._passthru(line, context)
80
+ @main._passthru(line)
68
81
  end
69
82
  end
70
83
 
71
84
  def process(text)
85
+ _setfile!("(string)")
72
86
  enum = text.each_line
73
87
  front = text.match(/.*?\n/).to_a.first.chomp
74
88
  @main.source(enum, "STDIN: '#{front}...'", 0)
@@ -80,6 +94,7 @@ class Livetext
80
94
  end
81
95
 
82
96
  def transform(text)
97
+ _setfile!("(string)")
83
98
  @output = ::Livetext.output
84
99
  enum = text.each_line
85
100
  front = text.match(/.*?\n/).to_a.first.chomp
@@ -95,6 +110,7 @@ class Livetext
95
110
  ## FIXME don't need process *and* process_text
96
111
 
97
112
  def process_text(text)
113
+ _setfile!("(string)")
98
114
  text = text.split("\n") if text.is_a? String
99
115
  enum = text.each
100
116
  @backtrace = false
@@ -103,7 +119,7 @@ class Livetext
103
119
  loop do
104
120
  line = @main.nextline
105
121
  break if line.nil?
106
- process_line(line, context)
122
+ process_line(line)
107
123
  end
108
124
  val = @main.finalize if @main.respond_to? :finalize
109
125
  val
@@ -115,9 +131,8 @@ class Livetext
115
131
 
116
132
  ## FIXME process_file[!] should call process[_text]
117
133
 
118
- def process_file(fname, context=nil)
119
- context ||= binding
120
- @context = context
134
+ def process_file(fname)
135
+ _setfile(fname)
121
136
  raise "No such file '#{fname}' to process" unless File.exist?(fname)
122
137
  text = File.readlines(fname)
123
138
  enum = text.each
@@ -126,14 +141,14 @@ class Livetext
126
141
  loop do
127
142
  line = @main.nextline
128
143
  break if line.nil?
129
- # STDERR.puts "LINE: #{line.inspect}"
130
- process_line(line, context)
144
+ process_line(line)
131
145
  end
132
146
  val = @main.finalize if @main.respond_to? :finalize
133
147
  val
134
148
  end
135
149
 
136
150
  def process_file!(fname, backtrace=false)
151
+ _setfile(fname)
137
152
  raise "No such file '#{fname}' to process" unless File.exist?(fname)
138
153
  @main.output = StringIO.new
139
154
  enum = File.readlines(fname).each
data/lib/standard.rb CHANGED
@@ -42,7 +42,7 @@ module Livetext::Standard
42
42
  funcname = @_args[0]
43
43
  _error! "Illegal name '#{funcname}'" if _disallowed?(funcname)
44
44
  func_def = <<-EOS
45
- def #{funcname}(*args)
45
+ def #{funcname}(param)
46
46
  #{_body_text(true)}
47
47
  end
48
48
  EOS
@@ -161,8 +161,7 @@ module Livetext::Standard
161
161
  val = val[1..-2] if val[0] == ?" && val[-1] == ?"
162
162
  val = val[1..-2] if val[0] == ?' && val[-1] == ?'
163
163
  val = FormatLine.var_func_parse(val)
164
- Livetext::Vars[var.to_sym] = val
165
- Livetext::Vars[var] = val # FIXME
164
+ @parent._setvar(var, val)
166
165
  end
167
166
  _optional_blank_line
168
167
  end
@@ -186,8 +185,7 @@ module Livetext::Standard
186
185
  # end
187
186
  # s2 << line
188
187
  # end
189
- Livetext::Vars[var.to_sym] = s2
190
- Livetext::Vars[var] = s2.chomp # FIXME?
188
+ @parent._setvar(var, s2.chomp)
191
189
  _optional_blank_line
192
190
  end
193
191
 
@@ -198,6 +196,17 @@ module Livetext::Standard
198
196
  _optional_blank_line
199
197
  end
200
198
 
199
+ def inherit
200
+ file = @_args.first
201
+ upper = "../#{file}"
202
+ good = (File.exist?(upper) || File.exist?(file))
203
+ _error!("File #{file} not found (local or parent)") unless good
204
+
205
+ @parent.process_file(upper) if File.exist?(upper)
206
+ @parent.process_file(file) if File.exist?(file)
207
+ _optional_blank_line
208
+ end
209
+
201
210
  def include! # FIXME huh?
202
211
  file = @_args.first
203
212
  return unless File.exist?(file)
@@ -212,7 +221,14 @@ module Livetext::Standard
212
221
  file = "#{Plugins}/" + name.downcase + ".rb"
213
222
  return if @_mixins.include?(name)
214
223
  file = "./#{name}.rb" unless File.exist?(file)
215
- _check_existence(file, "No such mixin '#{name}'")
224
+ if File.exist?(file)
225
+ # Just keep going...
226
+ else
227
+ if File.expand_path(".") != "/"
228
+ Dir.chdir("..") { mixin }
229
+ return
230
+ end
231
+ end
216
232
 
217
233
  @_mixins << name
218
234
  meths = grab_file(file)
data/lib/userapi.rb CHANGED
@@ -74,7 +74,6 @@ module Livetext::UserAPI
74
74
  end_found = false
75
75
  loop do
76
76
  @line = nextline
77
- # puts "--- loop: @line = #{@line.inspect}"
78
77
  break if @line.nil?
79
78
  @line.chomp!
80
79
  if _end?(@line)
@@ -115,17 +114,17 @@ module Livetext::UserAPI
115
114
  str
116
115
  end
117
116
 
118
- def _format(line, context = nil)
117
+ def _format(line)
119
118
  return "" if line == "\n"
120
- line2 = FormatLine.parse!(line, context)
119
+ line2 = FormatLine.parse!(line)
121
120
  line.replace(line2) unless line.nil?
122
121
  line
123
122
  end
124
123
 
125
- def _passthru(line, context = nil)
124
+ def _passthru(line)
126
125
  return if @_nopass
127
126
  _out "<p>" if line == "\n" and ! @_nopara
128
- line = _format(line, context)
127
+ line = _format(line)
129
128
  _out line
130
129
  end
131
130
 
@@ -14,8 +14,7 @@ Functions can take a parameter in brackets
14
14
  (which it can parse itself as needed):
15
15
 
16
16
  .func mean
17
- list = self.class.param
18
- list = list.split(",").map(&:to_f)
17
+ list = param.split(",").map(&:to_f)
19
18
  sum = list.inject(0, :+)
20
19
  avg = sum / list.size.to_f
21
20
  avg.to_s
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.8.82
4
+ version: 0.8.83
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-11 00:00:00.000000000 Z
11
+ date: 2019-05-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A smart text processor extensible in Ruby
14
14
  email: rubyhacker@gmail.com