volt 0.8.14 → 0.8.15
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 +4 -4
- data/.gitignore +1 -1
- data/Readme.md +8 -2
- data/VERSION +1 -1
- data/app/volt/controllers/notices_controller.rb +1 -1
- data/app/volt/models/user.rb +2 -2
- data/app/volt/tasks/live_query/live_query_pool.rb +1 -1
- data/app/volt/tasks/query_tasks.rb +1 -1
- data/app/volt/tasks/store_tasks.rb +1 -1
- data/app/volt/tasks/user_tasks.rb +2 -2
- data/lib/volt/boot.rb +2 -2
- data/lib/volt/cli/asset_compile.rb +31 -27
- data/lib/volt/cli.rb +64 -65
- data/lib/volt/config.rb +25 -23
- data/lib/volt/console.rb +17 -16
- data/lib/volt/controllers/model_controller.rb +82 -80
- data/lib/volt/data_stores/data_store.rb +2 -2
- data/lib/volt/data_stores/mongo_driver.rb +2 -2
- data/lib/volt/extra_core/inflections.rb +2 -2
- data/lib/volt/extra_core/inflector/inflections.rb +185 -183
- data/lib/volt/extra_core/inflector/methods.rb +50 -48
- data/lib/volt/extra_core/string.rb +2 -2
- data/lib/volt/models/array_model.rb +93 -92
- data/lib/volt/models/cursor.rb +3 -2
- data/lib/volt/models/model.rb +248 -251
- data/lib/volt/models/model_hash_behaviour.rb +44 -44
- data/lib/volt/models/model_helpers.rb +38 -36
- data/lib/volt/models/model_state.rb +16 -17
- data/lib/volt/models/model_wrapper.rb +25 -24
- data/lib/volt/models/persistors/array_store.rb +145 -143
- data/lib/volt/models/persistors/base.rb +18 -16
- data/lib/volt/models/persistors/flash.rb +24 -22
- data/lib/volt/models/persistors/local_store.rb +46 -44
- data/lib/volt/models/persistors/model_identity_map.rb +10 -8
- data/lib/volt/models/persistors/model_store.rb +76 -76
- data/lib/volt/models/persistors/params.rb +19 -17
- data/lib/volt/models/persistors/query/query_listener.rb +65 -63
- data/lib/volt/models/persistors/query/query_listener_pool.rb +12 -10
- data/lib/volt/models/persistors/store.rb +28 -28
- data/lib/volt/models/persistors/store_factory.rb +12 -10
- data/lib/volt/models/persistors/store_state.rb +33 -31
- data/lib/volt/models/url.rb +96 -104
- data/lib/volt/models/validations.rb +56 -54
- data/lib/volt/models/validators/length_validator.rb +24 -22
- data/lib/volt/models/validators/presence_validator.rb +14 -12
- data/lib/volt/page/bindings/attribute_binding.rb +106 -106
- data/lib/volt/page/bindings/base_binding.rb +23 -21
- data/lib/volt/page/bindings/component_binding.rb +3 -1
- data/lib/volt/page/bindings/content_binding.rb +34 -34
- data/lib/volt/page/bindings/each_binding.rb +113 -113
- data/lib/volt/page/bindings/event_binding.rb +38 -34
- data/lib/volt/page/bindings/if_binding.rb +56 -54
- data/lib/volt/page/bindings/template_binding/grouped_controllers.rb +24 -22
- data/lib/volt/page/bindings/template_binding.rb +182 -185
- data/lib/volt/page/channel.rb +79 -77
- data/lib/volt/page/channel_stub.rb +29 -27
- data/lib/volt/page/document.rb +6 -5
- data/lib/volt/page/document_events.rb +54 -52
- data/lib/volt/page/page.rb +139 -138
- data/lib/volt/page/string_template_renderer.rb +36 -36
- data/lib/volt/page/sub_context.rb +26 -25
- data/lib/volt/page/targets/attribute_section.rb +27 -25
- data/lib/volt/page/targets/attribute_target.rb +7 -6
- data/lib/volt/page/targets/base_section.rb +27 -26
- data/lib/volt/page/targets/binding_document/base_node.rb +3 -1
- data/lib/volt/page/targets/binding_document/component_node.rb +85 -82
- data/lib/volt/page/targets/binding_document/html_node.rb +11 -9
- data/lib/volt/page/targets/dom_section.rb +78 -77
- data/lib/volt/page/targets/dom_target.rb +8 -6
- data/lib/volt/page/targets/dom_template.rb +90 -88
- data/lib/volt/page/targets/helpers/comment_searchers.rb +51 -49
- data/lib/volt/page/tasks.rb +59 -57
- data/lib/volt/page/template_renderer.rb +17 -14
- data/lib/volt/page/url_tracker.rb +26 -24
- data/lib/volt/reactive/computation.rb +87 -88
- data/lib/volt/reactive/dependency.rb +30 -28
- data/lib/volt/reactive/eventable.rb +64 -62
- data/lib/volt/reactive/hash_dependency.rb +25 -23
- data/lib/volt/reactive/reactive_accessors.rb +34 -32
- data/lib/volt/reactive/reactive_array.rb +162 -162
- data/lib/volt/reactive/reactive_hash.rb +37 -35
- data/lib/volt/router/routes.rb +99 -101
- data/lib/volt/server/component_handler.rb +20 -21
- data/lib/volt/server/component_templates.rb +72 -70
- data/lib/volt/server/html_parser/attribute_scope.rb +109 -99
- data/lib/volt/server/html_parser/each_scope.rb +17 -16
- data/lib/volt/server/html_parser/if_view_scope.rb +51 -49
- data/lib/volt/server/html_parser/sandlebars_parser.rb +184 -177
- data/lib/volt/server/html_parser/textarea_scope.rb +24 -22
- data/lib/volt/server/html_parser/view_handler.rb +66 -65
- data/lib/volt/server/html_parser/view_parser.rb +23 -21
- data/lib/volt/server/html_parser/view_scope.rb +142 -141
- data/lib/volt/server/rack/asset_files.rb +81 -79
- data/lib/volt/server/rack/component_code.rb +17 -15
- data/lib/volt/server/rack/component_html_renderer.rb +14 -12
- data/lib/volt/server/rack/component_paths.rb +72 -71
- data/lib/volt/server/rack/index_files.rb +36 -39
- data/lib/volt/server/rack/opal_files.rb +43 -41
- data/lib/volt/server/rack/source_map_server.rb +23 -21
- data/lib/volt/server/socket_connection_handler.rb +46 -45
- data/lib/volt/server/socket_connection_handler_stub.rb +21 -19
- data/lib/volt/server.rb +60 -58
- data/lib/volt/spec/setup.rb +3 -3
- data/lib/volt/tasks/dispatcher.rb +24 -23
- data/lib/volt/tasks/task_handler.rb +35 -33
- data/lib/volt/utils/ejson.rb +8 -6
- data/lib/volt/utils/generic_counting_pool.rb +33 -31
- data/lib/volt/utils/generic_pool.rb +73 -70
- data/lib/volt/utils/local_storage.rb +42 -38
- data/lib/volt/volt/environment.rb +1 -1
- data/lib/volt.rb +44 -42
- data/spec/apps/kitchen_sink/app/main/assets/css/todos.css +28 -0
- data/spec/apps/kitchen_sink/app/main/config/routes.rb +1 -0
- data/spec/apps/kitchen_sink/app/main/controllers/main_controller.rb +2 -2
- data/spec/apps/kitchen_sink/app/main/controllers/todos_controller.rb +17 -0
- data/spec/apps/kitchen_sink/app/main/views/main/main.html +1 -0
- data/spec/apps/kitchen_sink/app/main/views/todos/index.html +24 -0
- data/spec/apps/kitchen_sink/config.ru +1 -1
- data/spec/controllers/reactive_accessors_spec.rb +5 -5
- data/spec/extra_core/inflector_spec.rb +2 -2
- data/spec/integration/list_spec.rb +68 -0
- data/spec/models/model_spec.rb +57 -57
- data/spec/models/persistors/params_spec.rb +6 -6
- data/spec/models/persistors/store_spec.rb +7 -7
- data/spec/models/validations_spec.rb +3 -3
- data/spec/page/bindings/content_binding_spec.rb +7 -7
- data/spec/page/bindings/template_binding_spec.rb +4 -5
- data/spec/page/sub_context_spec.rb +2 -2
- data/spec/reactive/computation_spec.rb +10 -10
- data/spec/reactive/dependency_spec.rb +2 -2
- data/spec/reactive/eventable_spec.rb +4 -4
- data/spec/reactive/reactive_array_spec.rb +13 -13
- data/spec/router/routes_spec.rb +5 -5
- data/spec/server/html_parser/sandlebars_parser_spec.rb +9 -9
- data/spec/server/html_parser/view_parser_spec.rb +27 -27
- data/spec/server/rack/asset_files_spec.rb +5 -5
- data/spec/server/rack/component_paths_spec.rb +2 -2
- data/spec/tasks/live_query_spec.rb +2 -2
- data/spec/tasks/query_tasks.rb +1 -1
- data/spec/tasks/query_tracker_spec.rb +1 -1
- data/spec/templates/targets/binding_document/component_node_spec.rb +2 -2
- data/spec/utils/generic_counting_pool_spec.rb +2 -2
- data/spec/utils/generic_pool_spec.rb +2 -2
- data/templates/component/controllers/main_controller.rb +1 -1
- data/templates/model/model.rb.tt +2 -2
- data/templates/newgem/app/newgem/controllers/main_controller.rb.tt +2 -2
- data/templates/project/app/main/controllers/main_controller.rb +1 -1
- data/templates/project/config.ru +1 -1
- metadata +10 -3
- 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
|
-
|
|
4
|
-
|
|
3
|
+
module Volt
|
|
4
|
+
class ViewScope
|
|
5
|
+
include AttributeScope
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
attr_reader :html, :bindings
|
|
8
|
+
attr_accessor :path, :binding_number
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
def initialize(handler, path)
|
|
11
|
+
@handler = handler
|
|
12
|
+
@path = path
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
@html = ''
|
|
15
|
+
@bindings = {}
|
|
16
|
+
@binding_number = 0
|
|
17
|
+
end
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
def <<(html)
|
|
20
|
+
@html << html
|
|
21
|
+
end
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
def add_else(content)
|
|
76
|
+
raise "#else can only be added inside of an if block"
|
|
77
|
+
end
|
|
77
78
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
def add_each(content)
|
|
80
|
+
@handler.scope << EachScope.new(@handler, @path + "/__each#{@binding_number}", content)
|
|
81
|
+
end
|
|
81
82
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
def add_template(content)
|
|
84
|
+
# Strip ( and ) from the outsides
|
|
85
|
+
content = content.strip.gsub(/^\(/, '').gsub(/\)$/, '')
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
90
|
-
|
|
90
|
+
@binding_number += 1
|
|
91
|
+
end
|
|
91
92
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
if parent.blank? || !getter.index('.')
|
|
99
|
+
parent = 'self'
|
|
100
|
+
end
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
return parent
|
|
103
|
+
end
|
|
103
104
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
def last_method_name(getter)
|
|
106
|
+
return getter.strip[/[^.]+$/]
|
|
107
|
+
end
|
|
107
108
|
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
def add_component(tag_name, attributes, unary)
|
|
110
|
+
component_name = tag_name[1..-1].gsub(':', '/')
|
|
110
111
|
|
|
111
|
-
|
|
112
|
+
@handler.html << "<!-- $#{@binding_number} --><!-- $/#{@binding_number} -->"
|
|
112
113
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
128
|
-
|
|
127
|
+
setter = getter_to_setter(getter)
|
|
128
|
+
data_hash << "#{(name + "=").inspect} => Proc.new { |val| #{setter} }"
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
# Add an _parent fetcher. Useful for things like volt-fields to get the parent model.
|
|
131
|
+
parent = parent_fetcher(getter)
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
138
|
-
|
|
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
|
-
|
|
146
|
+
arguments = "#{component_name.inspect}, { #{data_hash.join(',')} }"
|
|
147
147
|
|
|
148
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
@binding_number += 1
|
|
150
|
+
@binding_number += 1
|
|
151
|
+
end
|
|
156
152
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
162
|
-
|
|
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
|
-
|
|
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
|
-
|
|
172
|
-
'html' => scope.html
|
|
173
|
-
}
|
|
169
|
+
raise "template path already exists: #{scope.path}" if @handler.templates[scope.path]
|
|
174
170
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
end
|
|
171
|
+
template = {
|
|
172
|
+
'html' => scope.html
|
|
173
|
+
}
|
|
179
174
|
|
|
180
|
-
|
|
181
|
-
|
|
175
|
+
if scope.bindings.size > 0
|
|
176
|
+
# Add the bindings if there are any
|
|
177
|
+
template['bindings'] = scope.bindings
|
|
178
|
+
end
|
|
182
179
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
34
|
-
|
|
34
|
+
# Track that we added
|
|
35
|
+
@included_components[name] = true
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
# Load the dependencies
|
|
38
|
+
load_dependencies(path)
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
# Add any assets
|
|
41
|
+
add_assets(path)
|
|
42
|
+
@components << [path, name]
|
|
43
|
+
end
|
|
42
44
|
end
|
|
43
|
-
end
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
def components
|
|
47
|
+
@included_components.keys
|
|
48
|
+
end
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
def javascript_file(url)
|
|
51
|
+
@assets << [:javascript_file, url]
|
|
52
|
+
end
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
def css_file(url)
|
|
55
|
+
@assets << [:css_file, url]
|
|
56
|
+
end
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
def component_paths
|
|
59
|
+
return @components
|
|
60
|
+
end
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
89
|
+
javascript_files += opal_js_files
|
|
89
90
|
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
return javascript_files
|
|
92
|
+
end
|
|
92
93
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
15
|
-
|
|
15
|
+
def code
|
|
16
|
+
code = ''
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
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
|
-
|
|
5
|
-
|
|
4
|
+
module Volt
|
|
5
|
+
class ComponentHtmlRenderer
|
|
6
|
+
def initialize
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
end
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
def call(env)
|
|
11
|
+
req = Rack::Request.new(env)
|
|
12
|
+
path = req.path
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
# For now just assume main
|
|
15
|
+
component_name = 'main'
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
page = Page.new
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
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
|