liquidscript 0.10.2 → 0.10.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/liquidscript/compiler/icr/literals.rb +2 -2
- data/lib/liquidscript/generator/javascript/literals.rb +41 -15
- data/lib/liquidscript/version.rb +1 -1
- data/spec/fixtures/literals.generate.yml +3 -1
- data/spec/fixtures/loop.generate.yml +10 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 807022c4ded4e5b09cc881aa23814c524a8762e3
|
4
|
+
data.tar.gz: f798b85fe050801808dca1dcd75876dbcb1a6a75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9d7c9c7d1c98c9c291a69aa6ef59f0429dd06e72bb89357d2d1e3afdf039ad52f8260c449485a1a9281c9a062969365d2808ddcf30881aa7a7fa35d3d9a7574
|
7
|
+
data.tar.gz: ff62531459d871bdeabb0bf95b94f55ed96e0fdccdfda145cda0662cf7e9c17933fdf7c8dfc1811ae9fd3afe9111d609ba712eaff5b81ea7ee5b3cf3b3b10b2c
|
data/README.md
CHANGED
@@ -57,7 +57,7 @@ func()
|
|
57
57
|
|
58
58
|
## Contributing
|
59
59
|
|
60
|
-
1. Fork it (
|
60
|
+
1. Fork it (<http://github.com/medcat/liquidscript/fork>)
|
61
61
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
62
62
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
63
63
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -58,12 +58,12 @@ module Liquidscript
|
|
58
58
|
raise CompileError, "Expected `in', got #{content.value}"
|
59
59
|
end
|
60
60
|
|
61
|
-
obj =
|
61
|
+
obj = compile_vexpression
|
62
62
|
shift :rparen
|
63
63
|
|
64
64
|
v = set(ident)
|
65
65
|
body = _compile_block
|
66
|
-
code :for_in, v,
|
66
|
+
code :for_in, v, obj, body
|
67
67
|
end
|
68
68
|
|
69
69
|
def _compile_for_seg(first)
|
@@ -21,12 +21,20 @@ module Liquidscript
|
|
21
21
|
def generate_nrange(code)
|
22
22
|
start = code[1]
|
23
23
|
ending = code[2]
|
24
|
-
|
25
|
-
|
24
|
+
|
25
|
+
if (start.to_i - ending.to_i).abs > 50
|
26
|
+
generate_range(code, true)
|
27
|
+
elsif ending > start
|
28
|
+
buffer << "[" << (start..ending).to_a.join(', ') << "]"
|
29
|
+
else
|
30
|
+
buffer << "[" << (ending..start).to_a.reverse.join(', ') << "]"
|
31
|
+
end
|
26
32
|
end
|
27
33
|
|
28
|
-
def generate_range(code)
|
34
|
+
def generate_range(code, norep=false)
|
29
35
|
out = buffer
|
36
|
+
a = norep ? code[1] : replace(code[1])
|
37
|
+
b = norep ? code[2] : replace(code[2])
|
30
38
|
out << "(function(a, b) {\n" <<
|
31
39
|
indent! << "var out, i, t;\n" <<
|
32
40
|
indent << "out = [];\n" <<
|
@@ -38,8 +46,7 @@ module Liquidscript
|
|
38
46
|
unindent! << "};\n" <<
|
39
47
|
indent << "return t === undefined ?" <<
|
40
48
|
"out : out.reverse();\n" <<
|
41
|
-
unindent! << "})(" <<
|
42
|
-
replace(code[2]) << ")"
|
49
|
+
unindent! << "})(" << a << ", " << b << ")"
|
43
50
|
out
|
44
51
|
end
|
45
52
|
|
@@ -67,12 +74,14 @@ module Liquidscript
|
|
67
74
|
end
|
68
75
|
|
69
76
|
def generate_for_in(code)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
77
|
+
temporary_variable(2) do |v,d|
|
78
|
+
loop_body = buffer
|
79
|
+
loop_body << "var #{v}, #{d} = #{replace(code[2])};\n" <<
|
80
|
+
indent << "for(#{v} in #{d}) {\n" <<
|
81
|
+
indent! << "#{code[1].to_s} = #{d}[#{v}];\n"
|
82
|
+
insert_into(code[3], loop_body)
|
83
|
+
loop_body << unindent! << "}"
|
84
|
+
end
|
76
85
|
end
|
77
86
|
|
78
87
|
def generate_for_seg(code)
|
@@ -152,10 +161,6 @@ module Liquidscript
|
|
152
161
|
"#{replace(code[2])} #{op} #{replace(code[3])}"
|
153
162
|
end
|
154
163
|
|
155
|
-
#def generate_identifier(code)
|
156
|
-
# code.value
|
157
|
-
#end
|
158
|
-
|
159
164
|
def generate_variable(code)
|
160
165
|
code.to_s
|
161
166
|
end
|
@@ -207,6 +212,27 @@ module Liquidscript
|
|
207
212
|
|
208
213
|
function << indent_level << "}"
|
209
214
|
end
|
215
|
+
|
216
|
+
private
|
217
|
+
|
218
|
+
def temporary_variable(n)
|
219
|
+
return unless n > 0
|
220
|
+
variable = 'i'
|
221
|
+
yielded = []
|
222
|
+
@_temporary_variable ||= -1
|
223
|
+
@_temporary_variable += 1
|
224
|
+
@_temporary_variable.times { variable.succ! }
|
225
|
+
yielded << variable
|
226
|
+
|
227
|
+
n.times do
|
228
|
+
new_var = yielded.last.dup
|
229
|
+
@_temporary_variable += 1
|
230
|
+
yielded << yielded.last.succ
|
231
|
+
end
|
232
|
+
out = yield *yielded.map { |x| "_#{x}" }
|
233
|
+
@_temporary_variable -= n
|
234
|
+
out
|
235
|
+
end
|
210
236
|
end
|
211
237
|
end
|
212
238
|
end
|
data/lib/liquidscript/version.rb
CHANGED
@@ -2,6 +2,7 @@ data: |
|
|
2
2
|
object = { hello: "world" }
|
3
3
|
test = [1, 2]
|
4
4
|
range = 0x1..0x9
|
5
|
+
range2 = 10..1
|
5
6
|
regex = r/^\/test/
|
6
7
|
block = ///
|
7
8
|
^test # comment
|
@@ -9,10 +10,11 @@ data: |
|
|
9
10
|
regex == block
|
10
11
|
|
11
12
|
compiled: |
|
12
|
-
var object, test, range, regex, block;
|
13
|
+
var object, test, range, range2, regex, block;
|
13
14
|
object = { "hello": "world" };
|
14
15
|
test = [1, 2];
|
15
16
|
range = [0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9];
|
17
|
+
range2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1];
|
16
18
|
regex = /^\/test/;
|
17
19
|
block = /^test/;
|
18
20
|
regex === block;
|
@@ -9,8 +9,17 @@ data: |
|
|
9
9
|
console.log(t)
|
10
10
|
}
|
11
11
|
|
12
|
+
for(v in 1..5) {
|
13
|
+
console.log(v)
|
14
|
+
}
|
15
|
+
|
12
16
|
compiled: |
|
13
|
-
var t;
|
17
|
+
var t, v;
|
14
18
|
t = 0x5;
|
15
19
|
while(t > 0) { t--; };
|
16
20
|
for(t = 0; t < 5; t += 1) { console.log(t); };
|
21
|
+
var _i, _j = [1, 2, 3, 4, 5];
|
22
|
+
for(_i in _j) {
|
23
|
+
v = _j[_i];
|
24
|
+
console.log(v);
|
25
|
+
};
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liquidscript
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Rodi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|