volt 0.6.5 → 0.7.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.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/Readme.md +47 -40
  3. data/VERSION +1 -1
  4. data/app/volt/controllers/notices_controller.rb +3 -3
  5. data/app/volt/tasks/live_query/data_store.rb +2 -2
  6. data/app/volt/tasks/live_query/live_query.rb +20 -20
  7. data/app/volt/tasks/live_query/live_query_pool.rb +6 -6
  8. data/app/volt/tasks/live_query/query_tracker.rb +15 -15
  9. data/app/volt/tasks/query_tasks.rb +13 -13
  10. data/app/volt/tasks/store_tasks.rb +7 -7
  11. data/app/volt/views/notices/index.html +17 -18
  12. data/lib/volt/assets/test.rb +2 -2
  13. data/lib/volt/benchmark/benchmark.rb +25 -23
  14. data/lib/volt/cli/asset_compile.rb +11 -0
  15. data/lib/volt/cli/new_gem.rb +16 -16
  16. data/lib/volt/cli.rb +14 -12
  17. data/lib/volt/console.rb +5 -6
  18. data/lib/volt/controllers/model_controller.rb +18 -18
  19. data/lib/volt/extra_core/array.rb +4 -4
  20. data/lib/volt/extra_core/hash.rb +3 -3
  21. data/lib/volt/extra_core/object.rb +6 -6
  22. data/lib/volt/extra_core/string.rb +6 -6
  23. data/lib/volt/extra_core/symbol.rb +5 -5
  24. data/lib/volt/extra_core/time.rb +4 -4
  25. data/lib/volt/extra_core/true_false.rb +6 -6
  26. data/lib/volt/extra_core/try.rb +9 -9
  27. data/lib/volt/models/array_model.rb +26 -26
  28. data/lib/volt/models/model.rb +35 -35
  29. data/lib/volt/models/model_hash_behaviour.rb +15 -15
  30. data/lib/volt/models/model_helpers.rb +8 -8
  31. data/lib/volt/models/model_wrapper.rb +6 -6
  32. data/lib/volt/models/persistors/array_store.rb +36 -36
  33. data/lib/volt/models/persistors/base.rb +6 -6
  34. data/lib/volt/models/persistors/flash.rb +5 -5
  35. data/lib/volt/models/persistors/model_identity_map.rb +2 -2
  36. data/lib/volt/models/persistors/model_store.rb +22 -22
  37. data/lib/volt/models/persistors/params.rb +3 -3
  38. data/lib/volt/models/persistors/query/query_listener.rb +14 -14
  39. data/lib/volt/models/persistors/query/query_listener_pool.rb +2 -2
  40. data/lib/volt/models/persistors/store.rb +8 -8
  41. data/lib/volt/models/persistors/store_factory.rb +2 -2
  42. data/lib/volt/models/url.rb +37 -37
  43. data/lib/volt/page/bindings/attribute_binding.rb +14 -14
  44. data/lib/volt/page/bindings/base_binding.rb +9 -9
  45. data/lib/volt/page/bindings/component_binding.rb +7 -7
  46. data/lib/volt/page/bindings/content_binding.rb +3 -3
  47. data/lib/volt/page/bindings/each_binding.rb +13 -13
  48. data/lib/volt/page/bindings/event_binding.rb +4 -4
  49. data/lib/volt/page/bindings/if_binding.rb +12 -12
  50. data/lib/volt/page/bindings/template_binding.rb +30 -30
  51. data/lib/volt/page/channel.rb +19 -19
  52. data/lib/volt/page/channel_stub.rb +6 -6
  53. data/lib/volt/page/document.rb +2 -2
  54. data/lib/volt/page/document_events.rb +4 -4
  55. data/lib/volt/page/draw_cycle.rb +3 -3
  56. data/lib/volt/page/memory_test.rb +6 -6
  57. data/lib/volt/page/page.rb +19 -19
  58. data/lib/volt/page/reactive_template.rb +9 -9
  59. data/lib/volt/page/sub_context.rb +5 -5
  60. data/lib/volt/page/targets/attribute_section.rb +9 -9
  61. data/lib/volt/page/targets/attribute_target.rb +3 -3
  62. data/lib/volt/page/targets/base_section.rb +2 -2
  63. data/lib/volt/page/targets/binding_document/component_node.rb +23 -23
  64. data/lib/volt/page/targets/binding_document/html_node.rb +2 -2
  65. data/lib/volt/page/targets/dom_section.rb +40 -38
  66. data/lib/volt/page/targets/dom_target.rb +2 -2
  67. data/lib/volt/page/tasks.rb +12 -12
  68. data/lib/volt/page/template_renderer.rb +4 -4
  69. data/lib/volt/page/url_tracker.rb +6 -6
  70. data/lib/volt/reactive/array_extensions.rb +2 -2
  71. data/lib/volt/reactive/destructive_methods.rb +5 -5
  72. data/lib/volt/reactive/event_chain.rb +25 -25
  73. data/lib/volt/reactive/events.rb +33 -33
  74. data/lib/volt/reactive/object_tracker.rb +21 -21
  75. data/lib/volt/reactive/object_tracking.rb +2 -2
  76. data/lib/volt/reactive/reactive_array.rb +57 -57
  77. data/lib/volt/reactive/reactive_tags.rb +16 -16
  78. data/lib/volt/reactive/reactive_value.rb +72 -72
  79. data/lib/volt/reactive/string_extensions.rb +3 -3
  80. data/lib/volt/router/routes.rb +22 -23
  81. data/lib/volt/server/component_handler.rb +5 -5
  82. data/lib/volt/server/component_templates.rb +14 -11
  83. data/lib/volt/server/html_parser/attribute_scope.rb +116 -0
  84. data/lib/volt/server/html_parser/each_scope.rb +18 -0
  85. data/lib/volt/server/html_parser/if_view_scope.rb +71 -0
  86. data/lib/volt/server/html_parser/sandlebars_parser.rb +219 -0
  87. data/lib/volt/server/html_parser/textarea_scope.rb +31 -0
  88. data/lib/volt/server/html_parser/view_handler.rb +82 -0
  89. data/lib/volt/server/html_parser/view_parser.rb +23 -0
  90. data/lib/volt/server/html_parser/view_scope.rb +145 -0
  91. data/lib/volt/server/rack/asset_files.rb +17 -17
  92. data/lib/volt/server/rack/component_paths.rb +18 -18
  93. data/lib/volt/server/rack/index_files.rb +8 -8
  94. data/lib/volt/server/rack/opal_files.rb +11 -11
  95. data/lib/volt/server/socket_connection_handler.rb +13 -13
  96. data/lib/volt/server/socket_connection_handler_stub.rb +2 -2
  97. data/lib/volt/server.rb +18 -18
  98. data/lib/volt/tasks/dispatcher.rb +5 -5
  99. data/lib/volt/utils/ejson.rb +2 -2
  100. data/lib/volt/utils/generic_counting_pool.rb +8 -8
  101. data/lib/volt/utils/generic_pool.rb +16 -16
  102. data/lib/volt/volt/environment.rb +4 -4
  103. data/lib/volt.rb +6 -6
  104. data/spec/integration/test_integration_spec.rb +2 -2
  105. data/spec/models/event_chain_spec.rb +38 -38
  106. data/spec/models/model_spec.rb +128 -128
  107. data/spec/models/old_model_spec.rb +17 -17
  108. data/spec/models/persistors/params_spec.rb +3 -3
  109. data/spec/models/persistors/store_spec.rb +7 -7
  110. data/spec/models/reactive_array_spec.rb +82 -82
  111. data/spec/models/reactive_generator_spec.rb +11 -11
  112. data/spec/models/reactive_tags_spec.rb +6 -6
  113. data/spec/models/reactive_value_spec.rb +70 -70
  114. data/spec/models/store_spec.rb +4 -4
  115. data/spec/models/string_extensions_spec.rb +13 -13
  116. data/spec/page/bindings/content_binding_spec.rb +6 -6
  117. data/spec/page/sub_context_spec.rb +1 -1
  118. data/spec/router/routes_spec.rb +3 -3
  119. data/spec/server/html_parser/sample_page.html +595 -0
  120. data/spec/server/html_parser/sandlebars_parser_spec.rb +192 -0
  121. data/spec/server/html_parser/view_parser_spec.rb +286 -0
  122. data/spec/server/rack/asset_files_spec.rb +6 -6
  123. data/spec/server/rack/component_paths_spec.rb +5 -5
  124. data/spec/spec_helper.rb +4 -5
  125. data/spec/store/mongo_spec.rb +3 -3
  126. data/spec/tasks/live_query_spec.rb +6 -6
  127. data/spec/tasks/query_tasks.rb +4 -4
  128. data/spec/tasks/query_tracker_spec.rb +20 -20
  129. data/spec/templates/targets/binding_document/component_node_spec.rb +4 -4
  130. data/spec/templates/template_binding_spec.rb +28 -28
  131. data/spec/utils/generic_counting_pool_spec.rb +5 -5
  132. data/spec/utils/generic_pool_spec.rb +14 -14
  133. data/templates/newgem/app/newgem/views/index/index.html +1 -2
  134. data/templates/project/app/home/config/dependencies.rb +1 -1
  135. data/templates/project/app/home/controllers/index_controller.rb +1 -1
  136. data/templates/project/app/home/views/index/about.html +4 -6
  137. data/templates/project/app/home/views/index/home.html +4 -5
  138. data/templates/project/app/home/views/index/index.html +8 -9
  139. data/templates/project/spec/spec_helper.rb +1 -1
  140. metadata +17 -8
  141. data/lib/volt/server/binding_setup.rb +0 -2
  142. data/lib/volt/server/if_binding_setup.rb +0 -31
  143. data/lib/volt/server/scope.rb +0 -43
  144. data/lib/volt/server/template_parser.rb +0 -453
  145. data/spec/server/template_parser_spec.rb +0 -50
@@ -0,0 +1,192 @@
1
+ require 'benchmark'
2
+ require 'volt/server/html_parser/sandlebars_parser'
3
+
4
+ class HTMLHandler
5
+ attr_reader :html
6
+
7
+ def initialize
8
+ @html = ''
9
+ end
10
+
11
+ def comment(comment)
12
+ @html << "<!--#{comment}-->"
13
+ end
14
+
15
+ def text(text)
16
+ @html << text
17
+ end
18
+
19
+ def binding(binding)
20
+ @html << "{#{binding}}"
21
+ end
22
+
23
+ def start_tag(tag_name, attributes, unary)
24
+ attr_str = attributes.map {|v| "#{v[0]}=\"#{v[1]}\"" }.join(' ')
25
+ if attr_str.size > 0
26
+ # extra space
27
+ attr_str = " " + attr_str
28
+ end
29
+ @html << "<#{tag_name}#{attr_str}#{unary ? ' /' : ''}>"
30
+ end
31
+
32
+ def end_tag(tag_name)
33
+ @html << "</#{tag_name}>"
34
+ end
35
+ end
36
+
37
+ def parse_url(url)
38
+ require 'open-uri'
39
+ html = open("http://#{url}").read
40
+
41
+ # html = File.read("/Users/ryanstout/Desktop/tests/#{url}1.html")
42
+
43
+ File.open("/Users/ryanstout/Desktop/tests/#{url}1.html", 'w') {|f| f.write(html) }
44
+
45
+ handler = HTMLHandler.new
46
+ SandlebarsParser.new(html, handler)
47
+
48
+ File.open("/Users/ryanstout/Desktop/tests/#{url}2.html", 'w') {|f| f.write(handler.html) }
49
+ end
50
+
51
+ describe SandlebarsParser do
52
+ def test_html(html, match=nil)
53
+ handler = HTMLHandler.new
54
+ parser = SandlebarsParser.new(html, handler)
55
+
56
+ expect(handler.html).to eq(match || html)
57
+ end
58
+
59
+ it "should handle a doctype" do
60
+ html = "<!DOCTYPE html><p>text</p>"
61
+
62
+ test_html(html)
63
+ end
64
+
65
+ it "should parse comments" do
66
+ html = "<!-- my comment -->"
67
+ test_html(html)
68
+ end
69
+
70
+ it "should handle text" do
71
+ html = "some text, <!-- a comment -->, some more text"
72
+ test_html(html)
73
+ end
74
+
75
+ it "should handle tags" do
76
+ html = "<a name=\"cool\"></a>"
77
+ test_html(html)
78
+ end
79
+
80
+ it "should close tags" do
81
+ html = "<div><p>test</p>"
82
+ match = "<div><p>test</p></div>"
83
+
84
+ test_html(html, match)
85
+ end
86
+
87
+ it "should handle a script tag with html in it" do
88
+ html = "<script><!-- some js code <a>cool</a> here --></script>"
89
+ match = "<script> some js code <a>cool</a> here </script>"
90
+ test_html(html, match)
91
+ end
92
+
93
+ it "should handle bindings" do
94
+ html = "<p>some cool {text} is {awesome}</p>"
95
+ test_html(html)
96
+ end
97
+
98
+ it "should handle bindings with nested { and }" do
99
+ html = "<p>testing with {nested { 'binding stuff' }}</p>"
100
+ test_html(html)
101
+ end
102
+
103
+ it "should raise an exception on an unclosed binding at the end of the document" do
104
+ html = "<p>testing with {nested"
105
+
106
+ handler = HTMLHandler.new
107
+ expect { SandlebarsParser.new(html, handler) }.to raise_error(HTMLParseError)
108
+ end
109
+
110
+ it "should raise an exception on an unclosed binding" do
111
+ html = "<p>testing with {nested </p>\n<p>ok</p>"
112
+
113
+ handler = HTMLHandler.new
114
+ expect { SandlebarsParser.new(html, handler) }.to raise_error(HTMLParseError)
115
+ end
116
+
117
+ it "should report the line number" do
118
+ html = "\n\n<p>some paragraph</p>\n\n<p>testing with {nested </p>\n<p>ok</p>"
119
+
120
+ handler = HTMLHandler.new
121
+ expect { SandlebarsParser.new(html, handler) }.to raise_error(HTMLParseError, "unclosed binding: {nested </p> on line: 5")
122
+ end
123
+
124
+ it "should handle a bunch of things" do
125
+ html = <<-END
126
+ <p class="some class">This is my text <a href="something.com">something.com</a></p>
127
+ END
128
+
129
+ test_html(html)
130
+ end
131
+
132
+ it "should not jump between script tags" do
133
+ html = "\n<script>some text</script>\n\n<script>inside 2</script>\n"
134
+
135
+ test_html(html)
136
+ end
137
+
138
+ it "should not jump bindings" do
139
+ html = "<p>{some} text {binding}</p>"
140
+ test_html(html)
141
+ end
142
+
143
+ it "should handle escaping things in a tripple escape" do
144
+ html = "this is my {{{ tripple escape }}}"
145
+ match = "this is my tripple escape "
146
+ test_html(html, match)
147
+ end
148
+
149
+ it "should let you escape { and }" do
150
+ html = "should escape {{{{}}} and {{{}}}}"
151
+ match = "should escape { and }"
152
+ test_html(html, match)
153
+ end
154
+
155
+ it "should handle sandlebar tags" do
156
+ html = "custom tag <:awesome name=\"yes\" />"
157
+ test_html(html)
158
+ end
159
+
160
+ it "should keep the text after script" do
161
+ html = "<ul><li>\n\n<script>\n\nsome js code\n\nmore\n\n</script> \n </li> \n \n </ul>"
162
+ test_html(html)
163
+ end
164
+
165
+ it "should handle dashes in attributes" do
166
+ html = "<form accept-charset=\"UTF-8\"></form>"
167
+ test_html(html)
168
+ end
169
+
170
+ it "should handle conditional comments for IE" do
171
+ html = "<!--[if ie6]>some ie only stuff<![endif]-->\n<br />"
172
+ test_html(html)
173
+ end
174
+
175
+ it "should be fast" do
176
+ html = File.read(File.join(File.dirname(__FILE__), 'sample_page.html'))
177
+ handler = HTMLHandler.new
178
+ time = Benchmark.measure do
179
+ SandlebarsParser.new(html, handler)
180
+ end
181
+
182
+ # Less than 100ms
183
+ expect(time.total).to be < 0.1
184
+ end
185
+
186
+ # it "should warn you when you over close tags" do
187
+ # html = "<div><p>test</p></div></div>"
188
+ #
189
+ # handler = HTMLHandler.new
190
+ # expect { SandlebarsParser.new(html, handler) }.to raise_error(HTMLParseError)
191
+ # end
192
+ end
@@ -0,0 +1,286 @@
1
+ require 'benchmark'
2
+ require 'volt/server/html_parser/view_parser'
3
+
4
+ describe ViewParser do
5
+ it "should parse content bindings" do
6
+ html = "<p>Some {content} binding, {name}</p>"
7
+
8
+ view = ViewParser.new(html, "home/index/index")
9
+
10
+ expect(view.templates).to eq({
11
+ 'home/index/index/body' => {
12
+ 'html' => '<p>Some <!-- $0 --><!-- $/0 --> binding, <!-- $1 --><!-- $/1 --></p>',
13
+ 'bindings' => {
14
+ 0 => ["lambda { |__p, __t, __c, __id| ContentBinding.new(__p, __t, __c, __id, Proc.new { content }) }"],
15
+ 1 => ["lambda { |__p, __t, __c, __id| ContentBinding.new(__p, __t, __c, __id, Proc.new { name }) }"]
16
+ }
17
+ }
18
+ })
19
+ end
20
+
21
+ it "should parse if bindings" do
22
+ html = <<-END
23
+ <p>
24
+ Some
25
+ {#if showing == :text}
26
+ text
27
+ {#elsif showing == :button}
28
+ <button>Button</button>
29
+ {#else}
30
+ <a href="">link</a>
31
+ {/}
32
+ </p>
33
+ END
34
+
35
+ view = ViewParser.new(html, "home/index/index")
36
+
37
+ expect(view.templates).to eq( {
38
+ "home/index/index/body/__ifg0/__if0" => {
39
+ "html" => "\n text\n "
40
+ },
41
+ "home/index/index/body/__ifg0/__if1" => {
42
+ "html" => "\n <button>Button</button>\n "
43
+ },
44
+ "home/index/index/body/__ifg0/__if2" => {
45
+ "html" => "\n <a href=\"\">link</a>\n "
46
+ },
47
+ "home/index/index/body" => {
48
+ "html" => " <p>\n Some\n <!-- $0 --><!-- $/0 -->\n </p>\n",
49
+ "bindings" => {
50
+ 0 => [
51
+ "lambda { |__p, __t, __c, __id| IfBinding.new(__p, __t, __c, __id, [[Proc.new { showing == :text }, \"home/index/index/body/__ifg0/__if0\"], [Proc.new { showing == :button }, \"home/index/index/body/__ifg0/__if1\"], [nil, \"home/index/index/body/__ifg0/__if2\"]]) }"
52
+ ]
53
+ }
54
+ }
55
+ })
56
+
57
+
58
+ end
59
+
60
+ it "should handle nested if's" do
61
+ html = <<-END
62
+ <p>
63
+ Some
64
+ {#if showing == :text}
65
+ {#if sub_item}
66
+ sub item text
67
+ {/}
68
+ {#else}
69
+ other
70
+ {/}
71
+ </p>
72
+ END
73
+
74
+ view = ViewParser.new(html, "home/index/index")
75
+
76
+ expect(view.templates).to eq( {
77
+ "home/index/index/body/__ifg0/__if0/__ifg0/__if0" => {
78
+ "html"=>"\n sub item text\n "
79
+ },
80
+ "home/index/index/body/__ifg0/__if0" => {
81
+ "html" => "\n <!-- $0 --><!-- $/0 -->\n ",
82
+ "bindings" => {
83
+ 0 => [
84
+ "lambda { |__p, __t, __c, __id| IfBinding.new(__p, __t, __c, __id, [[Proc.new { sub_item }, \"home/index/index/body/__ifg0/__if0/__ifg0/__if0\"]]) }"
85
+ ]
86
+ }
87
+ },
88
+ "home/index/index/body/__ifg0/__if1" => {
89
+ "html" => "\n other\n "
90
+ },
91
+ "home/index/index/body" => {
92
+ "html" => " <p>\n Some\n <!-- $0 --><!-- $/0 -->\n </p>\n",
93
+ "bindings" => {
94
+ 0 => [
95
+ "lambda { |__p, __t, __c, __id| IfBinding.new(__p, __t, __c, __id, [[Proc.new { showing == :text }, \"home/index/index/body/__ifg0/__if0\"], [nil, \"home/index/index/body/__ifg0/__if1\"]]) }"
96
+ ]
97
+ }
98
+ }
99
+ })
100
+ end
101
+
102
+
103
+ it "should parse each bindings" do
104
+ html = <<-END
105
+ <div class="main">
106
+ {#each _items as item}
107
+ <p>{item}</p>
108
+ {/}
109
+ </div>
110
+ END
111
+
112
+ view = ViewParser.new(html, "home/index/index")
113
+
114
+ expect(view.templates).to eq({
115
+ "home/index/index/body/__template/0" => {
116
+ "html" => "\n <p><!-- $0 --><!-- $/0 --></p>\n ",
117
+ "bindings" => {
118
+ 0 => [
119
+ "lambda { |__p, __t, __c, __id| ContentBinding.new(__p, __t, __c, __id, Proc.new { item }) }"
120
+ ]
121
+ }
122
+ },
123
+ "home/index/index/body" => {
124
+ "html" => " <div class=\"main\">\n <!-- $0 --><!-- $/0 -->\n </div>\n",
125
+ "bindings" => {
126
+ 0 => [
127
+ "lambda { |__p, __t, __c, __id| EachBinding.new(__p, __t, __c, __id, Proc.new { _items }, \"item\", \"home/index/index/body/__template/0\") }"
128
+ ]
129
+ }
130
+ }
131
+ })
132
+
133
+
134
+ end
135
+
136
+ it "should parse a single attribute binding" do
137
+ html = <<-END
138
+ <div class="{main_class}">
139
+ </div>
140
+ END
141
+
142
+ view = ViewParser.new(html, "home/index/index")
143
+
144
+ expect(view.templates).to eq({
145
+ "home/index/index/body" => {
146
+ "html" => " <div id=\"id0\">\n </div>\n",
147
+ "bindings" => {
148
+ "id0" => [
149
+ "lambda { |__p, __t, __c, __id| AttributeBinding.new(__p, __t, __c, __id, \"class\", Proc.new { main_class }) }"
150
+ ]
151
+ }
152
+ }
153
+ })
154
+ end
155
+
156
+ it "should parse multiple attribute bindings in a single attribute" do
157
+ html = <<-END
158
+ <div class="start {main_class} {awesome_class} string">
159
+ </div>
160
+ END
161
+
162
+ view = ViewParser.new(html, "home/index/index")
163
+
164
+ expect(view.templates).to eq({
165
+ "home/index/index/body/_rv1" => {
166
+ "html" => "start <!-- $0 --><!-- $/0 --> <!-- $1 --><!-- $/1 --> string",
167
+ "bindings" => {
168
+ 0 => [
169
+ "lambda { |__p, __t, __c, __id| ContentBinding.new(__p, __t, __c, __id, Proc.new { main_class }) }"
170
+ ],
171
+ 1 => [
172
+ "lambda { |__p, __t, __c, __id| ContentBinding.new(__p, __t, __c, __id, Proc.new { awesome_class }) }"
173
+ ]
174
+ }
175
+ },
176
+ "home/index/index/body" => {
177
+ "html" => " <div id=\"id0\">\n </div>\n",
178
+ "bindings" => {
179
+ "id0" => [
180
+ "lambda { |__p, __t, __c, __id| AttributeBinding.new(__p, __t, __c, __id, \"class\", Proc.new { ReactiveTemplate.new(__p, __c, \"home/index/index/body/_rv1\") }) }"
181
+ ]
182
+ }
183
+ }
184
+ })
185
+ end
186
+
187
+ it "should parse a template" do
188
+ html = <<-END
189
+ {#template "/home/temp/path"}
190
+ END
191
+
192
+ view = ViewParser.new(html, "home/index/index")
193
+
194
+ expect(view.templates).to eq({
195
+ "home/index/index/body" => {
196
+ "html" => " <!-- $0 --><!-- $/0 -->\n",
197
+ "bindings" => {
198
+ 0 => [
199
+ "lambda { |__p, __t, __c, __id| TemplateBinding.new(__p, __t, __c, __id, \"home/index/index/body\", Proc.new { [\"/home/temp/path\"] }) }"
200
+ ]
201
+ }
202
+ }
203
+ })
204
+ end
205
+
206
+
207
+ it "should setup a href multiple attribute binding correctly" do
208
+ html = <<-END
209
+ <a href="/{link_name}">Link</a>
210
+ END
211
+
212
+ view = ViewParser.new(html, "home/index/index/body")
213
+
214
+ # puts view.templates.inspect
215
+ end
216
+ it "should setup a href single attribute binding correctly" do
217
+ html = <<-END
218
+ <a href="{link_name}">Link</a>
219
+ END
220
+
221
+ view = ViewParser.new(html, "home/index/index/body")
222
+
223
+ # puts view.templates.inspect
224
+ end
225
+
226
+ it "should parse components" do
227
+
228
+ end
229
+
230
+ it "should parse sections" do
231
+ html = <<-END
232
+ <:Title>
233
+ This text goes in the title
234
+
235
+ <:Body>
236
+ <p>This text goes in the body</p>
237
+ END
238
+
239
+ view = ViewParser.new(html, "home/index/index")
240
+
241
+ expect(view.templates).to eq( {
242
+ "home/index/index/title" => {
243
+ "html" => "\n This text goes in the title\n\n "
244
+ },
245
+ "home/index/index/body" => {
246
+ "html" => "\n <p>This text goes in the body</p>\n"
247
+ }
248
+ })
249
+
250
+
251
+ end
252
+
253
+ it "should keep the html inside of a textarea if there are no bindings" do
254
+ html = <<-END
255
+ <textarea name="cool">some text in a textarea</textarea>
256
+ END
257
+
258
+ view = ViewParser.new(html, "home/index/index")
259
+
260
+ expect(view.templates).to eq({
261
+ "home/index/index/body" => {
262
+ "html" => " <textarea name=\"cool\">some text in a textarea</textarea>\n"
263
+ }
264
+ })
265
+ end
266
+
267
+ it "should setup bindings for textarea values" do
268
+ html = <<-END
269
+ <textarea name="cool">{awesome}</textarea>
270
+ END
271
+
272
+ view = ViewParser.new(html, "home/index/index")
273
+
274
+ expect(view.templates).to eq({
275
+ "home/index/index/body" => {
276
+ "html" => " <textarea name=\"cool\" id=\"id1\"></textarea>\n",
277
+ "bindings" => {
278
+ "id1" => [
279
+ "lambda { |__p, __t, __c, __id| AttributeBinding.new(__p, __t, __c, __id, \"value\", Proc.new { awesome }) }"
280
+ ]
281
+ }
282
+ }
283
+ })
284
+ end
285
+
286
+ end
@@ -4,22 +4,22 @@ if RUBY_PLATFORM != 'opal'
4
4
  describe AssetFiles do
5
5
  before do
6
6
  spec_app_root = File.join(File.dirname(__FILE__), "../../apps/file_loading")
7
-
7
+
8
8
  path_to_main = File.join(File.dirname(__FILE__), "../../apps/file_loading/app/main")
9
9
  @component_paths = ComponentPaths.new(spec_app_root)
10
10
  end
11
-
11
+
12
12
  it "should return the dependencies list" do
13
13
  main = AssetFiles.new("main", @component_paths)
14
-
14
+
15
15
  components = main.components
16
16
  expect(components).to eq(['volt', 'main', 'shared', 'bootstrap', "slideshow"])
17
17
  end
18
-
18
+
19
19
  it "should list all JS files" do
20
20
  main = AssetFiles.new("main", @component_paths)
21
-
21
+
22
22
  expect(main.javascript_files(nil)).to eq(["/assets/js/jquery-2.0.3.js", "/assets/js/sockjs-0.2.1.min.js", "/assets/js/bootstrap.js", "/assets/js/test2.js", "/assets/js/test3.js", "/assets/js/test1.js", "/assets/volt/page/page.js", "/components/home.js"])
23
23
  end
24
24
  end
25
- end
25
+ end
@@ -4,11 +4,11 @@ if RUBY_PLATFORM != 'opal'
4
4
  describe ComponentPaths do
5
5
  before do
6
6
  spec_app_root = File.join(File.dirname(__FILE__), "../../apps/file_loading")
7
-
7
+
8
8
  path_to_main = File.join(File.dirname(__FILE__), "../../apps/file_loading/app/main")
9
9
  @component_paths = ComponentPaths.new(spec_app_root)
10
10
  end
11
-
11
+
12
12
  it "should return the paths to all app folders" do
13
13
  match_count = 0
14
14
  @component_paths.app_folders do |app_folder|
@@ -16,13 +16,13 @@ if RUBY_PLATFORM != 'opal'
16
16
  match_count += 1
17
17
  end
18
18
  end
19
-
19
+
20
20
  expect(match_count).to eq(2)
21
21
  end
22
-
22
+
23
23
  it "should return the path to a component" do
24
24
  main_path = @component_paths.component_path('main')
25
25
  expect(main_path).to match(/spec\/apps\/file_loading\/app\/main$/)
26
26
  end
27
27
  end
28
- end
28
+ end
data/spec/spec_helper.rb CHANGED
@@ -8,9 +8,8 @@
8
8
  ENV['SAUCE_USERNAME'] = 'ryanstout'
9
9
  ENV['SAUCE_ACCESS_KEY'] = 'a537b01d-33ed-4028-9e80-eeb602748a5f'
10
10
 
11
- require 'capybara/rspec'
12
-
13
11
  if ENV['IN_BROWSER']
12
+ require 'capybara/rspec'
14
13
  # Needed at the moment to get chrome tests working
15
14
  require 'chromedriver2/helper'
16
15
  require 'capybara/poltergeist'
@@ -22,7 +21,7 @@ require 'volt'
22
21
 
23
22
  # Capybara.default_driver = :sauce
24
23
  # Capybara.server_port = 2020
25
- #
24
+ #
26
25
  # Sauce.config do |conf|
27
26
  # conf[:start_tunnel] = true
28
27
  # conf[:browsers] = [
@@ -44,7 +43,7 @@ if ENV['IN_BROWSER']
44
43
 
45
44
  kitchen_sink_path = File.expand_path(File.join(File.dirname(__FILE__), "apps/kitchen_sink"))
46
45
  Capybara.app = Server.new(kitchen_sink_path).app
47
-
46
+
48
47
  Capybara.default_driver = :poltergeist
49
48
  end
50
49
 
@@ -60,4 +59,4 @@ if RUBY_PLATFORM != 'opal'
60
59
  # --seed 1234
61
60
  config.order = 'random'
62
61
  end
63
- end
62
+ end
@@ -1,7 +1,7 @@
1
1
  # require 'mongo'
2
2
  # include Mongo
3
- #
3
+ #
4
4
  # mongo_client = MongoClient.new("localhost", 27017)
5
5
  # items = mongo_client['docs']['items']
6
- #
7
- # items
6
+ #
7
+ # items
@@ -3,18 +3,18 @@ if RUBY_PLATFORM != 'opal'
3
3
  before do
4
4
  load File.join(File.dirname(__FILE__), "../../app/volt/tasks/live_query/live_query.rb")
5
5
  end
6
-
6
+
7
7
  it "should run a query" do
8
8
  pool = double('pool')
9
9
  data_store = double('data store')
10
-
10
+
11
11
  expect(data_store).to receive(:query).with('_items', {}).and_return([
12
12
  {'_id' => 0, '_name' => 'one'}
13
13
  ])
14
-
14
+
15
15
  live_query = LiveQuery.new(pool, data_store, '_items', {})
16
16
  end
17
-
18
-
17
+
18
+
19
19
  end
20
- end
20
+ end
@@ -3,8 +3,8 @@ if RUBY_PLATFORM != 'opal'
3
3
  before do
4
4
  load File.join(File.dirname(__FILE__), "../../app/volt/tasks/query_tasks.rb")
5
5
  end
6
-
7
-
8
-
6
+
7
+
8
+
9
9
  end
10
- end
10
+ end