volt 0.8.14 → 0.8.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/Readme.md +8 -2
  4. data/VERSION +1 -1
  5. data/app/volt/controllers/notices_controller.rb +1 -1
  6. data/app/volt/models/user.rb +2 -2
  7. data/app/volt/tasks/live_query/live_query_pool.rb +1 -1
  8. data/app/volt/tasks/query_tasks.rb +1 -1
  9. data/app/volt/tasks/store_tasks.rb +1 -1
  10. data/app/volt/tasks/user_tasks.rb +2 -2
  11. data/lib/volt/boot.rb +2 -2
  12. data/lib/volt/cli/asset_compile.rb +31 -27
  13. data/lib/volt/cli.rb +64 -65
  14. data/lib/volt/config.rb +25 -23
  15. data/lib/volt/console.rb +17 -16
  16. data/lib/volt/controllers/model_controller.rb +82 -80
  17. data/lib/volt/data_stores/data_store.rb +2 -2
  18. data/lib/volt/data_stores/mongo_driver.rb +2 -2
  19. data/lib/volt/extra_core/inflections.rb +2 -2
  20. data/lib/volt/extra_core/inflector/inflections.rb +185 -183
  21. data/lib/volt/extra_core/inflector/methods.rb +50 -48
  22. data/lib/volt/extra_core/string.rb +2 -2
  23. data/lib/volt/models/array_model.rb +93 -92
  24. data/lib/volt/models/cursor.rb +3 -2
  25. data/lib/volt/models/model.rb +248 -251
  26. data/lib/volt/models/model_hash_behaviour.rb +44 -44
  27. data/lib/volt/models/model_helpers.rb +38 -36
  28. data/lib/volt/models/model_state.rb +16 -17
  29. data/lib/volt/models/model_wrapper.rb +25 -24
  30. data/lib/volt/models/persistors/array_store.rb +145 -143
  31. data/lib/volt/models/persistors/base.rb +18 -16
  32. data/lib/volt/models/persistors/flash.rb +24 -22
  33. data/lib/volt/models/persistors/local_store.rb +46 -44
  34. data/lib/volt/models/persistors/model_identity_map.rb +10 -8
  35. data/lib/volt/models/persistors/model_store.rb +76 -76
  36. data/lib/volt/models/persistors/params.rb +19 -17
  37. data/lib/volt/models/persistors/query/query_listener.rb +65 -63
  38. data/lib/volt/models/persistors/query/query_listener_pool.rb +12 -10
  39. data/lib/volt/models/persistors/store.rb +28 -28
  40. data/lib/volt/models/persistors/store_factory.rb +12 -10
  41. data/lib/volt/models/persistors/store_state.rb +33 -31
  42. data/lib/volt/models/url.rb +96 -104
  43. data/lib/volt/models/validations.rb +56 -54
  44. data/lib/volt/models/validators/length_validator.rb +24 -22
  45. data/lib/volt/models/validators/presence_validator.rb +14 -12
  46. data/lib/volt/page/bindings/attribute_binding.rb +106 -106
  47. data/lib/volt/page/bindings/base_binding.rb +23 -21
  48. data/lib/volt/page/bindings/component_binding.rb +3 -1
  49. data/lib/volt/page/bindings/content_binding.rb +34 -34
  50. data/lib/volt/page/bindings/each_binding.rb +113 -113
  51. data/lib/volt/page/bindings/event_binding.rb +38 -34
  52. data/lib/volt/page/bindings/if_binding.rb +56 -54
  53. data/lib/volt/page/bindings/template_binding/grouped_controllers.rb +24 -22
  54. data/lib/volt/page/bindings/template_binding.rb +182 -185
  55. data/lib/volt/page/channel.rb +79 -77
  56. data/lib/volt/page/channel_stub.rb +29 -27
  57. data/lib/volt/page/document.rb +6 -5
  58. data/lib/volt/page/document_events.rb +54 -52
  59. data/lib/volt/page/page.rb +139 -138
  60. data/lib/volt/page/string_template_renderer.rb +36 -36
  61. data/lib/volt/page/sub_context.rb +26 -25
  62. data/lib/volt/page/targets/attribute_section.rb +27 -25
  63. data/lib/volt/page/targets/attribute_target.rb +7 -6
  64. data/lib/volt/page/targets/base_section.rb +27 -26
  65. data/lib/volt/page/targets/binding_document/base_node.rb +3 -1
  66. data/lib/volt/page/targets/binding_document/component_node.rb +85 -82
  67. data/lib/volt/page/targets/binding_document/html_node.rb +11 -9
  68. data/lib/volt/page/targets/dom_section.rb +78 -77
  69. data/lib/volt/page/targets/dom_target.rb +8 -6
  70. data/lib/volt/page/targets/dom_template.rb +90 -88
  71. data/lib/volt/page/targets/helpers/comment_searchers.rb +51 -49
  72. data/lib/volt/page/tasks.rb +59 -57
  73. data/lib/volt/page/template_renderer.rb +17 -14
  74. data/lib/volt/page/url_tracker.rb +26 -24
  75. data/lib/volt/reactive/computation.rb +87 -88
  76. data/lib/volt/reactive/dependency.rb +30 -28
  77. data/lib/volt/reactive/eventable.rb +64 -62
  78. data/lib/volt/reactive/hash_dependency.rb +25 -23
  79. data/lib/volt/reactive/reactive_accessors.rb +34 -32
  80. data/lib/volt/reactive/reactive_array.rb +162 -162
  81. data/lib/volt/reactive/reactive_hash.rb +37 -35
  82. data/lib/volt/router/routes.rb +99 -101
  83. data/lib/volt/server/component_handler.rb +20 -21
  84. data/lib/volt/server/component_templates.rb +72 -70
  85. data/lib/volt/server/html_parser/attribute_scope.rb +109 -99
  86. data/lib/volt/server/html_parser/each_scope.rb +17 -16
  87. data/lib/volt/server/html_parser/if_view_scope.rb +51 -49
  88. data/lib/volt/server/html_parser/sandlebars_parser.rb +184 -177
  89. data/lib/volt/server/html_parser/textarea_scope.rb +24 -22
  90. data/lib/volt/server/html_parser/view_handler.rb +66 -65
  91. data/lib/volt/server/html_parser/view_parser.rb +23 -21
  92. data/lib/volt/server/html_parser/view_scope.rb +142 -141
  93. data/lib/volt/server/rack/asset_files.rb +81 -79
  94. data/lib/volt/server/rack/component_code.rb +17 -15
  95. data/lib/volt/server/rack/component_html_renderer.rb +14 -12
  96. data/lib/volt/server/rack/component_paths.rb +72 -71
  97. data/lib/volt/server/rack/index_files.rb +36 -39
  98. data/lib/volt/server/rack/opal_files.rb +43 -41
  99. data/lib/volt/server/rack/source_map_server.rb +23 -21
  100. data/lib/volt/server/socket_connection_handler.rb +46 -45
  101. data/lib/volt/server/socket_connection_handler_stub.rb +21 -19
  102. data/lib/volt/server.rb +60 -58
  103. data/lib/volt/spec/setup.rb +3 -3
  104. data/lib/volt/tasks/dispatcher.rb +24 -23
  105. data/lib/volt/tasks/task_handler.rb +35 -33
  106. data/lib/volt/utils/ejson.rb +8 -6
  107. data/lib/volt/utils/generic_counting_pool.rb +33 -31
  108. data/lib/volt/utils/generic_pool.rb +73 -70
  109. data/lib/volt/utils/local_storage.rb +42 -38
  110. data/lib/volt/volt/environment.rb +1 -1
  111. data/lib/volt.rb +44 -42
  112. data/spec/apps/kitchen_sink/app/main/assets/css/todos.css +28 -0
  113. data/spec/apps/kitchen_sink/app/main/config/routes.rb +1 -0
  114. data/spec/apps/kitchen_sink/app/main/controllers/main_controller.rb +2 -2
  115. data/spec/apps/kitchen_sink/app/main/controllers/todos_controller.rb +17 -0
  116. data/spec/apps/kitchen_sink/app/main/views/main/main.html +1 -0
  117. data/spec/apps/kitchen_sink/app/main/views/todos/index.html +24 -0
  118. data/spec/apps/kitchen_sink/config.ru +1 -1
  119. data/spec/controllers/reactive_accessors_spec.rb +5 -5
  120. data/spec/extra_core/inflector_spec.rb +2 -2
  121. data/spec/integration/list_spec.rb +68 -0
  122. data/spec/models/model_spec.rb +57 -57
  123. data/spec/models/persistors/params_spec.rb +6 -6
  124. data/spec/models/persistors/store_spec.rb +7 -7
  125. data/spec/models/validations_spec.rb +3 -3
  126. data/spec/page/bindings/content_binding_spec.rb +7 -7
  127. data/spec/page/bindings/template_binding_spec.rb +4 -5
  128. data/spec/page/sub_context_spec.rb +2 -2
  129. data/spec/reactive/computation_spec.rb +10 -10
  130. data/spec/reactive/dependency_spec.rb +2 -2
  131. data/spec/reactive/eventable_spec.rb +4 -4
  132. data/spec/reactive/reactive_array_spec.rb +13 -13
  133. data/spec/router/routes_spec.rb +5 -5
  134. data/spec/server/html_parser/sandlebars_parser_spec.rb +9 -9
  135. data/spec/server/html_parser/view_parser_spec.rb +27 -27
  136. data/spec/server/rack/asset_files_spec.rb +5 -5
  137. data/spec/server/rack/component_paths_spec.rb +2 -2
  138. data/spec/tasks/live_query_spec.rb +2 -2
  139. data/spec/tasks/query_tasks.rb +1 -1
  140. data/spec/tasks/query_tracker_spec.rb +1 -1
  141. data/spec/templates/targets/binding_document/component_node_spec.rb +2 -2
  142. data/spec/utils/generic_counting_pool_spec.rb +2 -2
  143. data/spec/utils/generic_pool_spec.rb +2 -2
  144. data/templates/component/controllers/main_controller.rb +1 -1
  145. data/templates/model/model.rb.tt +2 -2
  146. data/templates/newgem/app/newgem/controllers/main_controller.rb.tt +2 -2
  147. data/templates/project/app/main/controllers/main_controller.rb +1 -1
  148. data/templates/project/config.ru +1 -1
  149. metadata +10 -3
  150. data/app/volt/assets/js/vertxbus.js +0 -216
data/lib/volt.rb CHANGED
@@ -8,47 +8,49 @@ else
8
8
  require 'volt/data_stores/data_store'
9
9
  end
10
10
 
11
- class Volt
12
- if RUBY_PLATFORM == 'opal'
13
- @@in_browser = `!!document && !window.OPAL_SPEC_PHANTOM`
14
- else
15
- @@in_browser = false
11
+ module Volt
12
+ @in_browser = if RUBY_PLATFORM == 'opal'
13
+ `!!document && !window.OPAL_SPEC_PHANTOM`
14
+ else
15
+ false
16
+ end
17
+
18
+ class << self
19
+ include Volt::Config unless RUBY_PLATFORM == 'opal'
20
+ def root
21
+ @root ||= File.expand_path(Dir.pwd)
22
+ end
23
+
24
+ def root=(val)
25
+ @root = val
26
+ end
27
+
28
+ def server?
29
+ !!ENV['SERVER']
30
+ end
31
+
32
+ def client?
33
+ !ENV['SERVER']
34
+ end
35
+
36
+ def source_maps?
37
+ !!ENV['MAPS']
38
+ end
39
+
40
+ def env
41
+ @env ||= Volt::Environment.new
42
+ end
43
+
44
+ def logger
45
+ @logger ||= Logger.new
46
+ end
47
+
48
+ def logger=(val)
49
+ @logger = val
50
+ end
51
+
52
+ def in_browser?
53
+ @in_browser
54
+ end
16
55
  end
17
-
18
- def self.root
19
- @root ||= File.expand_path(Dir.pwd)
20
- end
21
-
22
- def self.root=(val)
23
- @root = val
24
- end
25
-
26
- def self.server?
27
- !!ENV['SERVER']
28
- end
29
-
30
- def self.client?
31
- !ENV['SERVER']
32
- end
33
-
34
- def self.source_maps?
35
- !!ENV['MAPS']
36
- end
37
-
38
- def self.env
39
- @env ||= Volt::Environment.new
40
- end
41
-
42
- def self.logger
43
- @logger ||= Logger.new
44
- end
45
-
46
- def self.logger=(val)
47
- @logger = val
48
- end
49
-
50
- def self.in_browser?
51
- @@in_browser
52
- end
53
-
54
56
  end
@@ -0,0 +1,28 @@
1
+ .todo-table {
2
+ width: auto;
3
+ }
4
+
5
+ .todo-table td {
6
+ padding: 5px;
7
+ border-top: 1px solid #EEEEEE;
8
+ }
9
+
10
+ .complete, tr.selected td.complete {
11
+ text-decoration: line-through;
12
+ color: #CCCCCC;
13
+ }
14
+
15
+ tr.selected td {
16
+ background-color: #428bca;
17
+ color: #FFFFFF;
18
+ }
19
+
20
+
21
+ textarea {
22
+ height: 140px;
23
+ width: 400px;
24
+ }
25
+
26
+ tr.selected td button {
27
+ color: #000000;
28
+ }
@@ -3,6 +3,7 @@
3
3
  get "/bindings/{{_route_test}}", _action: 'bindings'
4
4
  get "/bindings", _action: 'bindings'
5
5
  get "/store", _action: 'store'
6
+ get "/todos", _controller: 'todos'
6
7
 
7
8
  # The main route, this should be last. It will match any params not previously matched.
8
9
  get '/', {}
@@ -1,4 +1,4 @@
1
- class MainController < ModelController
1
+ class MainController < Volt::ModelController
2
2
  model :page
3
3
 
4
4
  private
@@ -8,4 +8,4 @@ class MainController < ModelController
8
8
  def main_path
9
9
  params._controller.or('main') + "/" + params._action.or('index')
10
10
  end
11
- end
11
+ end
@@ -0,0 +1,17 @@
1
+ class TodosController < Volt::ModelController
2
+ model :page
3
+
4
+ def add_todo
5
+ self._todos << {name: self._new_todo}
6
+ self._new_todo = ''
7
+ end
8
+
9
+ def remove_todo(todo)
10
+ self._todos.delete(todo)
11
+ end
12
+
13
+ def completed
14
+ self._todos.count {|t| t._completed }
15
+ end
16
+
17
+ end
@@ -7,6 +7,7 @@
7
7
  <ul class="nav nav-pills pull-right">
8
8
  <:nav href="/" text="Home" />
9
9
  <:nav href="/bindings" text="Bindings" />
10
+ <:nav href="/todos" text="Todos" />
10
11
  <:nav href="/store" text="Store" />
11
12
  </ul>
12
13
  <h3 class="text-muted">Project name</h3>
@@ -0,0 +1,24 @@
1
+ <:Title>
2
+ Todos
3
+
4
+ <:Body>
5
+ <h1>Todos Example</h1>
6
+
7
+ <div id="count">{{ completed }} of {{ _todos.size }}</div>
8
+
9
+ <table id="todos-table" class="table">
10
+ {{ _todos.each do |todo| }}
11
+ <tr>
12
+ <td><input type="checkbox" checked="{{ todo._completed }}"></td>
13
+ <td class="name {{ if todo._completed }}complete{{ end }}">{{todo._name}}</td>
14
+ <td><button e-click="remove_todo(todo)">X</button></td>
15
+ </tr>
16
+ {{ end }}
17
+ </table>
18
+
19
+ <form e-submit="add_todo" role="form">
20
+ <div class="form-group">
21
+ <label>Todo</label>
22
+ <input class="form-control" id="newtodo" type="text" value="{{ page._new_todo }}" />
23
+ </div>
24
+ </form>
@@ -1,4 +1,4 @@
1
1
  # Run via rack server
2
2
  require 'bundler/setup'
3
3
  require 'volt/server'
4
- run Server.new.app
4
+ run Volt::Server.new.app
@@ -2,12 +2,12 @@ require 'spec_helper'
2
2
  require 'volt/reactive/reactive_accessors'
3
3
 
4
4
  class TestReactiveAccessors
5
- include ReactiveAccessors
5
+ include Volt::ReactiveAccessors
6
6
 
7
7
  reactive_accessor :_name
8
8
  end
9
9
 
10
- describe ReactiveAccessors do
10
+ describe Volt::ReactiveAccessors do
11
11
  it "should assign a reactive value" do
12
12
  inst = TestReactiveAccessors.new
13
13
 
@@ -30,11 +30,11 @@ describe ReactiveAccessors do
30
30
  expect(values).to eq([nil])
31
31
 
32
32
  inst._name = 'Ryan'
33
- Computation.flush!
33
+ Volt::Computation.flush!
34
34
  expect(values).to eq([nil,'Ryan'])
35
35
 
36
36
  inst._name = 'Stout'
37
- Computation.flush!
37
+ Volt::Computation.flush!
38
38
  expect(values).to eq([nil,'Ryan','Stout'])
39
39
  end
40
- end
40
+ end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
  require 'volt/extra_core/inflector'
3
3
 
4
- describe Inflector do
4
+ describe Volt::Inflector do
5
5
  it "should pluralize correctly" do
6
6
  expect('car'.pluralize).to eq('cars')
7
7
  # expect('database'.pluralize).to eq('database')
8
8
  end
9
- end
9
+ end
@@ -0,0 +1,68 @@
1
+ if ENV['BROWSER'] == 'firefox'
2
+ require 'spec_helper'
3
+
4
+ describe "todo example spec", :type => :feature do
5
+ before do
6
+ visit '/'
7
+
8
+ click_link 'Todos'
9
+
10
+
11
+ fill_in('newtodo', :with => "Item 1\n")
12
+ fill_in('newtodo', :with => "Item 2\n")
13
+ fill_in('newtodo', :with => "Item 3\n")
14
+ end
15
+
16
+ it "should add items to the list" do
17
+ expect(find('#todos-table')).to have_content('Item 1')
18
+ end
19
+
20
+ it 'should strikethrough when the checkbox is checked' do
21
+ box = all(:css, "#todos-table input[type=checkbox]")[0]
22
+
23
+ expect(find('#todos-table')).to_not have_css('td.name.complete')
24
+
25
+ box.set(true)
26
+ expect(find('#todos-table')).to have_css('td.name.complete')
27
+
28
+ box.set(false)
29
+ expect(find('#todos-table')).to_not have_css('td.name.complete')
30
+ end
31
+
32
+ it 'should delete items' do
33
+ expect(find('#todos-table')).to have_content('Item 1')
34
+ expect(find('#todos-table')).to have_content('Item 2')
35
+ expect(find('#todos-table')).to have_content('Item 3')
36
+
37
+ # Click the middle one
38
+ all(:css, "#todos-table button")[1].click
39
+
40
+ expect(find('#todos-table')).to have_content('Item 1')
41
+ expect(find('#todos-table')).to_not have_content('Item 2')
42
+ expect(find('#todos-table')).to have_content('Item 3')
43
+ end
44
+
45
+ it 'should track the number of todos and the numbers that are complete' do
46
+ count = find('#count')
47
+
48
+ expect(count).to have_content('0 of 3')
49
+
50
+ box1 = all(:css, "#todos-table input[type=checkbox]")[0]
51
+ box1.set(true)
52
+
53
+ expect(count).to have_content('1 of 3')
54
+
55
+ all(:css, "#todos-table button")[0].click
56
+ expect(count).to have_content('0 of 2')
57
+
58
+ box1 = all(:css, "#todos-table input[type=checkbox]")[0]
59
+ box1.set(true)
60
+ expect(count).to have_content('1 of 2')
61
+
62
+ box2 = all(:css, "#todos-table input[type=checkbox]")[1]
63
+ box2.set(true)
64
+
65
+ expect(count).to have_content('2 of 2')
66
+ end
67
+ end
68
+ end