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,98 +1,99 @@
|
|
|
1
1
|
# ComponentPaths gives an array of every folder where you find a component.
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
# Yield for every folder where we might find components
|
|
8
|
-
def app_folders
|
|
9
|
-
# Find all app folders
|
|
10
|
-
@app_folders ||= begin
|
|
11
|
-
volt_app = File.expand_path(File.join(File.dirname(__FILE__), "../../../../app"))
|
|
12
|
-
app_folders = [volt_app, "#{@root}/app", "#{@root}/vendor/app"].map {|f| File.expand_path(f) }
|
|
13
|
-
|
|
14
|
-
# Gem folders with volt in them
|
|
15
|
-
# TODO: we should probably qualify this a bit more
|
|
16
|
-
app_folders += Gem.loaded_specs.values.map { |g| g.full_gem_path }.reject {|g| g !~ /volt/ }.map {|f| f + '/app' }
|
|
17
|
-
|
|
18
|
-
app_folders
|
|
2
|
+
module Volt
|
|
3
|
+
class ComponentPaths
|
|
4
|
+
def initialize(root=nil)
|
|
5
|
+
@root = root || Dir.pwd
|
|
19
6
|
end
|
|
20
7
|
|
|
21
|
-
# Yield
|
|
22
|
-
|
|
8
|
+
# Yield for every folder where we might find components
|
|
9
|
+
def app_folders
|
|
10
|
+
# Find all app folders
|
|
11
|
+
@app_folders ||= begin
|
|
12
|
+
volt_app = File.expand_path(File.join(File.dirname(__FILE__), "../../../../app"))
|
|
13
|
+
app_folders = [volt_app, "#{@root}/app", "#{@root}/vendor/app"].map { |f| File.expand_path(f) }
|
|
23
14
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
return files.flatten
|
|
30
|
-
end
|
|
15
|
+
# Gem folders with volt in them
|
|
16
|
+
# TODO: we should probably qualify this a bit more
|
|
17
|
+
app_folders += Gem.loaded_specs.values.map { |g| g.full_gem_path }.reject { |g| g !~ /volt/ }.map { |f| f + '/app' }
|
|
31
18
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return @components if @components
|
|
19
|
+
app_folders
|
|
20
|
+
end
|
|
35
21
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
Dir["#{app_folder}/*"].sort.each do |folder|
|
|
39
|
-
if File.directory?(folder)
|
|
40
|
-
folder_name = folder[/[^\/]+$/]
|
|
22
|
+
# Yield each app folder and return a flattened array with
|
|
23
|
+
# the results
|
|
41
24
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
25
|
+
files = []
|
|
26
|
+
@app_folders.each do |app_folder|
|
|
27
|
+
files << yield(app_folder)
|
|
45
28
|
end
|
|
29
|
+
|
|
30
|
+
return files.flatten
|
|
46
31
|
end
|
|
47
32
|
|
|
48
|
-
|
|
49
|
-
|
|
33
|
+
# returns an array of every folder that is a component
|
|
34
|
+
def components
|
|
35
|
+
return @components if @components
|
|
50
36
|
|
|
51
|
-
|
|
52
|
-
def require_in_components
|
|
53
|
-
if RUBY_PLATFORM == 'opal'
|
|
54
|
-
else
|
|
37
|
+
@components = {}
|
|
55
38
|
app_folders do |app_folder|
|
|
56
|
-
|
|
39
|
+
Dir["#{app_folder}/*"].sort.each do |folder|
|
|
40
|
+
if File.directory?(folder)
|
|
41
|
+
folder_name = folder[/[^\/]+$/]
|
|
57
42
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
require(path)
|
|
43
|
+
@components[folder_name] ||= []
|
|
44
|
+
@components[folder_name] << folder
|
|
45
|
+
end
|
|
62
46
|
end
|
|
47
|
+
end
|
|
63
48
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
49
|
+
return @components
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Makes each components classes available on the load path, require classes.
|
|
53
|
+
def require_in_components
|
|
54
|
+
if RUBY_PLATFORM == 'opal'
|
|
55
|
+
else
|
|
56
|
+
app_folders do |app_folder|
|
|
57
|
+
$LOAD_PATH.unshift(app_folder)
|
|
58
|
+
|
|
59
|
+
# Sort so we get consistent load order across platforms
|
|
60
|
+
Dir["#{app_folder}/*/{controllers,models,tasks}/*.rb"].each do |ruby_file|
|
|
61
|
+
path = ruby_file.gsub(/^#{app_folder}\//, '')[0..-4]
|
|
62
|
+
require(path)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
if Volt.server?
|
|
66
|
+
# Add models to page
|
|
67
|
+
Dir["#{app_folder}/*/models/*.rb"].each do |ruby_file|
|
|
68
|
+
class_name = File.basename(ruby_file).gsub(/[.]rb$/, '')
|
|
69
|
+
$page.add_model(class_name)
|
|
70
|
+
end
|
|
69
71
|
end
|
|
70
72
|
end
|
|
71
73
|
end
|
|
72
74
|
end
|
|
73
|
-
end
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
# Returns the path for a specific component
|
|
77
|
+
def component_path(name)
|
|
78
|
+
folders = components[name]
|
|
78
79
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
if folders
|
|
81
|
+
return folders.first
|
|
82
|
+
else
|
|
83
|
+
return nil
|
|
84
|
+
end
|
|
83
85
|
end
|
|
84
|
-
end
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
# Return every asset folder we need to serve from
|
|
88
|
+
def asset_folders
|
|
89
|
+
folders = []
|
|
90
|
+
app_folders do |app_folder|
|
|
91
|
+
Dir["#{app_folder}/*/assets"].sort.each do |asset_folder|
|
|
92
|
+
folders << yield(asset_folder)
|
|
93
|
+
end
|
|
92
94
|
end
|
|
93
|
-
end
|
|
94
95
|
|
|
95
|
-
|
|
96
|
+
folders.flatten
|
|
97
|
+
end
|
|
96
98
|
end
|
|
97
|
-
|
|
98
99
|
end
|
|
@@ -2,54 +2,51 @@ require 'volt/server/rack/asset_files'
|
|
|
2
2
|
require 'volt/router/routes'
|
|
3
3
|
|
|
4
4
|
# Serves the main pages
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
module Volt
|
|
6
|
+
class IndexFiles
|
|
7
|
+
def initialize(app, component_paths, opal_files)
|
|
8
|
+
@app = app
|
|
9
|
+
@component_paths = component_paths
|
|
10
|
+
@opal_files = opal_files
|
|
11
|
+
|
|
12
|
+
@@router ||= Routes.new.define do
|
|
13
|
+
# Find the route file
|
|
14
|
+
home_path = component_paths.component_path('main')
|
|
15
|
+
route_file = File.read("#{home_path}/config/routes.rb")
|
|
16
|
+
eval(route_file)
|
|
17
|
+
end
|
|
16
18
|
end
|
|
17
|
-
end
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
def route_match?(path)
|
|
21
|
+
params = @@router.url_to_params(path)
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
return params if params
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
return false
|
|
26
|
+
end
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
def call(env)
|
|
29
|
+
if route_match?(env['PATH_INFO'])
|
|
30
|
+
[200, {'Content-Type' => 'text/html; charset=utf-8'}, [html]]
|
|
31
|
+
else
|
|
32
|
+
@app.call env
|
|
33
|
+
end
|
|
32
34
|
end
|
|
33
|
-
end
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
def html
|
|
37
|
+
index_path = File.expand_path(File.join(Volt.root, "public/index.html"))
|
|
38
|
+
html = File.read(index_path)
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
ERB.new(html).result(binding)
|
|
41
|
+
end
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
def javascript_files
|
|
44
|
+
# TODO: Cache somehow, this is being loaded every time
|
|
45
|
+
AssetFiles.new('main', @component_paths).javascript_files(@opal_files)
|
|
46
|
+
end
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
def css_files
|
|
49
|
+
AssetFiles.new('main', @component_paths).css_files
|
|
50
|
+
end
|
|
49
51
|
end
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
52
|
end
|
|
54
|
-
|
|
55
|
-
|
|
@@ -5,64 +5,66 @@ if Volt.env.production?
|
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
# Sets up the maps for the opal assets, and source maps if enabled.
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
module Volt
|
|
9
|
+
class OpalFiles
|
|
10
|
+
attr_reader :environment
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
def initialize(builder, app_path, component_paths)
|
|
13
|
+
Opal::Processor.source_map_enabled = Volt.source_maps?
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
# Don't run arity checks in production
|
|
16
|
+
# Opal::Processor.arity_check_enabled = !Volt.env.production?
|
|
17
|
+
# Opal::Processor.dynamic_require_severity = :raise
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
@component_paths = component_paths
|
|
20
|
+
@environment = Opal::Environment.new
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
# Since the scope changes in builder blocks, we need to capture
|
|
23
|
+
# environment in closure
|
|
24
|
+
environment = @environment
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
environment.cache = Sprockets::Cache::FileStore.new("./tmp")
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
if Volt.env.production?
|
|
29
|
+
# Compress in production
|
|
30
|
+
environment.js_compressor = Sprockets::UglifierCompressor
|
|
31
|
+
environment.css_compressor = Sprockets::YUICompressor
|
|
32
|
+
end
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
environment.append_path(app_path)
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
volt_gem_lib_path = File.expand_path(File.join(File.dirname(__FILE__), "../../.."))
|
|
37
|
+
environment.append_path(volt_gem_lib_path)
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
add_asset_folders(environment)
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
# Add the opal load paths
|
|
42
|
+
Opal.paths.each do |path|
|
|
43
|
+
environment.append_path(path)
|
|
44
|
+
end
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
# opal-jquery gem
|
|
47
|
+
spec = Gem::Specification.find_by_name("opal-jquery")
|
|
48
|
+
environment.append_path(spec.gem_dir + "/opal")
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
builder.map '/assets' do
|
|
51
|
+
run environment
|
|
52
|
+
end
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
if Volt.source_maps?
|
|
55
|
+
source_maps = SourceMapServer.new(environment)
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
builder.map(source_maps.prefix) do
|
|
58
|
+
run source_maps
|
|
59
|
+
end
|
|
58
60
|
end
|
|
59
61
|
end
|
|
60
|
-
end
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
def add_asset_folders(environment)
|
|
64
|
+
@component_paths.asset_folders do |asset_folder|
|
|
65
|
+
environment.append_path(asset_folder)
|
|
66
|
+
end
|
|
65
67
|
end
|
|
66
|
-
end
|
|
67
68
|
|
|
69
|
+
end
|
|
68
70
|
end
|
|
@@ -1,31 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
module Volt
|
|
2
|
+
class SourceMapServer
|
|
3
|
+
def initialize sprockets
|
|
4
|
+
@sprockets = sprockets
|
|
5
|
+
end
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
attr_reader :sprockets
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
attr_writer :prefix
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
def prefix
|
|
12
|
+
@prefix ||= '/__opal_source_maps__'
|
|
13
|
+
end
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
def inspect
|
|
16
|
+
"#<#{self.class}:#{object_id}>"
|
|
17
|
+
end
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
def call(env)
|
|
20
|
+
path_info = env['PATH_INFO']
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
if path_info =~ /\.js\.map$/
|
|
23
|
+
path = env['PATH_INFO'].gsub(/^\/|\.js\.map$/, '')
|
|
24
|
+
asset = sprockets[path]
|
|
25
|
+
return [404, {}, []] if asset.nil?
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
return [200, {"Content-Type" => "text/json"}, [$OPAL_SOURCE_MAPS[asset.pathname].to_s]]
|
|
28
|
+
else
|
|
29
|
+
return [200, {"Content-Type" => "text/text"}, [File.read(sprockets.resolve(path_info))]]
|
|
30
|
+
end
|
|
29
31
|
end
|
|
30
32
|
end
|
|
31
33
|
end
|
|
@@ -2,67 +2,68 @@ require 'json'
|
|
|
2
2
|
require 'sockjs/session'
|
|
3
3
|
require File.join(File.dirname(__FILE__), "../../../app/volt/tasks/query_tasks")
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
module Volt
|
|
6
|
+
class SocketConnectionHandler < SockJS::Session
|
|
7
|
+
# Create one instance of the dispatcher
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
def self.dispatcher=(val)
|
|
10
|
+
@@dispatcher = val
|
|
11
|
+
end
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
def self.dispatcher
|
|
14
|
+
@@dispatcher
|
|
15
|
+
end
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
# Sends a message to all, optionally skipping a users channel
|
|
18
|
+
def self.send_message_all(skip_channel=nil, *args)
|
|
19
|
+
@@channels.each do |channel|
|
|
20
|
+
if skip_channel && channel == skip_channel
|
|
21
|
+
next
|
|
22
|
+
end
|
|
23
|
+
channel.send_message(*args)
|
|
21
24
|
end
|
|
22
|
-
channel.send_message(*args)
|
|
23
|
-
end
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
end
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
def initialize(session, *args)
|
|
29
|
+
@session = session
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
@@channels ||= []
|
|
32
|
+
@@channels << self
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
super
|
|
35
|
+
end
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
def process_message(message)
|
|
38
|
+
# self.class.message_all(message)
|
|
39
|
+
# Messages are json and wrapped in an array
|
|
40
|
+
message = JSON.parse(message).first
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
@@dispatcher.dispatch(self, message)
|
|
43
|
+
end
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
def send_message(*args)
|
|
46
|
+
str = JSON.dump([*args])
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
begin
|
|
49
|
+
send(str)
|
|
50
|
+
rescue MetaState::WrongStateError => e
|
|
51
|
+
puts "Tried to send to closed connection: #{e.inspect}"
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
# Mark this channel as closed
|
|
54
|
+
closed
|
|
55
|
+
end
|
|
54
56
|
end
|
|
55
|
-
end
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
def closed
|
|
59
|
+
# Remove ourself from the available channels
|
|
60
|
+
@@channels.delete(self)
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
QueryTasks.new(self).close!
|
|
63
|
+
end
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
def inspect
|
|
66
|
+
"<#{self.class.to_s}:#{object_id}>"
|
|
67
|
+
end
|
|
66
68
|
end
|
|
67
|
-
|
|
68
69
|
end
|
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
module Volt
|
|
2
|
+
class SocketConnectionHandlerStub
|
|
3
|
+
def self.dispatcher=(val)
|
|
4
|
+
@@dispatcher = val
|
|
5
|
+
end
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
def self.dispatcher
|
|
8
|
+
@@dispatcher
|
|
9
|
+
end
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
def initialize(channel_stub)
|
|
12
|
+
@channel_stub = channel_stub
|
|
13
|
+
end
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
# Sends a message to all, optionally skipping a users channel
|
|
16
|
+
def self.send_message_all(skip_channel=nil, *args)
|
|
17
|
+
# Stub
|
|
18
|
+
end
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
def process_message(message)
|
|
21
|
+
@@dispatcher.dispatch(self, message)
|
|
22
|
+
end
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
def send_message(*args)
|
|
25
|
+
@channel_stub.message_received(*args)
|
|
26
|
+
end
|
|
25
27
|
end
|
|
26
28
|
end
|