liquidscript 0.5.1 → 0.6.0

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
  SHA1:
3
- metadata.gz: c7b27422d639d89c8df52c7e75eee1babea5f56a
4
- data.tar.gz: 340a10447020593a0f17c688f09a5dde271b1a97
3
+ metadata.gz: f78baec8227e0ec1b9986e425bfebd2b6f8111d2
4
+ data.tar.gz: 2cbb8ff3abcd35097d0fb0857323d00278333459
5
5
  SHA512:
6
- metadata.gz: c735ed037f3a6e5166252b2aee8c0a9be0ba275d7906601e2ae1b3553fbd293f1f227d90ce80cea5d7ba6135cc9ab07c8cb831558e796330ad6c85cffec7e3fc
7
- data.tar.gz: 2b3d9a03a02404890c5740845f85e407a2671a717a456bebfc4c0d816c0309f4d0fa45705a53225216ba6a90cc078b174116e4c06480b1191260372c5a16d3f4
6
+ metadata.gz: e022aa7c15cbf00447245c497fc139d59374150b2ff6de9d46052cd0f5e673ee1c9c959add7a14bf771f22b073808128c4f2c9d5d568d7b3d1a2a77f0a7fa71b
7
+ data.tar.gz: fb7907b5e7d3002e65a9194e810fb9c4adfd3392163e5e41fe3784f432a7c2a6312ae3b29613c58db3a0583ceac3b681246d455577149a56170995dee118356e
@@ -46,14 +46,14 @@ module Liquidscript
46
46
  :comma => action.shift,
47
47
  :module => action { components << compile_module },
48
48
  :class => action { components << compile_class },
49
- [:identifier, :dstring] => compile_object
49
+ [:identifier, :istring] => compile_object
50
50
  end
51
51
 
52
52
  components
53
53
  end
54
54
 
55
55
  def _compile_class_body_key(mod)
56
- item = shift :identifier, :dstring
56
+ item = shift :identifier, :istring
57
57
 
58
58
  item = compile_property(item) if item.type == :identifier &&
59
59
  peek?(:prop) && !mod
@@ -13,11 +13,17 @@ module Liquidscript
13
13
  # Just in case there is a property named 'class' or 'module'
14
14
  v = expect [:identifier, :class, :module] => property
15
15
 
16
- expect :lparen => action { compile_call(v) },
17
- :equal => action { compile_assignment(v) },
18
- :prop => action { compile_property(v) },
19
- :unop => action { |o| code :op, v, o },
20
- :_ => action { v }
16
+ value_expect(v)
17
+ end
18
+
19
+ def compile_access(body)
20
+ shift :lbrack
21
+ key = compile_vexpression
22
+ shift :rbrack
23
+
24
+ v = code :access, body, key
25
+
26
+ value_expect(v)
21
27
  end
22
28
 
23
29
  def compile_call(subject)
@@ -28,6 +34,17 @@ module Liquidscript
28
34
 
29
35
  code :call, subject, *arguments
30
36
  end
37
+
38
+ protected
39
+
40
+ def value_expect(v, &default)
41
+ expect :lparen => action { compile_call(v) },
42
+ :equal => action { compile_assignment(v) },
43
+ :prop => action { compile_property(v) },
44
+ :lbrack => action { compile_access(v) },
45
+ :unop => action { |o| code :op, v, o },
46
+ :_ => default || action { v }
47
+ end
31
48
  end
32
49
  end
33
50
  end
@@ -68,11 +68,7 @@ module Liquidscript
68
68
  code :get, ref(identifier)
69
69
  end
70
70
 
71
- expect :equal => action { compile_assignment(identifier) },
72
- :prop => action { compile_property(identifier) },
73
- :lparen => action { compile_call(identifier) },
74
- :unop => action { |o| code :op, ref(identifier), o },
75
- :_ => default
71
+ value_expect(identifier, &default)
76
72
  end
77
73
 
78
74
  def compile_regex
@@ -163,7 +159,7 @@ module Liquidscript
163
159
  end
164
160
 
165
161
  def compile_object_key
166
- key = shift :identifier, :dstring
162
+ key = shift :identifier, :istring
167
163
  shift :colon
168
164
 
169
165
  key
@@ -21,8 +21,8 @@ module Liquidscript
21
21
  end
22
22
 
23
23
  def generate_op(code)
24
- if code[1].type == :variable
25
- "#{code[1].name}#{code[2].value}"
24
+ if code[1].type == :identifier
25
+ "#{code[1].value}#{code[2].value}"
26
26
  else
27
27
  "#{replace(code[1])}#{code[2].value}"
28
28
  end
@@ -79,7 +79,6 @@ module Liquidscript
79
79
  end
80
80
 
81
81
  def generate_sstring(code)
82
-
83
82
  "'#{code.first.gsub(/'/, "\\'")}'"
84
83
  end
85
84
 
@@ -13,8 +13,18 @@ module Liquidscript
13
13
  case code[1].type
14
14
  when :variable
15
15
  "#{code[1].name} = #{replace code[2]}"
16
- when :property
16
+ when :property, :access
17
17
  "#{replace code[1]} = #{replace code[2]}"
18
+
19
+ end
20
+ end
21
+
22
+ def generate_access(code)
23
+ case code[1].type
24
+ when :identifier
25
+ "#{code[1].value}[#{replace code[2]}]"
26
+ else
27
+ "#{replace code[1]}[#{replace code[2]}]"
18
28
  end
19
29
  end
20
30
 
@@ -106,14 +106,20 @@ module Liquidscript
106
106
 
107
107
  code[2].each do |part|
108
108
  k, v = part
109
- case k
109
+ to_match = if k.is_a? Symbol
110
+ k
111
+ else
112
+ k.type
113
+ end
114
+
115
+ case to_match
110
116
  when :identifier
111
- body.block 8, <<-JS
117
+ body.block 7, <<-JS
112
118
  #{module_name}.#{k.value} = #{replace(v)};
113
119
  JS
114
- when :dstring
115
- body.block 8, <<-JS
116
- #{module_name}[#{k.value}] = #{replace(v)};
120
+ when :istring
121
+ body.block 7, <<-JS
122
+ #{module_name}["#{k.value}"] = #{replace(v)};
117
123
  JS
118
124
  when :class
119
125
  body << generate_class(part)
@@ -1,5 +1,5 @@
1
1
  module Liquidscript
2
2
 
3
3
  # The current version of liquidscript.
4
- VERSION = "0.5.1".freeze
4
+ VERSION = "0.6.0".freeze
5
5
  end
@@ -1,3 +1,6 @@
1
+ require "liquidscript"
2
+ require "sprockets"
3
+
1
4
  module Sprockets
2
5
  class LiquidscriptTemplate < Template
3
6
  def self.default_mime_type
@@ -8,4 +11,6 @@ module Sprockets
8
11
  @output ||= Liquidscript.compile(data)
9
12
  end
10
13
  end
14
+
15
+ register_engine '.liq', LiquidscriptTemplate
11
16
  end
@@ -0,0 +1,20 @@
1
+ data: |
2
+
3
+ module Test {
4
+ thing: {
5
+ "Content-Type": 'test
6
+ }
7
+ "test": 1
8
+ }
9
+
10
+ Test["test"] = 2
11
+
12
+ compiled: |
13
+ var Test;
14
+ Test = Test || {};
15
+ Test.thing = {
16
+ "Content-Type": 'test'
17
+ };
18
+ Test["test"] = 1;;
19
+
20
+ Test["test"] = 2;
@@ -11,7 +11,7 @@ RSpec::Matchers.define :generate do |v|
11
11
  end
12
12
 
13
13
  failure_message_for_should do |data|
14
- sprintf "expected: %{dest}\n got: %{actual}",
14
+ sprintf "expected: %{dest}\n got: %{actual}\n tree: %{tree}",
15
15
  :source => data.inspect,
16
16
  :dest => for_match(v).inspect,
17
17
  :actual => actual.inspect,
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.5.1
4
+ version: 0.6.0
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-03-15 00:00:00.000000000 Z
11
+ date: 2014-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -168,6 +168,7 @@ files:
168
168
  - spec/fixtures/literals.generate.yml
169
169
  - spec/fixtures/loop.generate.yml
170
170
  - spec/fixtures/main.compile.yml
171
+ - spec/fixtures/object.generate.yml
171
172
  - spec/fixtures/operator.generate.yml
172
173
  - spec/fixtures/set.generate.yml
173
174
  - spec/fixtures/string.compile.yml
@@ -226,6 +227,7 @@ test_files:
226
227
  - spec/fixtures/literals.generate.yml
227
228
  - spec/fixtures/loop.generate.yml
228
229
  - spec/fixtures/main.compile.yml
230
+ - spec/fixtures/object.generate.yml
229
231
  - spec/fixtures/operator.generate.yml
230
232
  - spec/fixtures/set.generate.yml
231
233
  - spec/fixtures/string.compile.yml