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,112 +1,110 @@
1
1
  require 'volt'
2
2
 
3
- # The Routes class takes a set of routes and sets up methods to go from
4
- # a url to params, and params to url.
5
- # routes do
6
- # get "/about", _view: 'about'
7
- # get "/blog/{_id}/edit", _view: 'blog/edit', _action: 'edit'
8
- # get "/blog/{_id}", _view: 'blog/show', _action: 'show'
9
- # get "/blog", _view: 'blog'
10
- # get "/blog/new", _view: 'blog/new', _action: 'new'
11
- # get "/cool/{_name}", _view: 'cool'
12
- # end
13
- #
14
- # Using the routes above, we would generate the following:
15
- #
16
- # @direct_routes = {
17
- # '/about' => {_view: 'about'},
18
- # '/blog' => {_view: 'blog'}
19
- # '/blog/new' => {_view: 'blog/new', _action: 'new'}
20
- # }
21
- #
22
- # -- nil represents a terminal
23
- # -- * represents any match
24
- # -- a number for a parameter means use the value in that number section
25
- #
26
- # @indirect_routes = {
27
- # '*' => {
28
- # 'edit' => {
29
- # nil => {_id: 1, _view: 'blog/edit', _action: 'edit'}
30
- # }
31
- # nil => {_id: 1, _view: 'blog/show', _action: 'show'}
32
- # }
33
- # }
34
- # }
35
- #
36
- # Match for params
37
- # @param_matches = [
38
- # {_id: nil, _view: 'blog/edit', _action: 'edit'} => Proc.new {|params| "/blog/#{params.id}/edit", params.reject {|k,v| k == :id }}
39
- # ]
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
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
- return self
57
- end
53
+ def define(&block)
54
+ instance_eval(&block)
58
55
 
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
56
+ return self
66
57
  end
67
58
 
68
- add_param_matcher(path, params)
69
- end
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
- # 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
68
+ add_param_matcher(path, params)
80
69
  end
81
70
 
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])
85
-
86
- if result
87
- return param_matcher[1].call(new_params)
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
- return nil, nil
92
- end
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
- # 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
86
+ if result
87
+ return param_matcher[1].call(new_params)
88
+ end
89
+ end
100
90
 
101
- # Next, split the url and walk the sections
102
- parts = url_parts(path)
91
+ return nil, nil
92
+ end
103
93
 
104
- result = match_path(parts, parts, @indirect_routes)
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
- return result
107
- end
101
+ # Next, split the url and walk the sections
102
+ parts = url_parts(path)
108
103
 
109
- private
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 = url_parts(path)
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
- # Get the
205
- binding = part[2...-2].strip.to_sym
206
- input_params.delete(binding)
207
- else
208
- part
209
- end
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
- class ComponentHandler
6
- def initialize(component_paths)
7
- @component_paths = component_paths
8
- end
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
- # TODO: Sanatize template path
14
- component_name = req.path.strip.gsub(/^\/components\//, '').gsub(/[.]js$/, '')
11
+ def call(env)
12
+ req = Rack::Request.new(env)
15
13
 
16
- javascript_code = compile_for_component(component_name)
14
+ # TODO: Sanatize template path
15
+ component_name = req.path.strip.gsub(/^\/components\//, '').gsub(/[.]js$/, '')
17
16
 
18
- return [200, {"Content-Type" => "application/javascript; charset=utf-8"}, StringIO.new(javascript_code)]
19
- end
17
+ javascript_code = compile_for_component(component_name)
20
18
 
21
- def compile_for_component(component_name)
22
- code = ComponentCode.new(component_name, @component_paths).code
19
+ return [200, {"Content-Type" => "application/javascript; charset=utf-8"}, StringIO.new(javascript_code)]
20
+ end
23
21
 
24
- # Add the lib directory to the load path
25
- Opal.append_path(Volt.root + '/lib')
22
+ def compile_for_component(component_name)
23
+ code = ComponentCode.new(component_name, @component_paths).code
26
24
 
27
- # Compile the code
28
- javascript_code = Opal.compile(code)
25
+ # Add the lib directory to the load path
26
+ Opal.append_path(Volt.root + '/lib')
29
27
 
30
- return javascript_code
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
- class ComponentTemplates
6
- def initialize(component_path, component_name, client=true)
7
- @component_path = component_path
8
- @component_name = component_name
9
- @client = true
10
- end
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
- return code
20
- end
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
- def page_reference
23
- if @client
24
- '$page'
25
- else
26
- 'page'
20
+ return code
27
21
  end
28
- end
29
22
 
30
- def generate_view_code
31
- code = ''
32
- views_path = "#{@component_path}/views/"
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
- # Load all templates in the folder
35
- Dir["#{views_path}*/*.html"].sort.each do |view_path|
36
- # Get the path for the template, supports templates in folders
37
- template_path = view_path[views_path.size..((-1 * ('.html'.size + 1)))]
38
- template_path = "#{@component_name}/#{template_path}"
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
- all_templates = ViewParser.new(File.read(view_path), template_path)
41
+ all_templates = ViewParser.new(File.read(view_path), template_path)
41
42
 
42
- binding_initializers = []
43
- all_templates.templates.each_pair do |name, template|
44
- binding_code = []
43
+ binding_initializers = []
44
+ all_templates.templates.each_pair do |name, template|
45
+ binding_code = []
45
46
 
46
- if template['bindings']
47
- template['bindings'].each_pair do |key,value|
48
- binding_code << "#{key.inspect} => [#{value.join(', ')}]"
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
- binding_code = "{#{binding_code.join(', ')}}"
53
+ binding_code = "{#{binding_code.join(', ')}}"
53
54
 
54
- code << "#{page_reference}.add_template(#{name.inspect}, #{template['html'].inspect}, #{binding_code})\n"
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
- return code
59
- end
62
+ def generate_controller_code
63
+ code = ''
64
+ controllers_path = "#{@component_path}/controllers/"
60
65
 
61
- def generate_controller_code
62
- code = ''
63
- controllers_path = "#{@component_path}/controllers/"
66
+ Dir["#{controllers_path}*_controller.rb"].sort.each do |controller_path|
67
+ code << File.read(controller_path) + "\n\n"
68
+ end
64
69
 
65
- Dir["#{controllers_path}*_controller.rb"].sort.each do |controller_path|
66
- code << File.read(controller_path) + "\n\n"
70
+ return code
67
71
  end
68
72
 
69
- return code
70
- end
73
+ def generate_model_code
74
+ code = ''
75
+ models_path = "#{@component_path}/models/"
71
76
 
72
- def generate_model_code
73
- code = ''
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
- Dir["#{models_path}*.rb"].sort.each do |model_path|
77
- code << File.read(model_path) + "\n\n"
80
+ model_name = model_path.match(/([^\/]+)[.]rb$/)[1]
78
81
 
79
- model_name = model_path.match(/([^\/]+)[.]rb$/)[1]
82
+ code << "#{page_reference}.add_model(#{model_name.inspect})\n\n"
83
+ end
80
84
 
81
- code << "#{page_reference}.add_model(#{model_name.inspect})\n\n"
85
+ return code
82
86
  end
83
87
 
84
- return code
85
- end
88
+ def generate_routes_code
89
+ code = ''
90
+ routes_path = "#{@component_path}/config/routes.rb"
86
91
 
87
- def generate_routes_code
88
- code = ''
89
- routes_path = "#{@component_path}/config/routes.rb"
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
- if File.exists?(routes_path)
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
- return code
98
- end
99
-
100
- def generate_tasks_code
101
- return TaskHandler.known_handlers.map do |handler|
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