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
@@ -1,187 +1,188 @@
1
1
  require 'volt/server/html_parser/attribute_scope'
2
2
 
3
- class ViewScope
4
- include AttributeScope
3
+ module Volt
4
+ class ViewScope
5
+ include AttributeScope
5
6
 
6
- attr_reader :html, :bindings
7
- attr_accessor :path, :binding_number
7
+ attr_reader :html, :bindings
8
+ attr_accessor :path, :binding_number
8
9
 
9
- def initialize(handler, path)
10
- @handler = handler
11
- @path = path
10
+ def initialize(handler, path)
11
+ @handler = handler
12
+ @path = path
12
13
 
13
- @html = ''
14
- @bindings = {}
15
- @binding_number = 0
16
- end
14
+ @html = ''
15
+ @bindings = {}
16
+ @binding_number = 0
17
+ end
17
18
 
18
- def <<(html)
19
- @html << html
20
- end
19
+ def <<(html)
20
+ @html << html
21
+ end
21
22
 
22
- def add_binding(content)
23
- content = content.strip
24
- index = content.index(/[ \(]/)
25
- if index
26
- first_symbol = content[0...index]
27
- args = content[index..-1].strip
28
-
29
- case first_symbol
30
- when 'if'
31
- add_if(args)
32
- when 'elsif'
33
- add_else(args)
34
- when 'else'
35
- if args.blank?
36
- add_else(nil)
37
- else
38
- raise "else does not take a conditional, #{content} was provided."
23
+ def add_binding(content)
24
+ content = content.strip
25
+ index = content.index(/[ \(]/)
26
+ if index
27
+ first_symbol = content[0...index]
28
+ args = content[index..-1].strip
29
+
30
+ case first_symbol
31
+ when 'if'
32
+ add_if(args)
33
+ when 'elsif'
34
+ add_else(args)
35
+ when 'else'
36
+ if args.blank?
37
+ add_else(nil)
38
+ else
39
+ raise "else does not take a conditional, #{content} was provided."
40
+ end
41
+ when 'template'
42
+ add_template(args)
43
+ else
44
+ if content =~ /.each\s+do\s+\|/
45
+ add_each(content)
46
+ else
47
+ add_content_binding(content)
48
+ end
39
49
  end
40
- when 'template'
41
- add_template(args)
42
50
  else
43
- if content =~ /.each\s+do\s+\|/
44
- add_each(content)
45
- else
46
- add_content_binding(content)
51
+ case content
52
+ when 'end'
53
+ # Close the binding
54
+ close_scope
55
+ when 'else'
56
+ add_else(nil)
57
+ else
58
+ add_content_binding(content)
47
59
  end
48
60
  end
49
- else
50
- case content
51
- when 'end'
52
- # Close the binding
53
- close_scope
54
- when 'else'
55
- add_else(nil)
56
- else
57
- add_content_binding(content)
58
- end
59
61
  end
60
- end
61
62
 
62
- def add_content_binding(content)
63
- @handler.html << "<!-- $#{@binding_number} --><!-- $/#{@binding_number} -->"
64
- save_binding(@binding_number, "lambda { |__p, __t, __c, __id| ContentBinding.new(__p, __t, __c, __id, Proc.new { #{content} }) }")
65
- @binding_number += 1
66
- end
63
+ def add_content_binding(content)
64
+ @handler.html << "<!-- $#{@binding_number} --><!-- $/#{@binding_number} -->"
65
+ save_binding(@binding_number, "lambda { |__p, __t, __c, __id| Volt::ContentBinding.new(__p, __t, __c, __id, Proc.new { #{content} }) }")
66
+ @binding_number += 1
67
+ end
67
68
 
68
- def add_if(content)
69
- # Add with path for if group.
70
- @handler.scope << IfViewScope.new(@handler, @path + "/__ifg#{@binding_number}", content)
71
- @binding_number += 1
72
- end
69
+ def add_if(content)
70
+ # Add with path for if group.
71
+ @handler.scope << IfViewScope.new(@handler, @path + "/__ifg#{@binding_number}", content)
72
+ @binding_number += 1
73
+ end
73
74
 
74
- def add_else(content)
75
- raise "#else can only be added inside of an if block"
76
- end
75
+ def add_else(content)
76
+ raise "#else can only be added inside of an if block"
77
+ end
77
78
 
78
- def add_each(content)
79
- @handler.scope << EachScope.new(@handler, @path + "/__each#{@binding_number}", content)
80
- end
79
+ def add_each(content)
80
+ @handler.scope << EachScope.new(@handler, @path + "/__each#{@binding_number}", content)
81
+ end
81
82
 
82
- def add_template(content)
83
- # Strip ( and ) from the outsides
84
- content = content.strip.gsub(/^\(/, '').gsub(/\)$/, '')
83
+ def add_template(content)
84
+ # Strip ( and ) from the outsides
85
+ content = content.strip.gsub(/^\(/, '').gsub(/\)$/, '')
85
86
 
86
- @handler.html << "<!-- $#{@binding_number} --><!-- $/#{@binding_number} -->"
87
- save_binding(@binding_number, "lambda { |__p, __t, __c, __id| TemplateBinding.new(__p, __t, __c, __id, #{@path.inspect}, Proc.new { [#{content}] }) }")
87
+ @handler.html << "<!-- $#{@binding_number} --><!-- $/#{@binding_number} -->"
88
+ save_binding(@binding_number, "lambda { |__p, __t, __c, __id| Volt::TemplateBinding.new(__p, __t, __c, __id, #{@path.inspect}, Proc.new { [#{content}] }) }")
88
89
 
89
- @binding_number += 1
90
- end
90
+ @binding_number += 1
91
+ end
91
92
 
92
- # Returns ruby code to fetch the parent. (by removing the last fetch)
93
- # TODO: Probably want to do this with AST transforms with the parser/unparser gems
94
- def parent_fetcher(getter)
95
- parent = getter.strip.gsub(/[.][^.]+$/, '')
93
+ # Returns ruby code to fetch the parent. (by removing the last fetch)
94
+ # TODO: Probably want to do this with AST transforms with the parser/unparser gems
95
+ def parent_fetcher(getter)
96
+ parent = getter.strip.gsub(/[.][^.]+$/, '')
96
97
 
97
- if parent.blank? || !getter.index('.')
98
- parent = 'self'
99
- end
98
+ if parent.blank? || !getter.index('.')
99
+ parent = 'self'
100
+ end
100
101
 
101
- return parent
102
- end
102
+ return parent
103
+ end
103
104
 
104
- def last_method_name(getter)
105
- return getter.strip[/[^.]+$/]
106
- end
105
+ def last_method_name(getter)
106
+ return getter.strip[/[^.]+$/]
107
+ end
107
108
 
108
- def add_component(tag_name, attributes, unary)
109
- component_name = tag_name[1..-1].gsub(':', '/')
109
+ def add_component(tag_name, attributes, unary)
110
+ component_name = tag_name[1..-1].gsub(':', '/')
110
111
 
111
- @handler.html << "<!-- $#{@binding_number} --><!-- $/#{@binding_number} -->"
112
+ @handler.html << "<!-- $#{@binding_number} --><!-- $/#{@binding_number} -->"
112
113
 
113
- data_hash = []
114
- attributes.each_pair do |name, value|
115
- parts = value.split(/(\{\{[^\}]+\}\})/).reject(&:blank?)
116
- binding_count = parts.count {|p| p[0] == '{' && p[1] == '{' && p[-2] == '}' && p[-1] == '}'}
114
+ data_hash = []
115
+ attributes.each_pair do |name, value|
116
+ parts, binding_count = binding_parts_and_count(value)
117
117
 
118
- # if this attribute has bindings
119
- if binding_count > 0
120
- if binding_count > 1
121
- # Multiple bindings
122
- elsif parts.size == 1 && binding_count == 1
123
- # A single binding
124
- getter = value[2...-2].strip
125
- data_hash << "#{name.inspect} => Proc.new { #{getter} }"
118
+ # if this attribute has bindings
119
+ if binding_count > 0
120
+ if binding_count > 1
121
+ # Multiple bindings
122
+ elsif parts.size == 1 && binding_count == 1
123
+ # A single binding
124
+ getter = value[2...-2].strip
125
+ data_hash << "#{name.inspect} => Proc.new { #{getter} }"
126
126
 
127
- setter = getter_to_setter(getter)
128
- data_hash << "#{(name + "=").inspect} => Proc.new { |val| #{setter} }"
127
+ setter = getter_to_setter(getter)
128
+ data_hash << "#{(name + "=").inspect} => Proc.new { |val| #{setter} }"
129
129
 
130
- # Add an _parent fetcher. Useful for things like volt-fields to get the parent model.
131
- parent = parent_fetcher(getter)
130
+ # Add an _parent fetcher. Useful for things like volt-fields to get the parent model.
131
+ parent = parent_fetcher(getter)
132
132
 
133
- # TODO: This adds some overhead, perhaps there is a way to compute this dynamically on the
134
- # front-end.
135
- data_hash << "#{(name + "_parent").inspect} => Proc.new { #{parent} }"
133
+ # TODO: This adds some overhead, perhaps there is a way to compute this dynamically on the
134
+ # front-end.
135
+ data_hash << "#{(name + "_parent").inspect} => Proc.new { #{parent} }"
136
136
 
137
- # Add a _last_method property. This is useful
138
- data_hash << "#{(name + "_last_method").inspect} => #{last_method_name(getter).inspect}"
137
+ # Add a _last_method property. This is useful
138
+ data_hash << "#{(name + "_last_method").inspect} => #{last_method_name(getter).inspect}"
139
+ end
140
+ else
141
+ # String
142
+ data_hash << "#{name.inspect} => #{value.inspect}"
139
143
  end
140
- else
141
- # String
142
- data_hash << "#{name.inspect} => #{value.inspect}"
143
144
  end
144
- end
145
145
 
146
- arguments = "#{component_name.inspect}, { #{data_hash.join(',')} }"
146
+ arguments = "#{component_name.inspect}, { #{data_hash.join(',')} }"
147
147
 
148
- save_binding(@binding_number, "lambda { |__p, __t, __c, __id| ComponentBinding.new(__p, __t, __c, __id, #{@path.inspect}, Proc.new { [#{arguments}] }) }")
149
-
150
- @binding_number += 1
151
- end
148
+ save_binding(@binding_number, "lambda { |__p, __t, __c, __id| Volt::ComponentBinding.new(__p, __t, __c, __id, #{@path.inspect}, Proc.new { [#{arguments}] }) }")
152
149
 
153
- def add_textarea(tag_name, attributes, unary)
154
- @handler.scope << TextareaScope.new(@handler, @path + "/__txtarea#{@binding_number}", attributes)
155
- @binding_number += 1
150
+ @binding_number += 1
151
+ end
156
152
 
157
- # close right away if unary
158
- @handler.last.close_scope if unary
159
- end
153
+ def add_textarea(tag_name, attributes, unary)
154
+ @handler.scope << TextareaScope.new(@handler, @path + "/__txtarea#{@binding_number}", attributes)
155
+ @binding_number += 1
160
156
 
161
- # Called when this scope should be closed out
162
- def close_scope(pop=true)
163
- if pop
164
- scope = @handler.scope.pop
165
- else
166
- scope = @handler.last
157
+ # close right away if unary
158
+ @handler.last.close_scope if unary
167
159
  end
168
160
 
169
- raise "template path already exists: #{scope.path}" if @handler.templates[scope.path]
161
+ # Called when this scope should be closed out
162
+ def close_scope(pop=true)
163
+ if pop
164
+ scope = @handler.scope.pop
165
+ else
166
+ scope = @handler.last
167
+ end
170
168
 
171
- template = {
172
- 'html' => scope.html
173
- }
169
+ raise "template path already exists: #{scope.path}" if @handler.templates[scope.path]
174
170
 
175
- if scope.bindings.size > 0
176
- # Add the bindings if there are any
177
- template['bindings'] = scope.bindings
178
- end
171
+ template = {
172
+ 'html' => scope.html
173
+ }
179
174
 
180
- @handler.templates[scope.path] = template
181
- end
175
+ if scope.bindings.size > 0
176
+ # Add the bindings if there are any
177
+ template['bindings'] = scope.bindings
178
+ end
182
179
 
183
- def save_binding(binding_number, code)
184
- @bindings[binding_number] ||= []
185
- @bindings[binding_number] << code
180
+ @handler.templates[scope.path] = template
181
+ end
182
+
183
+ def save_binding(binding_number, code)
184
+ @bindings[binding_number] ||= []
185
+ @bindings[binding_number] << code
186
+ end
186
187
  end
187
188
  end
@@ -1,107 +1,109 @@
1
1
  # Used to get a list of the assets and other included components
2
2
  # from the dependencies.rb files.
3
- class AssetFiles
4
- def initialize(component_name, component_paths)
5
- @component_paths = component_paths
6
- @assets = []
7
- @included_components = {}
8
- @components = []
9
-
10
- component('volt')
11
- component(component_name)
12
- end
13
-
14
- def load_dependencies(path)
15
- if path
16
- dependencies_file = File.join(path, "config/dependencies.rb")
17
- else
18
- raise "Unable to find component #{component_name.inspect}"
3
+ module Volt
4
+ class AssetFiles
5
+ def initialize(component_name, component_paths)
6
+ @component_paths = component_paths
7
+ @assets = []
8
+ @included_components = {}
9
+ @components = []
10
+
11
+ component('volt')
12
+ component(component_name)
19
13
  end
20
14
 
21
- if File.exists?(dependencies_file)
22
- # Run the dependencies file in this asset files context
23
- code = File.read(dependencies_file)
24
- instance_eval(code)
15
+ def load_dependencies(path)
16
+ if path
17
+ dependencies_file = File.join(path, "config/dependencies.rb")
18
+ else
19
+ raise "Unable to find component #{component_name.inspect}"
20
+ end
21
+
22
+ if File.exists?(dependencies_file)
23
+ # Run the dependencies file in this asset files context
24
+ code = File.read(dependencies_file)
25
+ instance_eval(code)
26
+ end
25
27
  end
26
- end
27
28
 
28
- def component(name)
29
- unless @included_components[name]
30
- # Get the path to the component
31
- path = @component_paths.component_path(name)
29
+ def component(name)
30
+ unless @included_components[name]
31
+ # Get the path to the component
32
+ path = @component_paths.component_path(name)
32
33
 
33
- # Track that we added
34
- @included_components[name] = true
34
+ # Track that we added
35
+ @included_components[name] = true
35
36
 
36
- # Load the dependencies
37
- load_dependencies(path)
37
+ # Load the dependencies
38
+ load_dependencies(path)
38
39
 
39
- # Add any assets
40
- add_assets(path)
41
- @components << [path, name]
40
+ # Add any assets
41
+ add_assets(path)
42
+ @components << [path, name]
43
+ end
42
44
  end
43
- end
44
45
 
45
- def components
46
- @included_components.keys
47
- end
46
+ def components
47
+ @included_components.keys
48
+ end
48
49
 
49
- def javascript_file(url)
50
- @assets << [:javascript_file, url]
51
- end
50
+ def javascript_file(url)
51
+ @assets << [:javascript_file, url]
52
+ end
52
53
 
53
- def css_file(url)
54
- @assets << [:css_file, url]
55
- end
54
+ def css_file(url)
55
+ @assets << [:css_file, url]
56
+ end
56
57
 
57
- def component_paths
58
- return @components
59
- end
58
+ def component_paths
59
+ return @components
60
+ end
60
61
 
61
- def add_assets(path)
62
- asset_folder = File.join(path, 'assets')
63
- if File.directory?(asset_folder)
64
- @assets << [:folder, asset_folder]
62
+ def add_assets(path)
63
+ asset_folder = File.join(path, 'assets')
64
+ if File.directory?(asset_folder)
65
+ @assets << [:folder, asset_folder]
66
+ end
65
67
  end
66
- end
67
68
 
68
69
 
69
- def javascript_files(opal_files)
70
- javascript_files = []
71
- @assets.each do |type, path|
72
- case type
73
- when :folder
74
- javascript_files += Dir["#{path}/**/*.js"].sort.map {|folder| '/assets' + folder[path.size..-1] }
75
- when :javascript_file
76
- javascript_files << path
70
+ def javascript_files(opal_files)
71
+ javascript_files = []
72
+ @assets.each do |type, path|
73
+ case type
74
+ when :folder
75
+ javascript_files += Dir["#{path}/**/*.js"].sort.map { |folder| '/assets' + folder[path.size..-1] }
76
+ when :javascript_file
77
+ javascript_files << path
78
+ end
77
79
  end
78
- end
79
80
 
80
- opal_js_files = []
81
- if Volt.source_maps?
82
- opal_js_files += opal_files.environment['volt/page/page'].to_a.map {|v| '/assets/' + v.logical_path + '?body=1' }
83
- else
84
- opal_js_files << '/assets/volt/page/page.js'
85
- end
86
- opal_js_files << '/components/main.js'
81
+ opal_js_files = []
82
+ if Volt.source_maps?
83
+ opal_js_files += opal_files.environment['volt/page/page'].to_a.map { |v| '/assets/' + v.logical_path + '?body=1' }
84
+ else
85
+ opal_js_files << '/assets/volt/page/page.js'
86
+ end
87
+ opal_js_files << '/components/main.js'
87
88
 
88
- javascript_files += opal_js_files
89
+ javascript_files += opal_js_files
89
90
 
90
- return javascript_files
91
- end
91
+ return javascript_files
92
+ end
92
93
 
93
- def css_files
94
- css_files = []
95
- @assets.each do |type, path|
96
- case type
97
- when :folder
98
- css_files += Dir["#{path}/**/*.{css,scss}"].sort.map {|folder| '/assets' + folder[path.size..-1].gsub(/[.]scss$/, '') }
99
- when :css_file
100
- css_files << path
94
+ def css_files
95
+ css_files = []
96
+ @assets.each do |type, path|
97
+ case type
98
+ when :folder
99
+ css_files += Dir["#{path}/**/*.{css,scss}"].sort.map { |folder| '/assets' + folder[path.size..-1].gsub(/[.]scss$/, '') }
100
+ when :css_file
101
+ css_files << path
102
+ end
101
103
  end
104
+
105
+ return css_files
102
106
  end
103
107
 
104
- return css_files
105
108
  end
106
-
107
109
  end
@@ -4,22 +4,24 @@ require 'volt/server/rack/asset_files'
4
4
 
5
5
  # Takes in the name and all component paths and has a .code
6
6
  # method that returns all of the ruby setup code for the component.
7
- class ComponentCode
8
- def initialize(component_name, component_paths, client=true)
9
- @component_name = component_name
10
- @component_paths = component_paths
11
- @client = client
12
- end
7
+ module Volt
8
+ class ComponentCode
9
+ def initialize(component_name, component_paths, client=true)
10
+ @component_name = component_name
11
+ @component_paths = component_paths
12
+ @client = client
13
+ end
13
14
 
14
- def code
15
- code = ''
15
+ def code
16
+ code = ''
16
17
 
17
- asset_files = AssetFiles.new(@component_name, @component_paths)
18
- asset_files.component_paths.each do |component_path, component_name|
19
- code << ComponentTemplates.new(component_path, component_name, @client).code
20
- code << "\n\n"
21
- end
18
+ asset_files = AssetFiles.new(@component_name, @component_paths)
19
+ asset_files.component_paths.each do |component_path, component_name|
20
+ code << ComponentTemplates.new(component_path, component_name, @client).code
21
+ code << "\n\n"
22
+ end
22
23
 
23
- return code
24
+ return code
25
+ end
24
26
  end
25
- end
27
+ end
@@ -1,21 +1,23 @@
1
1
  require 'volt/page/page'
2
2
 
3
3
  # A rack app that renders the html for a component on the backend.
4
- class ComponentHtmlRenderer
5
- def initialize
4
+ module Volt
5
+ class ComponentHtmlRenderer
6
+ def initialize
6
7
 
7
- end
8
+ end
8
9
 
9
- def call(env)
10
- req = Rack::Request.new(env)
11
- path = req.path
10
+ def call(env)
11
+ req = Rack::Request.new(env)
12
+ path = req.path
12
13
 
13
- # For now just assume main
14
- component_name = 'main'
14
+ # For now just assume main
15
+ component_name = 'main'
15
16
 
16
- page = Page.new
17
+ page = Page.new
17
18
 
18
- component_paths = ComponentPaths.new(Volt.root)
19
- code = ComponentCode.new(component_name, component_paths).code
19
+ component_paths = ComponentPaths.new(Volt.root)
20
+ code = ComponentCode.new(component_name, component_paths).code
21
+ end
20
22
  end
21
- end
23
+ end