volt 0.8.15 → 0.8.16
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/.rubocop.yml +11 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +1 -1
- data/Guardfile +2 -3
- data/Rakefile +1 -4
- data/VERSION +1 -1
- data/app/volt/controllers/notices_controller.rb +1 -1
- data/app/volt/tasks/live_query/data_store.rb +7 -7
- data/app/volt/tasks/live_query/live_query.rb +7 -9
- data/app/volt/tasks/live_query/live_query_pool.rb +13 -12
- data/app/volt/tasks/live_query/query_tracker.rb +4 -5
- data/app/volt/tasks/query_tasks.rb +9 -11
- data/app/volt/tasks/store_tasks.rb +4 -4
- data/app/volt/tasks/user_tasks.rb +1 -1
- data/bin/volt +2 -2
- data/lib/volt.rb +3 -7
- data/lib/volt/assets/test.rb +1 -2
- data/lib/volt/benchmark/benchmark.rb +3 -3
- data/lib/volt/boot.rb +1 -1
- data/lib/volt/cli.rb +18 -18
- data/lib/volt/cli/asset_compile.rb +8 -10
- data/lib/volt/cli/generate.rb +9 -11
- data/lib/volt/cli/new_gem.rb +51 -51
- data/lib/volt/config.rb +2 -3
- data/lib/volt/console.rb +1 -1
- data/lib/volt/controllers/model_controller.rb +6 -6
- data/lib/volt/data_stores/data_store.rb +1 -1
- data/lib/volt/data_stores/mongo_driver.rb +1 -1
- data/lib/volt/extra_core/array.rb +2 -2
- data/lib/volt/extra_core/blank.rb +1 -2
- data/lib/volt/extra_core/extra_core.rb +1 -1
- data/lib/volt/extra_core/inflector/methods.rb +0 -1
- data/lib/volt/extra_core/logger.rb +13 -7
- data/lib/volt/extra_core/numeric.rb +1 -1
- data/lib/volt/extra_core/string.rb +7 -7
- data/lib/volt/extra_core/stringify_keys.rb +5 -5
- data/lib/volt/models.rb +2 -2
- data/lib/volt/models/array_model.rb +18 -19
- data/lib/volt/models/cursor.rb +0 -1
- data/lib/volt/models/model.rb +17 -35
- data/lib/volt/models/model_hash_behaviour.rb +0 -2
- data/lib/volt/models/model_state.rb +1 -1
- data/lib/volt/models/model_wrapper.rb +1 -1
- data/lib/volt/models/persistors/array_store.rb +26 -13
- data/lib/volt/models/persistors/base.rb +1 -1
- data/lib/volt/models/persistors/flash.rb +2 -2
- data/lib/volt/models/persistors/local_store.rb +2 -3
- data/lib/volt/models/persistors/model_store.rb +7 -6
- data/lib/volt/models/persistors/params.rb +2 -2
- data/lib/volt/models/persistors/query/query_listener.rb +2 -0
- data/lib/volt/models/persistors/query/query_listener_pool.rb +1 -1
- data/lib/volt/models/persistors/store.rb +1 -2
- data/lib/volt/models/persistors/store_state.rb +2 -3
- data/lib/volt/models/url.rb +17 -16
- data/lib/volt/models/validations.rb +11 -14
- data/lib/volt/models/validators/length_validator.rb +3 -3
- data/lib/volt/models/validators/presence_validator.rb +2 -2
- data/lib/volt/page/bindings/attribute_binding.rb +2 -3
- data/lib/volt/page/bindings/base_binding.rb +1 -1
- data/lib/volt/page/bindings/each_binding.rb +8 -9
- data/lib/volt/page/bindings/event_binding.rb +2 -3
- data/lib/volt/page/bindings/template_binding.rb +8 -7
- data/lib/volt/page/bindings/template_binding/grouped_controllers.rb +2 -1
- data/lib/volt/page/channel.rb +10 -10
- data/lib/volt/page/channel_stub.rb +1 -1
- data/lib/volt/page/document.rb +0 -1
- data/lib/volt/page/document_events.rb +4 -4
- data/lib/volt/page/page.rb +26 -19
- data/lib/volt/page/string_template_renderer.rb +2 -2
- data/lib/volt/page/sub_context.rb +10 -4
- data/lib/volt/page/targets/attribute_section.rb +1 -1
- data/lib/volt/page/targets/attribute_target.rb +1 -2
- data/lib/volt/page/targets/base_section.rb +4 -4
- data/lib/volt/page/targets/binding_document/base_node.rb +0 -1
- data/lib/volt/page/targets/binding_document/component_node.rb +4 -5
- data/lib/volt/page/targets/dom_section.rb +21 -22
- data/lib/volt/page/targets/dom_target.rb +1 -1
- data/lib/volt/page/targets/dom_template.rb +11 -12
- data/lib/volt/page/targets/helpers/comment_searchers.rb +7 -8
- data/lib/volt/page/tasks.rb +0 -1
- data/lib/volt/page/template_renderer.rb +1 -1
- data/lib/volt/page/url_tracker.rb +3 -3
- data/lib/volt/reactive/computation.rb +5 -11
- data/lib/volt/reactive/dependency.rb +1 -3
- data/lib/volt/reactive/eventable.rb +17 -4
- data/lib/volt/reactive/hash_dependency.rb +1 -0
- data/lib/volt/reactive/reactive_accessors.rb +0 -1
- data/lib/volt/reactive/reactive_array.rb +20 -25
- data/lib/volt/reactive/reactive_hash.rb +3 -3
- data/lib/volt/router/routes.rb +11 -13
- data/lib/volt/server.rb +17 -17
- data/lib/volt/server/component_handler.rb +2 -2
- data/lib/volt/server/component_templates.rb +8 -8
- data/lib/volt/server/html_parser/attribute_scope.rb +9 -10
- data/lib/volt/server/html_parser/if_view_scope.rb +2 -2
- data/lib/volt/server/html_parser/sandlebars_parser.rb +14 -14
- data/lib/volt/server/html_parser/textarea_scope.rb +1 -2
- data/lib/volt/server/html_parser/view_handler.rb +1 -1
- data/lib/volt/server/html_parser/view_parser.rb +1 -1
- data/lib/volt/server/html_parser/view_scope.rb +10 -10
- data/lib/volt/server/rack/asset_files.rb +15 -16
- data/lib/volt/server/rack/component_code.rb +2 -2
- data/lib/volt/server/rack/component_html_renderer.rb +0 -1
- data/lib/volt/server/rack/component_paths.rb +13 -10
- data/lib/volt/server/rack/index_files.rb +4 -4
- data/lib/volt/server/rack/opal_files.rb +4 -5
- data/lib/volt/server/rack/source_map_server.rb +3 -3
- data/lib/volt/server/socket_connection_handler.rb +3 -4
- data/lib/volt/server/socket_connection_handler_stub.rb +1 -1
- data/lib/volt/spec/setup.rb +3 -3
- data/lib/volt/store/mongo.rb +2 -2
- data/lib/volt/tasks/task_handler.rb +3 -3
- data/lib/volt/utils/generic_counting_pool.rb +2 -2
- data/lib/volt/utils/generic_pool.rb +7 -8
- data/lib/volt/utils/local_storage.rb +4 -4
- data/lib/volt/volt/environment.rb +1 -1
- data/spec/apps/file_loading/app/shared/config/dependencies.rb +1 -1
- data/spec/apps/kitchen_sink/Gemfile +0 -2
- data/spec/apps/kitchen_sink/app/main/config/routes.rb +5 -5
- data/spec/apps/kitchen_sink/app/main/controllers/main_controller.rb +7 -6
- data/spec/apps/kitchen_sink/app/main/controllers/todos_controller.rb +3 -4
- data/spec/controllers/reactive_accessors_spec.rb +4 -4
- data/spec/extra_core/inflector_spec.rb +1 -1
- data/spec/extra_core/string_transformation_test_cases.rb +23 -24
- data/spec/extra_core/string_transformations_spec.rb +11 -12
- data/spec/integration/bindings_spec.rb +15 -15
- data/spec/integration/list_spec.rb +12 -13
- data/spec/integration/templates_spec.rb +3 -3
- data/spec/models/model_spec.rb +74 -80
- data/spec/models/persistors/params_spec.rb +2 -2
- data/spec/models/persistors/store_spec.rb +4 -4
- data/spec/models/validations_spec.rb +14 -23
- data/spec/page/bindings/content_binding_spec.rb +7 -8
- data/spec/page/bindings/template_binding_spec.rb +22 -24
- data/spec/page/sub_context_spec.rb +2 -2
- data/spec/reactive/computation_spec.rb +3 -3
- data/spec/reactive/reactive_array_spec.rb +12 -12
- data/spec/router/routes_spec.rb +45 -48
- data/spec/server/html_parser/sandlebars_parser_spec.rb +42 -42
- data/spec/server/html_parser/view_parser_spec.rb +132 -153
- data/spec/server/rack/asset_files_spec.rb +9 -8
- data/spec/server/rack/component_paths_spec.rb +5 -5
- data/spec/server/rack/rack_requests_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -1
- data/spec/tasks/live_query_spec.rb +4 -5
- data/spec/tasks/query_tasks.rb +2 -4
- data/spec/tasks/query_tracker_spec.rb +29 -29
- data/spec/templates/targets/binding_document/component_node_spec.rb +1 -1
- data/spec/utils/generic_counting_pool_spec.rb +4 -4
- data/spec/utils/generic_pool_spec.rb +12 -12
- data/templates/component/config/routes.rb +2 -2
- data/templates/component/controllers/main_controller.rb +7 -6
- data/templates/newgem/app/newgem/config/dependencies.rb +1 -1
- data/templates/newgem/app/newgem/config/routes.rb +1 -1
- data/templates/project/app/main/config/routes.rb +2 -2
- data/templates/project/app/main/controllers/main_controller.rb +7 -6
- data/templates/project/spec/sample_spec.rb +2 -2
- data/volt.gemspec +32 -33
- metadata +3 -4
- data/lib/volt/extra_core/log.rb +0 -56
- data/lib/volt/extra_core/try.rb +0 -31
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
module Volt
|
|
2
2
|
class CLI
|
|
3
|
-
|
|
4
|
-
desc "precompile", "precompile all application assets"
|
|
3
|
+
desc 'precompile', 'precompile all application assets'
|
|
5
4
|
|
|
6
5
|
def precompile
|
|
7
6
|
compile
|
|
8
7
|
end
|
|
9
8
|
|
|
10
|
-
desc
|
|
9
|
+
desc 'watch', 'compiles the project to /compiled when a file changes'
|
|
11
10
|
|
|
12
11
|
def watch
|
|
13
12
|
require 'listen'
|
|
@@ -18,7 +17,7 @@ module Volt
|
|
|
18
17
|
|
|
19
18
|
listener.start # non-blocking
|
|
20
19
|
|
|
21
|
-
Signal.trap(
|
|
20
|
+
Signal.trap('SIGINT') do
|
|
22
21
|
listener.stop
|
|
23
22
|
end
|
|
24
23
|
|
|
@@ -32,8 +31,9 @@ module Volt
|
|
|
32
31
|
end
|
|
33
32
|
|
|
34
33
|
private
|
|
34
|
+
|
|
35
35
|
def compile
|
|
36
|
-
print
|
|
36
|
+
print 'compiling project...'
|
|
37
37
|
require 'fileutils'
|
|
38
38
|
require 'opal'
|
|
39
39
|
require 'volt'
|
|
@@ -46,7 +46,7 @@ module Volt
|
|
|
46
46
|
@root_path ||= Dir.pwd
|
|
47
47
|
Volt.root = @root_path
|
|
48
48
|
|
|
49
|
-
@app_path = File.expand_path(File.join(@root_path,
|
|
49
|
+
@app_path = File.expand_path(File.join(@root_path, 'app'))
|
|
50
50
|
|
|
51
51
|
@component_paths = ComponentPaths.new(@root_path)
|
|
52
52
|
@app = Rack::Builder.new
|
|
@@ -67,7 +67,7 @@ module Volt
|
|
|
67
67
|
@opal_files.environment.each_logical_path do |logical_path|
|
|
68
68
|
logical_path = logical_path.to_s
|
|
69
69
|
# Only include files that aren't compiled elsewhere, like fonts
|
|
70
|
-
|
|
70
|
+
unless logical_path[/[.](y|css|js|html|erb)$/]
|
|
71
71
|
write_file(logical_path)
|
|
72
72
|
end
|
|
73
73
|
end
|
|
@@ -78,7 +78,6 @@ module Volt
|
|
|
78
78
|
logical_path = logical_path.gsub(/^\/assets\//, '')
|
|
79
79
|
write_file(logical_path)
|
|
80
80
|
end
|
|
81
|
-
|
|
82
81
|
end
|
|
83
82
|
|
|
84
83
|
def write_file(logical_path)
|
|
@@ -88,7 +87,7 @@ module Volt
|
|
|
88
87
|
|
|
89
88
|
begin
|
|
90
89
|
content = @opal_files.environment[logical_path].to_s
|
|
91
|
-
File.open(path,
|
|
90
|
+
File.open(path, 'wb') do |file|
|
|
92
91
|
file.write(content)
|
|
93
92
|
end
|
|
94
93
|
rescue Sprockets::FileNotFound, SyntaxError => e
|
|
@@ -106,7 +105,6 @@ module Volt
|
|
|
106
105
|
end
|
|
107
106
|
end
|
|
108
107
|
|
|
109
|
-
|
|
110
108
|
def write_index
|
|
111
109
|
path = "#{@root_path}/compiled/index.html"
|
|
112
110
|
FileUtils.mkdir_p(File.dirname(path))
|
data/lib/volt/cli/generate.rb
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
class Generate < Thor
|
|
2
2
|
include Thor::Actions
|
|
3
3
|
|
|
4
|
-
desc
|
|
5
|
-
method_option :name, :
|
|
6
|
-
method_option :component, :
|
|
7
|
-
def model(name, component='main')
|
|
4
|
+
desc 'model NAME COMPONENT', 'Creates a model named NAME in the component named COMPONENT'
|
|
5
|
+
method_option :name, type: :string, banner: 'The name of the model.'
|
|
6
|
+
method_option :component, type: :string, default: 'main', banner: 'The component the model should be created in.', required: false
|
|
7
|
+
def model(name, component = 'main')
|
|
8
8
|
output_file = Dir.pwd + "/app/#{component.underscore}/models/#{name.underscore.singularize}.rb"
|
|
9
|
-
template(
|
|
9
|
+
template('model/model.rb.tt', output_file, model_name: name.camelize.singularize)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
desc
|
|
13
|
-
method_option :name, :
|
|
12
|
+
desc 'component NAME', 'Creates a component named NAME in the app folder.'
|
|
13
|
+
method_option :name, type: :string, banner: 'The name of the component.'
|
|
14
14
|
def component(name)
|
|
15
15
|
name = name.underscore
|
|
16
16
|
component_folder = Dir.pwd + "/app/#{name}"
|
|
17
17
|
@component_name = name
|
|
18
|
-
directory(
|
|
18
|
+
directory('component', component_folder, component_name: name)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
|
|
22
21
|
def self.source_root
|
|
23
22
|
File.expand_path(File.join(File.dirname(__FILE__), '../../../templates'))
|
|
24
23
|
end
|
|
25
|
-
|
|
26
|
-
end
|
|
24
|
+
end
|
data/lib/volt/cli/new_gem.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'uri'
|
|
3
3
|
require 'fileutils'
|
|
4
4
|
|
|
5
5
|
# Creates a new "volt" gem, which can be used to easily repackage
|
|
@@ -7,8 +7,8 @@ require 'fileutils'
|
|
|
7
7
|
class NewGem
|
|
8
8
|
def initialize(thor, name, options)
|
|
9
9
|
@thor = thor
|
|
10
|
-
@component_name = name.chomp(
|
|
11
|
-
@name =
|
|
10
|
+
@component_name = name.chomp('/')
|
|
11
|
+
@name = 'volt-' + @component_name # remove trailing slash if present
|
|
12
12
|
|
|
13
13
|
if gem_is_available?
|
|
14
14
|
@thor.say("#{@name} is available! Making gem files.", :green)
|
|
@@ -37,80 +37,80 @@ class NewGem
|
|
|
37
37
|
request = Net::HTTP::Get.new(uri.request_uri)
|
|
38
38
|
response = http.request(request)
|
|
39
39
|
|
|
40
|
-
return response.code ==
|
|
40
|
+
return response.code == '404'
|
|
41
41
|
rescue SocketError => e
|
|
42
42
|
# rubygems is down, skip check
|
|
43
43
|
return true
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def copy_files
|
|
47
|
-
@thor.directory(
|
|
48
|
-
copy(
|
|
49
|
-
copy(
|
|
50
|
-
copy(
|
|
51
|
-
copy(
|
|
52
|
-
copy(
|
|
53
|
-
copy(
|
|
54
|
-
copy(
|
|
47
|
+
@thor.directory('newgem/app/newgem', File.join("#{@target}", "app/#{@component_name}"), @opts)
|
|
48
|
+
copy('newgem/Gemfile.tt', 'Gemfile')
|
|
49
|
+
copy('newgem/Rakefile.tt', 'Rakefile')
|
|
50
|
+
copy('newgem/README.md.tt', 'README.md')
|
|
51
|
+
copy('newgem/gitignore.tt', '.gitignore')
|
|
52
|
+
copy('newgem/newgem.gemspec.tt', "#{@name}.gemspec")
|
|
53
|
+
copy('newgem/lib/newgem.rb.tt', "lib/#{@namespaced_path}.rb")
|
|
54
|
+
copy('newgem/VERSION', 'VERSION')
|
|
55
55
|
FileUtils.mkdir_p(File.join(@target, "lib/#{@namespaced_path}"))
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
def copy_options
|
|
59
59
|
if @options[:bin]
|
|
60
|
-
copy(
|
|
60
|
+
copy('newgem/bin/newgem.tt', "bin/#{@name}")
|
|
61
61
|
end
|
|
62
62
|
case @options[:test]
|
|
63
63
|
when 'rspec'
|
|
64
|
-
copy(
|
|
65
|
-
copy(
|
|
66
|
-
copy(
|
|
64
|
+
copy('newgem/rspec.tt', '.rspec')
|
|
65
|
+
copy('newgem/spec/spec_helper.rb.tt', 'spec/spec_helper.rb')
|
|
66
|
+
copy('newgem/spec/newgem_spec.rb.tt', "spec/#{@namespaced_path}_spec.rb")
|
|
67
67
|
when 'minitest'
|
|
68
|
-
copy(
|
|
69
|
-
copy(
|
|
68
|
+
copy('newgem/test/minitest_helper.rb.tt', 'test/minitest_helper.rb')
|
|
69
|
+
copy('newgem/test/test_newgem.rb.tt', "test/test_#{@namespaced_path}.rb")
|
|
70
70
|
end
|
|
71
71
|
puts "Initializing git repo in #{@target}"
|
|
72
72
|
Dir.chdir(@target) { `git init`; `git add .` }
|
|
73
73
|
|
|
74
74
|
if @options[:edit]
|
|
75
|
-
run("#{@options[
|
|
75
|
+
run("#{@options['edit']} \"#{gemspec_dest}\"") # Open gemspec in editor
|
|
76
76
|
end
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
private
|
|
80
|
-
def copy(from, to)
|
|
81
|
-
@thor.template(File.join(from), File.join(@target, to), @opts)
|
|
82
|
-
end
|
|
83
80
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
git_user_name = `git config user.name`.chomp
|
|
88
|
-
git_user_email = `git config user.email`.chomp
|
|
89
|
-
|
|
90
|
-
opts = {
|
|
91
|
-
:name => @name,
|
|
92
|
-
:namespaced_path => @namespaced_path,
|
|
93
|
-
:constant_name => constant_name,
|
|
94
|
-
:constant_array => constant_array,
|
|
95
|
-
:author => git_user_name.empty? ? "TODO: Write your name" : git_user_name,
|
|
96
|
-
:email => git_user_email.empty? ? "TODO: Write your email address" : git_user_email,
|
|
97
|
-
:test => @options[:test],
|
|
98
|
-
:volt_version_base => volt_version_base
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return opts
|
|
102
|
-
end
|
|
81
|
+
def copy(from, to)
|
|
82
|
+
@thor.template(File.join(from), File.join(@target, to), @opts)
|
|
83
|
+
end
|
|
103
84
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
85
|
+
def gem_options
|
|
86
|
+
constant_name = get_constant_name
|
|
87
|
+
constant_array = constant_name.split('::')
|
|
88
|
+
git_user_name = `git config user.name`.chomp
|
|
89
|
+
git_user_email = `git config user.email`.chomp
|
|
90
|
+
|
|
91
|
+
opts = {
|
|
92
|
+
name: @name,
|
|
93
|
+
namespaced_path: @namespaced_path,
|
|
94
|
+
constant_name: constant_name,
|
|
95
|
+
constant_array: constant_array,
|
|
96
|
+
author: git_user_name.empty? ? 'TODO: Write your name' : git_user_name,
|
|
97
|
+
email: git_user_email.empty? ? 'TODO: Write your email address' : git_user_email,
|
|
98
|
+
test: @options[:test],
|
|
99
|
+
volt_version_base: volt_version_base
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
opts
|
|
103
|
+
end
|
|
108
104
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
105
|
+
def volt_version_base
|
|
106
|
+
version_path = File.join(File.dirname(__FILE__), '../../../VERSION')
|
|
107
|
+
File.read(version_path).split('.').tap { |v| v[v.size - 1] = 0 }.join('.')
|
|
108
|
+
end
|
|
112
109
|
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
def get_constant_name
|
|
111
|
+
constant_name = @name.split('_').map { |p| p[0..0].upcase + p[1..-1] }.join
|
|
112
|
+
constant_name = constant_name.split('-').map { |q| q[0..0].upcase + q[1..-1] }.join('::') if constant_name =~ /-/
|
|
115
113
|
|
|
114
|
+
constant_name
|
|
115
|
+
end
|
|
116
116
|
end
|
data/lib/volt/config.rb
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
# Config lets a user set global config options for Volt.
|
|
2
2
|
module Volt
|
|
3
3
|
module Config
|
|
4
|
-
|
|
5
4
|
def setup
|
|
6
|
-
yield
|
|
5
|
+
yield config
|
|
7
6
|
end
|
|
8
7
|
|
|
9
8
|
def config
|
|
@@ -18,7 +17,7 @@ module Volt
|
|
|
18
17
|
app_name: app_name,
|
|
19
18
|
db_name: ENV['DB_NAME'] || (app_name + '_' + Volt.env.to_s),
|
|
20
19
|
db_host: ENV['DB_HOST'] || 'localhost',
|
|
21
|
-
db_port: (ENV['DB_PORT'] ||
|
|
20
|
+
db_port: (ENV['DB_PORT'] || 27_017).to_i,
|
|
22
21
|
db_driver: ENV['DB_DRIVER'] || 'mongo'
|
|
23
22
|
)
|
|
24
23
|
end
|
data/lib/volt/console.rb
CHANGED
|
@@ -4,7 +4,7 @@ class Pry
|
|
|
4
4
|
# To make the console more useful, we make it so we flush the event registry
|
|
5
5
|
# after each line. This makes it so events are triggered after each line.
|
|
6
6
|
# To accomplish this we monkey-patch pry.
|
|
7
|
-
def rep(target=TOPLEVEL_BINDING)
|
|
7
|
+
def rep(target = TOPLEVEL_BINDING)
|
|
8
8
|
target = Pry.binding_for(target)
|
|
9
9
|
result = re(target)
|
|
10
10
|
|
|
@@ -18,14 +18,14 @@ module Volt
|
|
|
18
18
|
if Symbol === val || String === val
|
|
19
19
|
collections = [:page, :store, :params, :controller]
|
|
20
20
|
if collections.include?(val.to_sym)
|
|
21
|
-
self.current_model =
|
|
21
|
+
self.current_model = send(val)
|
|
22
22
|
else
|
|
23
|
-
|
|
23
|
+
fail "#{val} is not the name of a valid model, choose from: #{collections.join(', ')}"
|
|
24
24
|
end
|
|
25
25
|
elsif val
|
|
26
26
|
self.current_model = val
|
|
27
27
|
else
|
|
28
|
-
|
|
28
|
+
fail "model can not be #{val.inspect}"
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
@@ -37,17 +37,17 @@ module Volt
|
|
|
37
37
|
model = model.call
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
model
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def self.new(*args, &block)
|
|
44
|
-
inst =
|
|
44
|
+
inst = allocate
|
|
45
45
|
|
|
46
46
|
inst.model = (@default_model || :controller)
|
|
47
47
|
|
|
48
48
|
inst.initialize(*args, &block)
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
inst
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
attr_accessor :attrs
|
|
@@ -17,7 +17,6 @@ class Object
|
|
|
17
17
|
def present?
|
|
18
18
|
!blank?
|
|
19
19
|
end
|
|
20
|
-
|
|
21
20
|
end
|
|
22
21
|
|
|
23
22
|
class NilClass
|
|
@@ -73,7 +72,7 @@ class String
|
|
|
73
72
|
def blank?
|
|
74
73
|
# self !~ /[^[:space:]]/
|
|
75
74
|
# TODO: Opal fails with the previous regex
|
|
76
|
-
|
|
75
|
+
strip == ''
|
|
77
76
|
end
|
|
78
77
|
end
|
|
79
78
|
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
if RUBY_PLATFORM == 'opal'
|
|
2
|
+
# The basic front-end logger, log to console
|
|
3
|
+
class Logger
|
|
4
|
+
def initialize(*args)
|
|
5
|
+
# TODO: handle options
|
|
6
|
+
end
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
[:fatal, :info, :warn, :debug, :error].each do |method_name|
|
|
9
|
+
define_method(method_name) do |text, &block|
|
|
10
|
+
text = block.call if block
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
`console[method_name](text);`
|
|
13
|
+
end
|
|
10
14
|
end
|
|
11
15
|
end
|
|
16
|
+
else
|
|
17
|
+
require 'logger'
|
|
12
18
|
end
|
|
@@ -7,20 +7,20 @@ class String
|
|
|
7
7
|
# Turns a string into the camel case version. If it is already camel case, it should
|
|
8
8
|
# return the same string.
|
|
9
9
|
def camelize(first_letter = :upper)
|
|
10
|
-
new_str =
|
|
10
|
+
new_str = gsub(/_[a-z]/) { |a| a[1].upcase }
|
|
11
11
|
new_str = new_str[0].capitalize + new_str[1..-1] if first_letter == :upper
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
new_str
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
# Returns the underscore version of a string. If it is already underscore, it should
|
|
17
17
|
# return the same string.
|
|
18
18
|
def underscore
|
|
19
|
-
|
|
19
|
+
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def dasherize
|
|
23
|
-
|
|
23
|
+
gsub('_', '-')
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def pluralize
|
|
@@ -32,16 +32,16 @@ class String
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def titleize
|
|
35
|
-
|
|
35
|
+
gsub('_', ' ').split(' ').map(&:capitalize).join(' ')
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
def plural?
|
|
39
39
|
# TODO: Temp implementation
|
|
40
|
-
|
|
40
|
+
pluralize == self
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def singular?
|
|
44
44
|
# TODO: Temp implementation
|
|
45
|
-
|
|
45
|
+
singularize == self
|
|
46
46
|
end
|
|
47
47
|
end
|