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
data/lib/volt/router/routes.rb
CHANGED
|
@@ -1,112 +1,110 @@
|
|
|
1
1
|
require 'volt'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
# a
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
# get "/
|
|
8
|
-
# get "/blog/{_id}", _view: 'blog/
|
|
9
|
-
# get "/blog", _view: 'blog'
|
|
10
|
-
# get "/blog
|
|
11
|
-
# get "/
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
# '/
|
|
19
|
-
# '/blog
|
|
20
|
-
# }
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
# --
|
|
24
|
-
# --
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
|
|
41
|
-
class Routes
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def define(&block)
|
|
54
|
-
instance_eval(&block)
|
|
3
|
+
module Volt
|
|
4
|
+
# The Routes class takes a set of routes and sets up methods to go from
|
|
5
|
+
# a url to params, and params to url.
|
|
6
|
+
# routes do
|
|
7
|
+
# get "/about", _view: 'about'
|
|
8
|
+
# get "/blog/{_id}/edit", _view: 'blog/edit', _action: 'edit'
|
|
9
|
+
# get "/blog/{_id}", _view: 'blog/show', _action: 'show'
|
|
10
|
+
# get "/blog", _view: 'blog'
|
|
11
|
+
# get "/blog/new", _view: 'blog/new', _action: 'new'
|
|
12
|
+
# get "/cool/{_name}", _view: 'cool'
|
|
13
|
+
# end
|
|
14
|
+
#
|
|
15
|
+
# Using the routes above, we would generate the following:
|
|
16
|
+
#
|
|
17
|
+
# @direct_routes = {
|
|
18
|
+
# '/about' => {_view: 'about'},
|
|
19
|
+
# '/blog' => {_view: 'blog'}
|
|
20
|
+
# '/blog/new' => {_view: 'blog/new', _action: 'new'}
|
|
21
|
+
# }
|
|
22
|
+
#
|
|
23
|
+
# -- nil represents a terminal
|
|
24
|
+
# -- * represents any match
|
|
25
|
+
# -- a number for a parameter means use the value in that number section
|
|
26
|
+
#
|
|
27
|
+
# @indirect_routes = {
|
|
28
|
+
# '*' => {
|
|
29
|
+
# 'edit' => {
|
|
30
|
+
# nil => {_id: 1, _view: 'blog/edit', _action: 'edit'}
|
|
31
|
+
# }
|
|
32
|
+
# nil => {_id: 1, _view: 'blog/show', _action: 'show'}
|
|
33
|
+
# }
|
|
34
|
+
# }
|
|
35
|
+
# }
|
|
36
|
+
#
|
|
37
|
+
# Match for params
|
|
38
|
+
# @param_matches = [
|
|
39
|
+
# {_id: nil, _view: 'blog/edit', _action: 'edit'} => Proc.new {|params| "/blog/#{params.id}/edit", params.reject {|k,v| k == :id }}
|
|
40
|
+
# ]
|
|
41
|
+
class Routes
|
|
42
|
+
def initialize
|
|
43
|
+
# Paths where there are no bindings (an optimization)
|
|
44
|
+
@direct_routes = {}
|
|
45
|
+
|
|
46
|
+
# Paths with bindings
|
|
47
|
+
@indirect_routes = {}
|
|
48
|
+
|
|
49
|
+
# Matcher for going from params to url
|
|
50
|
+
@param_matches = []
|
|
51
|
+
end
|
|
55
52
|
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
def define(&block)
|
|
54
|
+
instance_eval(&block)
|
|
58
55
|
|
|
59
|
-
|
|
60
|
-
def get(path, params={})
|
|
61
|
-
params = params.symbolize_keys
|
|
62
|
-
if has_binding?(path)
|
|
63
|
-
add_indirect_path(path, params)
|
|
64
|
-
else
|
|
65
|
-
@direct_routes[path] = params
|
|
56
|
+
return self
|
|
66
57
|
end
|
|
67
58
|
|
|
68
|
-
|
|
69
|
-
|
|
59
|
+
# Add a route
|
|
60
|
+
def get(path, params={})
|
|
61
|
+
params = params.symbolize_keys
|
|
62
|
+
if has_binding?(path)
|
|
63
|
+
add_indirect_path(path, params)
|
|
64
|
+
else
|
|
65
|
+
@direct_routes[path] = params
|
|
66
|
+
end
|
|
70
67
|
|
|
71
|
-
|
|
72
|
-
# that should be shown in the url. The extra "unused" params
|
|
73
|
-
# will be tacked onto the end of the url ?param1=value1, etc...
|
|
74
|
-
#
|
|
75
|
-
# returns the url and new params, or nil, nil if no match is found.
|
|
76
|
-
def params_to_url(test_params)
|
|
77
|
-
# Add in underscores
|
|
78
|
-
test_params = test_params.each_with_object({}) do |(k,v), obj|
|
|
79
|
-
obj[:"_#{k}"] = v
|
|
68
|
+
add_param_matcher(path, params)
|
|
80
69
|
end
|
|
81
70
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
71
|
+
# Takes in params and generates a path and the remaining params
|
|
72
|
+
# that should be shown in the url. The extra "unused" params
|
|
73
|
+
# will be tacked onto the end of the url ?param1=value1, etc...
|
|
74
|
+
#
|
|
75
|
+
# returns the url and new params, or nil, nil if no match is found.
|
|
76
|
+
def params_to_url(test_params)
|
|
77
|
+
# Add in underscores
|
|
78
|
+
test_params = test_params.each_with_object({}) do |(k, v), obj|
|
|
79
|
+
obj[:"_#{k}"] = v
|
|
88
80
|
end
|
|
89
|
-
end
|
|
90
81
|
|
|
91
|
-
|
|
92
|
-
|
|
82
|
+
@param_matches.each do |param_matcher|
|
|
83
|
+
# TODO: Maybe a deep dup?
|
|
84
|
+
result, new_params = check_params_match(test_params.dup, param_matcher[0])
|
|
93
85
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
result = @direct_routes[path]
|
|
99
|
-
return result if result
|
|
86
|
+
if result
|
|
87
|
+
return param_matcher[1].call(new_params)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
100
90
|
|
|
101
|
-
|
|
102
|
-
|
|
91
|
+
return nil, nil
|
|
92
|
+
end
|
|
103
93
|
|
|
104
|
-
|
|
94
|
+
# Takes in a path and returns the matching params.
|
|
95
|
+
# returns params as a hash
|
|
96
|
+
def url_to_params(path)
|
|
97
|
+
# First try a direct match
|
|
98
|
+
result = @direct_routes[path]
|
|
99
|
+
return result if result
|
|
105
100
|
|
|
106
|
-
|
|
107
|
-
|
|
101
|
+
# Next, split the url and walk the sections
|
|
102
|
+
parts = url_parts(path)
|
|
108
103
|
|
|
109
|
-
|
|
104
|
+
match_path(parts, parts, @indirect_routes)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
private
|
|
110
108
|
# Recursively walk the @indirect_routes hash, return the params for a route, return
|
|
111
109
|
# false for non-matches.
|
|
112
110
|
def match_path(original_parts, remaining_parts, node)
|
|
@@ -177,7 +175,7 @@ class Routes
|
|
|
177
175
|
|
|
178
176
|
def add_param_matcher(path, params)
|
|
179
177
|
params = params.dup
|
|
180
|
-
parts
|
|
178
|
+
parts = url_parts(path)
|
|
181
179
|
|
|
182
180
|
parts.each_with_index do |part, index|
|
|
183
181
|
if has_binding?(part)
|
|
@@ -201,12 +199,12 @@ class Routes
|
|
|
201
199
|
|
|
202
200
|
url = parts.map do |part|
|
|
203
201
|
val = if has_binding?(part)
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
202
|
+
# Get the
|
|
203
|
+
binding = part[2...-2].strip.to_sym
|
|
204
|
+
input_params.delete(binding)
|
|
205
|
+
else
|
|
206
|
+
part
|
|
207
|
+
end
|
|
210
208
|
|
|
211
209
|
val
|
|
212
210
|
end.join('/')
|
|
@@ -261,5 +259,5 @@ class Routes
|
|
|
261
259
|
def has_binding?(string)
|
|
262
260
|
string.index('{{') && string.index('}}')
|
|
263
261
|
end
|
|
264
|
-
|
|
262
|
+
end
|
|
265
263
|
end
|
|
@@ -2,34 +2,33 @@ require 'stringio'
|
|
|
2
2
|
require 'volt'
|
|
3
3
|
require 'volt/server/rack/component_code'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def call(env)
|
|
11
|
-
req = Rack::Request.new(env)
|
|
5
|
+
module Volt
|
|
6
|
+
class ComponentHandler
|
|
7
|
+
def initialize(component_paths)
|
|
8
|
+
@component_paths = component_paths
|
|
9
|
+
end
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
def call(env)
|
|
12
|
+
req = Rack::Request.new(env)
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
# TODO: Sanatize template path
|
|
15
|
+
component_name = req.path.strip.gsub(/^\/components\//, '').gsub(/[.]js$/, '')
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
end
|
|
17
|
+
javascript_code = compile_for_component(component_name)
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
return [200, {"Content-Type" => "application/javascript; charset=utf-8"}, StringIO.new(javascript_code)]
|
|
20
|
+
end
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
def compile_for_component(component_name)
|
|
23
|
+
code = ComponentCode.new(component_name, @component_paths).code
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
# Add the lib directory to the load path
|
|
26
|
+
Opal.append_path(Volt.root + '/lib')
|
|
29
27
|
|
|
30
|
-
|
|
28
|
+
# Compile the code
|
|
29
|
+
javascript_code = Opal.compile(code)
|
|
31
30
|
|
|
31
|
+
return javascript_code
|
|
32
|
+
end
|
|
32
33
|
end
|
|
33
|
-
|
|
34
|
-
|
|
35
34
|
end
|
|
@@ -2,104 +2,106 @@ require 'volt/server/html_parser/view_parser'
|
|
|
2
2
|
|
|
3
3
|
# Initialize with the path to a component and returns all the front-end
|
|
4
4
|
# setup code (for controllers, models, views, and routes)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def code
|
|
13
|
-
code = generate_view_code
|
|
14
|
-
if @client
|
|
15
|
-
# On the backend, we just need the views
|
|
16
|
-
code << generate_controller_code + generate_model_code + generate_routes_code + generate_tasks_code
|
|
5
|
+
module Volt
|
|
6
|
+
class ComponentTemplates
|
|
7
|
+
def initialize(component_path, component_name, client=true)
|
|
8
|
+
@component_path = component_path
|
|
9
|
+
@component_name = component_name
|
|
10
|
+
@client = true
|
|
17
11
|
end
|
|
18
12
|
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
def code
|
|
14
|
+
code = generate_view_code
|
|
15
|
+
if @client
|
|
16
|
+
# On the backend, we just need the views
|
|
17
|
+
code << generate_controller_code + generate_model_code + generate_routes_code + generate_tasks_code
|
|
18
|
+
end
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
if @client
|
|
24
|
-
'$page'
|
|
25
|
-
else
|
|
26
|
-
'page'
|
|
20
|
+
return code
|
|
27
21
|
end
|
|
28
|
-
end
|
|
29
22
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
def page_reference
|
|
24
|
+
if @client
|
|
25
|
+
'$page'
|
|
26
|
+
else
|
|
27
|
+
'page'
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def generate_view_code
|
|
32
|
+
code = ''
|
|
33
|
+
views_path = "#{@component_path}/views/"
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
# Load all templates in the folder
|
|
36
|
+
Dir["#{views_path}*/*.html"].sort.each do |view_path|
|
|
37
|
+
# Get the path for the template, supports templates in folders
|
|
38
|
+
template_path = view_path[views_path.size..((-1 * ('.html'.size + 1)))]
|
|
39
|
+
template_path = "#{@component_name}/#{template_path}"
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
all_templates = ViewParser.new(File.read(view_path), template_path)
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
binding_initializers = []
|
|
44
|
+
all_templates.templates.each_pair do |name, template|
|
|
45
|
+
binding_code = []
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
if template['bindings']
|
|
48
|
+
template['bindings'].each_pair do |key, value|
|
|
49
|
+
binding_code << "#{key.inspect} => [#{value.join(', ')}]"
|
|
50
|
+
end
|
|
49
51
|
end
|
|
50
|
-
end
|
|
51
52
|
|
|
52
|
-
|
|
53
|
+
binding_code = "{#{binding_code.join(', ')}}"
|
|
53
54
|
|
|
54
|
-
|
|
55
|
+
code << "#{page_reference}.add_template(#{name.inspect}, #{template['html'].inspect}, #{binding_code})\n"
|
|
56
|
+
end
|
|
55
57
|
end
|
|
58
|
+
|
|
59
|
+
return code
|
|
56
60
|
end
|
|
57
61
|
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
def generate_controller_code
|
|
63
|
+
code = ''
|
|
64
|
+
controllers_path = "#{@component_path}/controllers/"
|
|
60
65
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
Dir["#{controllers_path}*_controller.rb"].sort.each do |controller_path|
|
|
67
|
+
code << File.read(controller_path) + "\n\n"
|
|
68
|
+
end
|
|
64
69
|
|
|
65
|
-
|
|
66
|
-
code << File.read(controller_path) + "\n\n"
|
|
70
|
+
return code
|
|
67
71
|
end
|
|
68
72
|
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
def generate_model_code
|
|
74
|
+
code = ''
|
|
75
|
+
models_path = "#{@component_path}/models/"
|
|
71
76
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
models_path = "#{@component_path}/models/"
|
|
77
|
+
Dir["#{models_path}*.rb"].sort.each do |model_path|
|
|
78
|
+
code << File.read(model_path) + "\n\n"
|
|
75
79
|
|
|
76
|
-
|
|
77
|
-
code << File.read(model_path) + "\n\n"
|
|
80
|
+
model_name = model_path.match(/([^\/]+)[.]rb$/)[1]
|
|
78
81
|
|
|
79
|
-
|
|
82
|
+
code << "#{page_reference}.add_model(#{model_name.inspect})\n\n"
|
|
83
|
+
end
|
|
80
84
|
|
|
81
|
-
code
|
|
85
|
+
return code
|
|
82
86
|
end
|
|
83
87
|
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
def generate_routes_code
|
|
89
|
+
code = ''
|
|
90
|
+
routes_path = "#{@component_path}/config/routes.rb"
|
|
86
91
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
if File.exists?(routes_path)
|
|
93
|
+
code << "#{page_reference}.add_routes do\n"
|
|
94
|
+
code << "\n" + File.read(routes_path) + "\n"
|
|
95
|
+
code << "end\n\n"
|
|
96
|
+
end
|
|
90
97
|
|
|
91
|
-
|
|
92
|
-
code << "#{page_reference}.add_routes do\n"
|
|
93
|
-
code << "\n" + File.read(routes_path) + "\n"
|
|
94
|
-
code << "end\n\n"
|
|
98
|
+
return code
|
|
95
99
|
end
|
|
96
100
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
"class #{handler.name} < TaskHandler; end"
|
|
103
|
-
end.join "\n"
|
|
101
|
+
def generate_tasks_code
|
|
102
|
+
return TaskHandler.known_handlers.map do |handler|
|
|
103
|
+
"class #{handler.name} < Volt::TaskHandler; end"
|
|
104
|
+
end.join "\n"
|
|
105
|
+
end
|
|
104
106
|
end
|
|
105
107
|
end
|