terrascript 0.1.3 → 0.1.4
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 +4 -4
- data/lib/terrascript.rb +42 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96f4fa5aed583625a0a2c81174e4d5e0c49355b7c99bed2f3c9a0f5b74f879de
|
4
|
+
data.tar.gz: a93586dcc687695c605ab8dfa34cad6830c30fd5a28b37a6f5995291250acfce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eac07d66a93a3cc33b14e5153a730e3df37b8f49e14799ddc749ef6cf1514c152809fb07188af6e440080d87bcd503a1edbffd49b01ff2d2d9791c084df9c184
|
7
|
+
data.tar.gz: e3418a950257c17ec385defdd7b985db8d868cba4faff9b0d16e30b6dafb1b809097a21741afa274fb733113e063d46de89553ade7ac099054fc1082bed4fac0
|
data/lib/terrascript.rb
CHANGED
@@ -1,12 +1,6 @@
|
|
1
|
-
|
1
|
+
require 'stringio'
|
2
2
|
|
3
3
|
class Transform
|
4
|
-
def transform
|
5
|
-
s = $stdout
|
6
|
-
$stdout = @out
|
7
|
-
eval("lambda { |#{@argName}|\n#{@body}\n}").call(@arg)
|
8
|
-
$stdout = s
|
9
|
-
end
|
10
4
|
|
11
5
|
def initialize(inFd, outFd = $stdout)
|
12
6
|
@in = inFd
|
@@ -15,6 +9,7 @@ class Transform
|
|
15
9
|
@argName = "block"
|
16
10
|
@arg = ""
|
17
11
|
@body = ""
|
12
|
+
@depth = 0
|
18
13
|
end
|
19
14
|
|
20
15
|
def process
|
@@ -23,11 +18,33 @@ class Transform
|
|
23
18
|
end
|
24
19
|
end
|
25
20
|
|
26
|
-
def
|
21
|
+
protected def transform
|
22
|
+
s = $stdout
|
23
|
+
$stdout = @out
|
24
|
+
|
25
|
+
# process nested directives
|
26
|
+
if @arg.include? "@inline"
|
27
|
+
stream = StringIO.new(@arg)
|
28
|
+
outStream = StringIO.new
|
29
|
+
Transform.new(stream, outStream).process
|
30
|
+
@arg = outStream.string
|
31
|
+
end
|
32
|
+
|
33
|
+
eval("lambda { |#{@argName}|\n#{@body}\n}").call(@arg)
|
34
|
+
|
35
|
+
$stdout = s
|
36
|
+
end
|
37
|
+
|
38
|
+
protected def keyword?(line, s)
|
39
|
+
line.lstrip.start_with? ("@" << s)
|
40
|
+
end
|
41
|
+
|
42
|
+
protected def processLine(line)
|
27
43
|
case @mode
|
28
44
|
|
29
45
|
when :read
|
30
|
-
|
46
|
+
case
|
47
|
+
when keyword?(line, "inline")
|
31
48
|
args = line.split(' ')
|
32
49
|
if !args[1].nil?
|
33
50
|
@argName = args[1]
|
@@ -38,11 +55,22 @@ class Transform
|
|
38
55
|
end
|
39
56
|
|
40
57
|
when :arg
|
41
|
-
|
42
|
-
|
43
|
-
@
|
44
|
-
|
45
|
-
|
58
|
+
case
|
59
|
+
when keyword?(line, "end")
|
60
|
+
if @depth == 0
|
61
|
+
transform
|
62
|
+
@arg = ""
|
63
|
+
@body = ""
|
64
|
+
@mode = :read
|
65
|
+
else
|
66
|
+
@depth = @depth - 1
|
67
|
+
@arg << line
|
68
|
+
end
|
69
|
+
|
70
|
+
when keyword?(line, "inline")
|
71
|
+
@depth = @depth + 1
|
72
|
+
@arg << line
|
73
|
+
|
46
74
|
else
|
47
75
|
@arg << line
|
48
76
|
end
|