livetext 0.9.27 → 0.9.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.lt3 +3 -2
- data/lib/livetext/expansion.rb +106 -0
- data/lib/livetext/formatter.rb +104 -0
- data/lib/livetext/functions.rb +9 -0
- data/lib/livetext/helpers.rb +23 -18
- data/lib/livetext/html.rb +73 -0
- data/lib/livetext/more.rb +24 -4
- data/lib/livetext/parser/general.rb +1 -1
- data/lib/livetext/parser/set.rb +10 -3
- data/lib/livetext/processor.rb +5 -0
- data/lib/livetext/standard.rb +16 -6
- data/lib/livetext/userapi.rb +39 -16
- data/lib/livetext/version.rb +1 -1
- data/lib/livetext.rb +1 -1
- data/plugin/bootstrap_menu.rb +140 -0
- data/plugin/misc/navbar.rb +162 -0
- data/test/snapshots/basic_formatting/expected-output.txt +1 -2
- data/test/snapshots/{basic_formatting/actual-error.txt → bootstrap_menu/expected-error.txt} +0 -0
- data/test/snapshots/bootstrap_menu/expected-output.txt +4 -0
- data/test/snapshots/bootstrap_menu/source.lt3 +17 -0
- data/test/snapshots/subset.txt +50 -48
- data/test/unit/all.rb +2 -2
- data/test/unit/lineparser.rb +1 -1
- data/test/unit/parser/general.rb +2 -2
- data/test/unit/parser/set.rb +0 -9
- metadata +9 -32
- data/lib/livetext/funcall.rb +0 -87
- data/lib/livetext/lineparser.rb +0 -575
- data/test/snapshots/basic_formatting/actual-output.txt +0 -13
- data/test/snapshots/basic_formatting/err-sdiff.txt +0 -1
- data/test/snapshots/basic_formatting/out-sdiff.txt +0 -14
- data/test/snapshots/functions/actual-error.txt +0 -19
- data/test/snapshots/functions/actual-output.txt +0 -0
- data/test/snapshots/functions/err-sdiff.txt +0 -20
- data/test/snapshots/import_bookish/toc.tmp +0 -0
- data/test/snapshots/mixin_bookish/toc.tmp +0 -0
- data/test/snapshots/more_complex_vars/actual-error.txt +0 -0
- data/test/snapshots/more_complex_vars/actual-output.txt +0 -4
- data/test/snapshots/more_complex_vars/err-sdiff.txt +0 -1
- data/test/snapshots/more_complex_vars/out-sdiff.txt +0 -5
- data/test/snapshots/more_functions/actual-error.txt +0 -19
- data/test/snapshots/more_functions/actual-output.txt +0 -0
- data/test/snapshots/more_functions/err-sdiff.txt +0 -20
- data/test/snapshots/raw_lines/actual-error.txt +0 -22
- data/test/snapshots/raw_lines/actual-output.txt +0 -0
- data/test/snapshots/raw_lines/err-sdiff.txt +0 -23
- data/test/snapshots/simple_vars/actual-error.txt +0 -0
- data/test/snapshots/simple_vars/actual-output.txt +0 -6
- data/test/snapshots/simple_vars/err-sdiff.txt +0 -1
- data/test/snapshots/simple_vars/out-sdiff.txt +0 -7
- data/test/snapshots/var_into_func/actual-error.txt +0 -19
- data/test/snapshots/var_into_func/actual-output.txt +0 -0
- data/test/snapshots/var_into_func/err-sdiff.txt +0 -20
- data/test/snapshots/var_into_func/out-sdiff.txt +0 -17
- data/test/unit/tokenizer.rb +0 -535
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee3796664666616d6b5428f4b27f81c3f902171fc8afc8fd351631c6c774e730
|
4
|
+
data.tar.gz: 5dd5250915ef13d930dca6b147e84b5e04e42d1a7b9c0f4b1e95d510ea49e476
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0e81ca1d3990468ae49f3c5e23ab608160f7db301f692757200fe57b5434f125bd83b3a7af80dd22ea8cc278972dcb39fe3b408f3a800871f3fb243e6c3639c
|
7
|
+
data.tar.gz: 4bc7641f62f63215fbcf52192a74956991e540a2282922da21a5b0ea2a5d959420a9226c52745c635fc91521d860921b4d7d69defb8b540868d73df9b8fbfd99
|
data/README.lt3
CHANGED
@@ -7,8 +7,9 @@
|
|
7
7
|
|
8
8
|
*[This README is currently mangled. Fixes coming soon!]
|
9
9
|
|
10
|
-
Livetext is simply a tool for transforming text
|
11
|
-
has commands embedded in it, and the output is dependent
|
10
|
+
Livetext is simply a tool for transforming text another format which may be HTML or some arbitrary
|
11
|
+
format (text or otherwise). The source file has commands embedded in it, and the output is dependent
|
12
|
+
on those commands.
|
12
13
|
|
13
14
|
Why is this special? It's very flexible, very extensible, and it's extensible _[in Ruby].
|
14
15
|
|
@@ -0,0 +1,106 @@
|
|
1
|
+
|
2
|
+
class Livetext::Expansion
|
3
|
+
|
4
|
+
Ident = "[[:alpha:]]([[:alnum:]]|_)*"
|
5
|
+
Dotted = "#{Ident}(\\.#{Ident})*"
|
6
|
+
Func = "\\$\\$"
|
7
|
+
Var = "\\$"
|
8
|
+
Lbrack = "\\["
|
9
|
+
Colon = ":"
|
10
|
+
|
11
|
+
def initialize(instance)
|
12
|
+
@live = instance
|
13
|
+
end
|
14
|
+
|
15
|
+
def format(line) # new/experimental
|
16
|
+
return "" if line == "\n" || line.nil?
|
17
|
+
formatted = Formatter.format(line)
|
18
|
+
with_vars = expand_variables(formatted)
|
19
|
+
with_func = expand_function_calls(with_vars)
|
20
|
+
end
|
21
|
+
|
22
|
+
def expand_variables(str)
|
23
|
+
rx = Regexp.compile("(?<result>" + Var + Dotted + ")")
|
24
|
+
enum = str.each_char
|
25
|
+
buffer = ""
|
26
|
+
loop do |i|
|
27
|
+
case # var or func or false alarm
|
28
|
+
when str.empty? # end of string
|
29
|
+
break
|
30
|
+
when str.slice(0..1) == "$$" # func?
|
31
|
+
buffer << str.slice!(0..1)
|
32
|
+
when str.slice(0) == "$" # var?
|
33
|
+
vmatch = rx.match(str)
|
34
|
+
if vmatch.nil?
|
35
|
+
buffer << str.slice!(0)
|
36
|
+
next
|
37
|
+
end
|
38
|
+
vname = vmatch["result"]
|
39
|
+
str.sub!(vname, "")
|
40
|
+
vsym = vname[1..-1].to_sym
|
41
|
+
vars = @live.vars
|
42
|
+
buffer << vars.get(vsym)
|
43
|
+
else # other
|
44
|
+
buffer << str.slice!(0)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
buffer
|
48
|
+
end
|
49
|
+
|
50
|
+
def funcall(name, param)
|
51
|
+
err = "[Error evaluating $$#{name}(#{param})]"
|
52
|
+
name = name.gsub(/\./, "__")
|
53
|
+
return if self.send?(name, param)
|
54
|
+
fobj = ::Livetext::Functions.new
|
55
|
+
result = fobj.send(name, param) rescue err
|
56
|
+
result.to_s
|
57
|
+
end
|
58
|
+
|
59
|
+
def expand_function_calls(str)
|
60
|
+
# Assume variables already resolved
|
61
|
+
pat1 = "(?<result>" + Func + Dotted + ")"
|
62
|
+
colon = ":"
|
63
|
+
lbrack = "\\["
|
64
|
+
rbrack = "\\]"
|
65
|
+
space_eol = "( |$)"
|
66
|
+
prx1 = "(?<param>[^ ]+)"
|
67
|
+
prx2 = "(?<param>.+)"
|
68
|
+
pat2 = "(?<full_param>#{colon}#{prx1})"
|
69
|
+
pat3 = "(?<full_param>#{lbrack}#{prx2}#{rbrack})"
|
70
|
+
rx = Regexp.compile("#{pat1}(#{pat2}|#{pat3})?")
|
71
|
+
|
72
|
+
buffer = ""
|
73
|
+
loop do |i|
|
74
|
+
case # Var or Func or false alarm
|
75
|
+
when str.nil?
|
76
|
+
return buffer
|
77
|
+
when str.empty? # end of string
|
78
|
+
break
|
79
|
+
when str.slice(0..1) == "$$" # Func?
|
80
|
+
fmatch = rx.match(str)
|
81
|
+
fname = fmatch["result"] # includes $$
|
82
|
+
param = fmatch["param"] # may be nil
|
83
|
+
full = fmatch["full_param"]
|
84
|
+
fsym = fname[2..-1] # no $$
|
85
|
+
=begin
|
86
|
+
puts "rx = #{rx.inspect}"
|
87
|
+
puts "fmatch = #{fmatch.inspect}"
|
88
|
+
puts "fname = #{fname.inspect}"
|
89
|
+
puts "param = #{param.inspect}"
|
90
|
+
puts "full = #{full.inspect}"
|
91
|
+
puts "fsym = #{fsym.inspect}"
|
92
|
+
=end
|
93
|
+
str.sub!(fname, "")
|
94
|
+
str.sub!(full, "") if full
|
95
|
+
retval = funcall(fsym, param)
|
96
|
+
# puts "retval = #{retval.inspect}"
|
97
|
+
buffer << retval
|
98
|
+
else # other
|
99
|
+
char = str.slice!(0)
|
100
|
+
buffer << char
|
101
|
+
end
|
102
|
+
end
|
103
|
+
buffer
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Formatter
|
2
|
+
|
3
|
+
Start = /(?<start>(^| ))/
|
4
|
+
Stop = /(?<stop> |$)/
|
5
|
+
|
6
|
+
def self.make_regex(sigil, cdata, stop = Stop)
|
7
|
+
rx = /#{Start}#{sigil}#{cdata}#{stop}/
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.iterate(str, rx, tag)
|
11
|
+
loop do
|
12
|
+
str, more = make_string(str, rx, tag)
|
13
|
+
break unless more
|
14
|
+
end
|
15
|
+
str
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.double(str, char, tag)
|
19
|
+
cdata = /(?<cdata>[^ \.,]*?)/
|
20
|
+
stop = /(?<stop>[\.,]|$)/
|
21
|
+
sigil = Regexp.escape(char+char)
|
22
|
+
rx = make_regex(sigil, cdata, stop)
|
23
|
+
str = iterate(str, rx, tag)
|
24
|
+
str
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.single(str, char, tag)
|
28
|
+
cdata = /((?<cdata>[^$ \[\*][^ ]*))/
|
29
|
+
sigil = Regexp.escape(char)
|
30
|
+
rx = make_regex(sigil, cdata)
|
31
|
+
str = iterate(str, rx, tag)
|
32
|
+
str
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.bracket(str, char, tag)
|
36
|
+
cdata = /(?<cdata>[^\]]*)\]/
|
37
|
+
stop = /(?<stop> |$)/
|
38
|
+
sigil = Regexp.escape(char + "[")
|
39
|
+
rx = make_regex(sigil, cdata, stop)
|
40
|
+
str = iterate(str, rx, tag)
|
41
|
+
str
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.make_string(str, rx, tag)
|
45
|
+
md = rx.match(str)
|
46
|
+
return [str, false] if md.nil?
|
47
|
+
start, cdata, stop = md.values_at(:start, :cdata, :stop)
|
48
|
+
str = str.sub(rx, start + "<#{tag}>" + cdata + "<\/#{tag}>" + stop)
|
49
|
+
[str, true]
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.handle(str, char, tag)
|
53
|
+
s2 = double(str, char, tag) # in this order...
|
54
|
+
s2 = single(s2, char, tag)
|
55
|
+
s2 = bracket(s2, char, tag)
|
56
|
+
s2
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.format(str)
|
60
|
+
s2 = str.chomp
|
61
|
+
s2 = handle(s2, "*", "b")
|
62
|
+
s2 = handle(s2, "_", "i")
|
63
|
+
s2 = handle(s2, "`", "tt")
|
64
|
+
s2 = handle(s2, "~", "strike")
|
65
|
+
s2
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
if $0 == __FILE__
|
70
|
+
# str = "**bold up front... This is **bold, __italic, and ``code."
|
71
|
+
str = "*bold and *bold and **more, and even *[more boldface] and *[still more] "
|
72
|
+
max = str.length
|
73
|
+
# str = "*bold "
|
74
|
+
s2 = Formatter.format(str)
|
75
|
+
printf "%-#{max}s => %-#{max}s\n", str.inspect, s2.inspect
|
76
|
+
exit
|
77
|
+
|
78
|
+
strings = ["*bold",
|
79
|
+
" *bold",
|
80
|
+
" *bold ",
|
81
|
+
"**bold.",
|
82
|
+
"**bold,",
|
83
|
+
"**bold",
|
84
|
+
" **bold.",
|
85
|
+
" **bold,",
|
86
|
+
" **bold",
|
87
|
+
" **bold. ",
|
88
|
+
" **bold, ",
|
89
|
+
" **bold ",
|
90
|
+
"*[fiat lux]",
|
91
|
+
" *[fiat lux]",
|
92
|
+
" *[fiat lux] ",
|
93
|
+
" *[fiat lux"
|
94
|
+
]
|
95
|
+
|
96
|
+
max = strings.max_by {|s| s.length }
|
97
|
+
max = max.length + 2
|
98
|
+
|
99
|
+
strings.each do |str|
|
100
|
+
s2 = Formatter.format(str)
|
101
|
+
printf "%-#{max}s => %-#{max}s\n", str.inspect, s2.inspect
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
data/lib/livetext/functions.rb
CHANGED
@@ -26,6 +26,15 @@ class Livetext::Functions
|
|
26
26
|
"[Error evaluating $$isqrt(#{arg})]"
|
27
27
|
end
|
28
28
|
|
29
|
+
def reverse(param=nil) # again, just for testing
|
30
|
+
arg = param
|
31
|
+
if arg.nil? || arg.empty?
|
32
|
+
return "(reverse: No parameter)"
|
33
|
+
else
|
34
|
+
return arg.reverse
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
29
38
|
def date(param=nil)
|
30
39
|
Time.now.strftime("%F")
|
31
40
|
end
|
data/lib/livetext/helpers.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
|
2
2
|
require_relative 'global_helpers'
|
3
|
+
require_relative 'expansion'
|
3
4
|
|
4
5
|
module Livetext::Helpers
|
5
6
|
|
@@ -55,10 +56,10 @@ module Livetext::Helpers
|
|
55
56
|
base = "#{name}#{ext}"
|
56
57
|
paths.each do |path|
|
57
58
|
file = path + base
|
58
|
-
::Livetext::TTY.puts " Checking: #{file}"
|
59
|
+
# ::Livetext::TTY.puts " Checking: #{file}"
|
59
60
|
return file if File.exist?(file)
|
60
61
|
end
|
61
|
-
::Livetext::TTY.puts " ...oops"
|
62
|
+
# ::Livetext::TTY.puts " ...oops"
|
62
63
|
return nil
|
63
64
|
end
|
64
65
|
|
@@ -115,15 +116,16 @@ module Livetext::Helpers
|
|
115
116
|
success
|
116
117
|
end
|
117
118
|
|
118
|
-
def invoke_dotcmd(name)
|
119
|
+
def invoke_dotcmd(name, *args)
|
119
120
|
# FIXME Add cmdargs stuff... depends on name, etc.
|
120
|
-
retval = @main.send(name)
|
121
|
+
retval = @main.send(name, *args)
|
121
122
|
retval
|
122
123
|
rescue => err
|
123
124
|
graceful_error(err)
|
124
125
|
end
|
125
126
|
|
126
127
|
def handle_dotcmd(line, indent = 0)
|
128
|
+
# FIXME api.data is broken
|
127
129
|
indent = @indentation.last # top of stack
|
128
130
|
line = line.sub(/# .*$/, "") # FIXME Could be problematic?
|
129
131
|
name = get_name(line)
|
@@ -161,11 +163,13 @@ module Livetext::Helpers
|
|
161
163
|
return File.exist?(file)
|
162
164
|
end
|
163
165
|
|
166
|
+
def read_variables(file)
|
167
|
+
pairs = File.readlines(file).map {|x| x.chomp.split }
|
168
|
+
@api.setvars(pairs)
|
169
|
+
end
|
170
|
+
|
164
171
|
def set_variables(pairs)
|
165
|
-
pairs
|
166
|
-
var, value = *pair
|
167
|
-
@parent.setvar(var, value)
|
168
|
-
end
|
172
|
+
@api.setvars(pairs)
|
169
173
|
end
|
170
174
|
|
171
175
|
def grab_file(fname)
|
@@ -215,26 +219,27 @@ module Livetext::Helpers
|
|
215
219
|
end
|
216
220
|
|
217
221
|
def setvar(var, val)
|
218
|
-
|
219
|
-
|
220
|
-
Livetext::Vars[
|
221
|
-
|
222
|
-
@_vars[
|
222
|
+
api.setvar(var, val)
|
223
|
+
# str, sym = var.to_s, var.to_sym
|
224
|
+
# Livetext::Vars[str] = val
|
225
|
+
# Livetext::Vars[sym] = val
|
226
|
+
# @_vars[str] = val
|
227
|
+
# @_vars[sym] = val
|
223
228
|
end
|
224
229
|
|
225
230
|
def setfile(file)
|
226
231
|
if file
|
227
|
-
setvar(:File, file)
|
232
|
+
api.setvar(:File, file)
|
228
233
|
dir = File.dirname(File.expand_path(file))
|
229
|
-
setvar(:FileDir, dir)
|
234
|
+
api.setvar(:FileDir, dir)
|
230
235
|
else
|
231
|
-
setvar(:File, "[no file]")
|
232
|
-
setvar(:FileDir, "[no dir]")
|
236
|
+
api.setvar(:File, "[no file]")
|
237
|
+
api.setvar(:FileDir, "[no dir]")
|
233
238
|
end
|
234
239
|
end
|
235
240
|
|
236
241
|
def setfile!(file) # FIXME why does this variant exist?
|
237
|
-
setvar(:File, file)
|
242
|
+
api.setvar(:File, file)
|
238
243
|
end
|
239
244
|
|
240
245
|
end
|
data/lib/livetext/html.rb
CHANGED
@@ -29,5 +29,78 @@ module HTMLHelper
|
|
29
29
|
end
|
30
30
|
[open, close]
|
31
31
|
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class HTML
|
35
|
+
|
36
|
+
def initialize(api)
|
37
|
+
@api = api
|
38
|
+
@indent = 0
|
39
|
+
end
|
40
|
+
|
41
|
+
def indented
|
42
|
+
" "*@indent
|
43
|
+
end
|
44
|
+
|
45
|
+
def indent(which)
|
46
|
+
case which
|
47
|
+
when :in, :right
|
48
|
+
@indent += 2
|
49
|
+
when :out, :left
|
50
|
+
@indent -= 2
|
51
|
+
else
|
52
|
+
abort "indent(#{which}) is nonsense"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def nav(**details, &block)
|
57
|
+
wrap(:nav, **details, &block)
|
58
|
+
end
|
32
59
|
|
60
|
+
def div(**details, &block)
|
61
|
+
wrap(:div, **details, &block)
|
62
|
+
end
|
63
|
+
|
64
|
+
def ul(**details, &block)
|
65
|
+
wrap(:ul, **details, &block)
|
66
|
+
end
|
67
|
+
|
68
|
+
def li(**details, &block)
|
69
|
+
wrap(:li, **details, &block)
|
70
|
+
end
|
71
|
+
|
72
|
+
def api
|
73
|
+
@api
|
74
|
+
end
|
75
|
+
|
76
|
+
def open_close_tags(*tags)
|
77
|
+
open, close = "", ""
|
78
|
+
tags.each do |tag|
|
79
|
+
open << "<#{tag}>"
|
80
|
+
close.prepend("</#{tag}>")
|
81
|
+
end
|
82
|
+
[open, close]
|
83
|
+
end
|
84
|
+
|
85
|
+
def wrap(*tags, **extras) # helper
|
86
|
+
open, close = open_close_tags(*tags)
|
87
|
+
extras.each_pair do |name, value|
|
88
|
+
open.sub!(">", " #{name}='#{value}'>")
|
89
|
+
end
|
90
|
+
api.out indented + open
|
91
|
+
indent(:in)
|
92
|
+
yield
|
93
|
+
indent(:out)
|
94
|
+
api.out indented + close
|
95
|
+
end
|
96
|
+
|
97
|
+
def tag(*tags, cdata: "", **extras) # helper
|
98
|
+
open, close = open_close_tags(*tags)
|
99
|
+
extras.each_pair do |name, value|
|
100
|
+
open.sub!(">", " #{name}='#{value}'>")
|
101
|
+
end
|
102
|
+
str = indented + open + cdata + close
|
103
|
+
str
|
104
|
+
end
|
33
105
|
end
|
106
|
+
|
data/lib/livetext/more.rb
CHANGED
@@ -6,6 +6,7 @@ class Livetext
|
|
6
6
|
include Helpers
|
7
7
|
|
8
8
|
class Variables
|
9
|
+
attr_reader :vars
|
9
10
|
def initialize(hash = {})
|
10
11
|
@vars = {}
|
11
12
|
hash.each_pair {|k, v| @vars[k.to_sym] = v }
|
@@ -18,6 +19,21 @@ class Livetext
|
|
18
19
|
def []=(var, value)
|
19
20
|
@vars[var.to_sym] = value
|
20
21
|
end
|
22
|
+
|
23
|
+
def get(var)
|
24
|
+
@vars[var.to_sym] || "[#{var} is undefined]"
|
25
|
+
end
|
26
|
+
|
27
|
+
def set(var, value)
|
28
|
+
@vars[var.to_sym] = value.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
def setvars(pairs)
|
32
|
+
pairs = pairs.to_a if pairs.is_a?(Hash)
|
33
|
+
pairs.each do |var, value|
|
34
|
+
api.setvar(var, value)
|
35
|
+
end
|
36
|
+
end
|
21
37
|
end
|
22
38
|
|
23
39
|
Vars = Variables.new
|
@@ -37,8 +53,10 @@ class Livetext
|
|
37
53
|
end
|
38
54
|
|
39
55
|
def self.interpolate(str)
|
40
|
-
|
41
|
-
|
56
|
+
expand = Livetext::Expansion.new(self)
|
57
|
+
str2 = expand.expand_variables(str)
|
58
|
+
str3 = expand.expand_function_calls(str2)
|
59
|
+
str3
|
42
60
|
end
|
43
61
|
|
44
62
|
def self.customize(mix: [], call: [], vars: {})
|
@@ -47,7 +65,8 @@ class Livetext
|
|
47
65
|
call = Array(call)
|
48
66
|
mix.each {|lib| obj.mixin(lib) }
|
49
67
|
call.each {|cmd| obj.main.send(cmd[1..-1]) } # ignores leading dot, no param
|
50
|
-
vars.each_pair {|var, val| obj.setvar(var, val.to_s) }
|
68
|
+
# vars.each_pair {|var, val| obj.setvar(var, val.to_s) }
|
69
|
+
api.setvars(vars)
|
51
70
|
obj
|
52
71
|
end
|
53
72
|
|
@@ -88,7 +107,8 @@ class Livetext
|
|
88
107
|
call = Array(call)
|
89
108
|
mix.each {|lib| mixin(lib) }
|
90
109
|
call.each {|cmd| @main.send(cmd[1..-1]) } # ignores leading dot, no param
|
91
|
-
vars.each_pair {|var, val| @api.
|
110
|
+
# vars.each_pair {|var, val| @api.set(var, val.to_s) }
|
111
|
+
api.setvars(vars)
|
92
112
|
self
|
93
113
|
end
|
94
114
|
|
@@ -24,7 +24,7 @@ class Livetext::ParseGeneral < StringParser
|
|
24
24
|
lines.each do |line|
|
25
25
|
next if line.strip.empty?
|
26
26
|
var, value = line.split(" ", 2)
|
27
|
-
val = Livetext.interpolate(value)
|
27
|
+
# val = Livetext.interpolate(value)
|
28
28
|
var = prefix + "." + var if prefix
|
29
29
|
pairs << [var, value]
|
30
30
|
end
|
data/lib/livetext/parser/set.rb
CHANGED
@@ -53,8 +53,9 @@ class Livetext::ParseSet < StringParser
|
|
53
53
|
var = get_var
|
54
54
|
skip_equal
|
55
55
|
value = get_value
|
56
|
-
value = Livetext.interpolate(value)
|
56
|
+
# value = Livetext.interpolate(value)
|
57
57
|
pair = [var, value]
|
58
|
+
Livetext::Vars[var.to_sym] = value
|
58
59
|
pair
|
59
60
|
end
|
60
61
|
|
@@ -115,10 +116,11 @@ class Livetext::ParseSet < StringParser
|
|
115
116
|
end
|
116
117
|
|
117
118
|
def unquoted_value
|
118
|
-
char = nil
|
119
119
|
value = ""
|
120
|
+
char = nil
|
120
121
|
loop do
|
121
122
|
char = peek
|
123
|
+
break if char.nil?
|
122
124
|
break if eos?
|
123
125
|
break if char == " " || char == ","
|
124
126
|
value << char
|
@@ -133,7 +135,12 @@ class Livetext::ParseSet < StringParser
|
|
133
135
|
|
134
136
|
def get_value
|
135
137
|
char = peek
|
136
|
-
|
138
|
+
flag = quote?(char)
|
139
|
+
if flag
|
140
|
+
value = quoted_value
|
141
|
+
else
|
142
|
+
value = unquoted_value
|
143
|
+
end
|
137
144
|
value
|
138
145
|
end
|
139
146
|
end
|
data/lib/livetext/processor.rb
CHANGED
@@ -35,12 +35,17 @@ class Processor
|
|
35
35
|
@indentation = @parent.indentation
|
36
36
|
@_mixins = []
|
37
37
|
@_imports = []
|
38
|
+
@html = HTML.new(@parent.api)
|
38
39
|
end
|
39
40
|
|
40
41
|
def api
|
41
42
|
@parent.api # FIXME Is this weird??
|
42
43
|
end
|
43
44
|
|
45
|
+
def html
|
46
|
+
@html
|
47
|
+
end
|
48
|
+
|
44
49
|
def output=(io)
|
45
50
|
@output = io
|
46
51
|
end
|
data/lib/livetext/standard.rb
CHANGED
@@ -45,6 +45,12 @@ module Livetext::Standard
|
|
45
45
|
api.optional_blank_line
|
46
46
|
end
|
47
47
|
|
48
|
+
# def setvars(pairs)
|
49
|
+
# pairs.each do |var, value|
|
50
|
+
# api.setvar(var, value)
|
51
|
+
# end
|
52
|
+
# end
|
53
|
+
|
48
54
|
def backtrace(args = nil, body = nil)
|
49
55
|
@backtrace = onoff(api.args.first)
|
50
56
|
api.optional_blank_line
|
@@ -159,9 +165,9 @@ module Livetext::Standard
|
|
159
165
|
end
|
160
166
|
|
161
167
|
def set(args = nil, body = nil)
|
162
|
-
line = api.data.chomp
|
168
|
+
line = api.args.join(" ") # data.chomp
|
163
169
|
pairs = Livetext::ParseSet.new(line).parse
|
164
|
-
|
170
|
+
api.setvars(pairs)
|
165
171
|
api.optional_blank_line
|
166
172
|
end
|
167
173
|
|
@@ -178,7 +184,8 @@ module Livetext::Standard
|
|
178
184
|
lines = api.body
|
179
185
|
end
|
180
186
|
pairs = Livetext::ParseGeneral.parse_vars(lines, prefix: nil)
|
181
|
-
|
187
|
+
STDERR.puts "! pairs = #{pairs.inspect}"
|
188
|
+
api.setvars(pairs)
|
182
189
|
api.optional_blank_line
|
183
190
|
end
|
184
191
|
|
@@ -193,7 +200,8 @@ module Livetext::Standard
|
|
193
200
|
lines = api.body
|
194
201
|
end
|
195
202
|
pairs = Livetext::ParseGeneral.parse_vars(lines, prefix: nil)
|
196
|
-
|
203
|
+
STDERR.puts "pairs = #{pairs.inspect}"
|
204
|
+
api.setvars(pairs)
|
197
205
|
api.optional_blank_line
|
198
206
|
end
|
199
207
|
|
@@ -207,7 +215,7 @@ module Livetext::Standard
|
|
207
215
|
end
|
208
216
|
indent = @parent.indentation.last
|
209
217
|
indented = " " * indent
|
210
|
-
api.
|
218
|
+
api.set(var, rhs.chomp)
|
211
219
|
api.optional_blank_line
|
212
220
|
end
|
213
221
|
|
@@ -271,7 +279,9 @@ module Livetext::Standard
|
|
271
279
|
end
|
272
280
|
|
273
281
|
def r(args = nil, body = nil)
|
274
|
-
|
282
|
+
# FIXME api.data is broken
|
283
|
+
# api.out api.data # No processing at all
|
284
|
+
api.out api.args.join(" ")
|
275
285
|
api.optional_blank_line
|
276
286
|
end
|
277
287
|
|