volt 0.8.27.beta2 → 0.8.27.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +3 -0
  4. data/CHANGELOG.md +7 -2
  5. data/CONTRIBUTING.md +133 -0
  6. data/Gemfile +0 -1
  7. data/Rakefile +11 -3
  8. data/Readme.md +4 -4
  9. data/VERSION +1 -1
  10. data/app/volt/models/user.rb +6 -3
  11. data/lib/volt/cli/console.rb +21 -12
  12. data/lib/volt/cli/runner.rb +1 -1
  13. data/lib/volt/cli.rb +5 -4
  14. data/lib/volt/config.rb +9 -11
  15. data/lib/volt/controllers/model_controller.rb +16 -0
  16. data/lib/volt/data_stores/data_store.rb +1 -1
  17. data/lib/volt/extra_core/array.rb +1 -6
  18. data/lib/volt/extra_core/blank.rb +1 -3
  19. data/lib/volt/extra_core/class.rb +1 -1
  20. data/lib/volt/extra_core/extra_core.rb +0 -1
  21. data/lib/volt/extra_core/logger.rb +78 -1
  22. data/lib/volt/extra_core/object.rb +4 -4
  23. data/lib/volt/models/array_model.rb +2 -3
  24. data/lib/volt/models/buffer.rb +1 -2
  25. data/lib/volt/models/field_helpers.rb +4 -5
  26. data/lib/volt/models/model.rb +27 -1
  27. data/lib/volt/models/model_hash_behaviour.rb +3 -4
  28. data/lib/volt/models/persistors/array_store.rb +6 -7
  29. data/lib/volt/models/persistors/cookies.rb +2 -2
  30. data/lib/volt/models/persistors/model_store.rb +5 -6
  31. data/lib/volt/models/validations.rb +5 -7
  32. data/lib/volt/models/validators/email_validator.rb +8 -29
  33. data/lib/volt/models/validators/format_validator.rb +116 -0
  34. data/lib/volt/models/validators/numericality_validator.rb +2 -2
  35. data/lib/volt/models/validators/phone_number_validator.rb +8 -29
  36. data/lib/volt/models/validators/unique_validator.rb +2 -2
  37. data/lib/volt/page/bindings/content_binding.rb +1 -1
  38. data/lib/volt/page/bindings/each_binding.rb +1 -1
  39. data/lib/volt/page/bindings/template_binding/view_lookup_for_path.rb +92 -0
  40. data/lib/volt/page/bindings/template_binding.rb +10 -85
  41. data/lib/volt/page/channel.rb +0 -1
  42. data/lib/volt/page/page.rb +5 -7
  43. data/lib/volt/page/sub_context.rb +1 -1
  44. data/lib/volt/page/targets/base_section.rb +2 -2
  45. data/lib/volt/page/targets/helpers/comment_searchers.rb +2 -2
  46. data/lib/volt/reactive/reactive_accessors.rb +1 -1
  47. data/lib/volt/reactive/reactive_array.rb +6 -6
  48. data/lib/volt/router/routes.rb +4 -4
  49. data/lib/volt/server/rack/asset_files.rb +1 -2
  50. data/lib/volt/server/rack/component_code.rb +0 -2
  51. data/lib/volt/server/rack/component_paths.rb +2 -2
  52. data/lib/volt/server/rack/quiet_common_logger.rb +2 -2
  53. data/lib/volt/spec/capybara.rb +1 -1
  54. data/lib/volt/spec/sauce_labs.rb +6 -6
  55. data/lib/volt/spec/setup.rb +8 -7
  56. data/lib/volt/tasks/dispatcher.rb +12 -10
  57. data/lib/volt/tasks/task_handler.rb +1 -1
  58. data/lib/volt/utils/generic_pool.rb +2 -2
  59. data/lib/volt/volt/users.rb +7 -9
  60. data/lib/volt.rb +2 -4
  61. data/spec/apps/file_loading/app/missing_deps/config/dependencies.rb +1 -1
  62. data/spec/apps/kitchen_sink/Gemfile +2 -2
  63. data/spec/apps/kitchen_sink/app/main/config/dependencies.rb +1 -1
  64. data/spec/apps/kitchen_sink/app/main/config/routes.rb +0 -1
  65. data/spec/apps/kitchen_sink/app/main/models/user.rb +1 -1
  66. data/spec/apps/kitchen_sink/app/main/views/main/main.html +1 -1
  67. data/spec/apps/kitchen_sink/config/app.rb +1 -1
  68. data/spec/extra_core/array_spec.rb +4 -2
  69. data/spec/extra_core/blank_spec.rb +11 -0
  70. data/spec/extra_core/class_spec.rb +2 -2
  71. data/spec/extra_core/logger_spec.rb +50 -0
  72. data/spec/extra_core/string_transformations_spec.rb +0 -1
  73. data/spec/integration/cookies_spec.rb +1 -2
  74. data/spec/integration/flash_spec.rb +2 -3
  75. data/spec/integration/list_spec.rb +1 -1
  76. data/spec/integration/templates_spec.rb +0 -1
  77. data/spec/integration/url_spec.rb +1 -2
  78. data/spec/integration/user_spec.rb +3 -3
  79. data/spec/models/field_helpers_spec.rb +2 -2
  80. data/spec/models/model_spec.rb +21 -2
  81. data/spec/models/user_spec.rb +69 -0
  82. data/spec/models/validations_spec.rb +69 -78
  83. data/spec/models/validators/email_validator_spec.rb +3 -3
  84. data/spec/models/validators/format_validator_spec.rb +144 -0
  85. data/spec/models/validators/length_validator_spec.rb +82 -0
  86. data/spec/models/validators/phone_number_validator_spec.rb +3 -3
  87. data/spec/page/bindings/template_binding/view_lookup_for_path_spec.rb +149 -0
  88. data/spec/page/bindings/template_binding_spec.rb +0 -151
  89. data/spec/reactive/computation_spec.rb +46 -0
  90. data/spec/reactive/dependency_spec.rb +0 -1
  91. data/spec/reactive/reactive_array_spec.rb +0 -1
  92. data/spec/router/routes_spec.rb +0 -4
  93. data/spec/server/html_parser/view_parser_spec.rb +0 -4
  94. data/spec/server/rack/asset_files_spec.rb +1 -1
  95. data/spec/server/rack/quite_common_logger_spec.rb +55 -0
  96. data/spec/spec_helper.rb +2 -5
  97. data/spec/tasks/dispatcher_spec.rb +16 -5
  98. data/spec/tasks/live_query_spec.rb +0 -1
  99. data/spec/tasks/query_tasks.rb +0 -1
  100. data/spec/tasks/query_tracker_spec.rb +0 -3
  101. data/spec/templates/targets/binding_document/component_node_spec.rb +0 -1
  102. data/spec/utils/generic_counting_pool_spec.rb +0 -1
  103. data/spec/utils/generic_pool_spec.rb +0 -1
  104. data/templates/component/assets/images/.empty_directory +0 -0
  105. data/templates/project/README.md.tt +3 -2
  106. data/templates/project/app/main/assets/images/.empty_directory +0 -0
  107. data/templates/project/config/base/index.html +6 -7
  108. data/volt.gemspec +3 -5
  109. metadata +27 -9
  110. data/lib/volt/extra_core/numeric.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8216481df968b9b14ca2012121437a9a1c238ac2
4
- data.tar.gz: 227dc9d5fd4540fb6870797ecb6d869fad1043ec
3
+ metadata.gz: e86338c95256cca4f64bc6889a2e6f86626c3e23
4
+ data.tar.gz: 71e9eef1f83c4a1fc2213b8ca9610da56518a401
5
5
  SHA512:
6
- metadata.gz: d21c46f836fd782f9d950a05799bd09ea5d9f62949cb516c85647721d656b51b2a060d050825d0f0bcd978346aaaf1f96c943672619e38174af5feea3d2b9725
7
- data.tar.gz: c7e55d8e6be62c7040ad98456a227779e6d8177dd453feaca9639883de0ad41479115c12e022e2e4aecc9962bd26569d5f4262cbe45905e29520f5fe1492088a
6
+ metadata.gz: e689c874e137c1e7aa59303238aa6d287f89e407b8c003bbcd43242201ac7fb2ab3254fafa5ccaa4f105fdfcf4c720d76a631684e8224511c9b8f62d92227f54
7
+ data.tar.gz: ed08a559fb6f89a85bf41f19822316195653acac6a0dda68c6f261e4e3e53c6677fe84b5525207c5a5fea3c01f2db64ef5faf547fd607db338d6adba21d9b4e0
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.5
1
+ 2.2.0
data/.travis.yml CHANGED
@@ -1,10 +1,13 @@
1
1
  language: ruby
2
+ sudo: false
3
+ cache: bundler
2
4
  rvm:
3
5
  - 2.1.0
4
6
  - 2.1.1
5
7
  - 2.1.2
6
8
  - 2.1.3
7
9
  - 2.1.5
10
+ - 2.2.0
8
11
  env:
9
12
  global:
10
13
  - secure: W03bt+hqLkAenymipqADIuRGZMiqu/sKx+9PXJJzCy0qAgmKs/PhPpHRpGpSmaYvVQQuiWX/rsw7xWXc2CHDJSp5aInd693xhJuSKXmnUp00r14/io+VWI9LE0lWjx4qdb6YQhdBTaxJB0+1sHDwU088yWBNnri/KwU4UlUgO5M=
data/CHANGELOG.md CHANGED
@@ -2,9 +2,14 @@
2
2
 
3
3
  ## 0.8.27 - WIP
4
4
  ### Added
5
- - Added email validator
5
+ - the {action}_remove method had been changed to before_{action}_remove and after_{action}_remove to provide more hooks and a clearer understanding of when it is happening.
6
+ - Changed it so content bindings escape all html (for CSRF - thanks @ChaosData)
7
+ - Added formats, email, phone validators (thanks @lexun and @kxcrl)
6
8
  - each_with_index is now supported in views and the ```index``` value is no longer provided by default.
7
-
9
+ - fixed bug with cookie parsing with equals in them
10
+ - fixed bug appending existing models to a collection
11
+ - refactored TemplateBinding, moved code into ViewLookupForPath (SRP)
12
+ - reserved fields now get a warning in models
8
13
 
9
14
  ## 0.8.24 - 2014-12-05
10
15
  ### Added
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,133 @@
1
+ Contributing to Volt
2
+ =====================
3
+
4
+ You want to contribute? Great! Thanks for being awesome! Volt is work of [hundreds of contributors](https://github.com/voltrb/volt/graphs/contributors). You're encouraged to submit [pull requests](https://github.com/voltrb/volt/pulls), [propose features and discuss issues](https://github.com/voltrb/volt/issues). When in doubt, ask a question in the [Volt gitter.im chatroom](https://gitter.im/voltrb/volt).
5
+
6
+ #### Find Something to Work on
7
+
8
+ If you want to contribute, but aren't sure what to work on, we keep our list of current todos in Trello at https://trello.com/b/QdCx9Tqb/volt Before starting, feel free to chat with me @ryanstout on [gitter](https://gitter.im/voltrb/volt).
9
+
10
+ #### Fork the Project
11
+
12
+ Fork the [project on Github](https://github.com/voltrb/volt) and check out your copy.
13
+
14
+ ```
15
+ git clone https://github.com/contributor/volt.git
16
+ cd volt
17
+ git remote add upstream https://github.com/voltrb/volt.git
18
+ ```
19
+
20
+ #### Create a Topic Branch
21
+
22
+ Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
23
+
24
+ ```
25
+ git checkout master
26
+ git pull upstream master
27
+ git checkout -b my-feature-branch
28
+ ```
29
+
30
+ #### Bundle Install and Test
31
+ Ensure that PhantomJS is installed on your computer.
32
+
33
+ ```
34
+ phantomjs --version
35
+ ```
36
+
37
+ If not installed, you can install from the source or use Homebrew:
38
+
39
+ ```
40
+ brew upgrade && brew install phantomjs
41
+ ```
42
+
43
+ #### Bundle Install and Test
44
+
45
+ Ensure that you can build the project and run tests.
46
+
47
+ ```
48
+ bundle install
49
+ bundle exec rake
50
+ ```
51
+
52
+ By default rake doesn't run the integration tests. The integration tests use capybara to run the tests in a real browser, (read more [here](https://github.com/voltrb/docs/blob/master/en/docs/testing.md)). You can run with integration tests in a browser with:
53
+
54
+ ```
55
+ BROWSER=firefox bundle exec rake
56
+ ````
57
+
58
+ #### Write Tests
59
+
60
+ Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. Add to [spec/volt](spec/volt).
61
+
62
+ We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.
63
+
64
+ #### Write Code
65
+
66
+ Implement your feature or bug fix.
67
+
68
+ Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop), run `bundle exec rubocop` and fix any style issues highlighted.
69
+
70
+ Make sure that `bundle exec rake` completes without errors.
71
+
72
+ #### Write Documentation
73
+
74
+ Document any external behavior in the [README](README.md).
75
+
76
+ #### Commit Changes
77
+
78
+ Make sure git knows your name and email address:
79
+
80
+ ```
81
+ git config --global user.name "Your Name"
82
+ git config --global user.email "contributor@example.com"
83
+ ```
84
+
85
+ Writing good commit logs is important. A commit log should describe what changed and why.
86
+
87
+ ```
88
+ git add ...
89
+ git commit
90
+ ```
91
+
92
+ #### Push
93
+
94
+ ```
95
+ git push origin my-feature-branch
96
+ ```
97
+
98
+ #### Make a Pull Request
99
+
100
+ Go to https://github.com/contributor/volt and select your feature branch. Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
101
+
102
+ #### Rebase
103
+
104
+ If you've been working on a change for a while, rebase with upstream/master.
105
+
106
+ ```
107
+ git fetch upstream
108
+ git rebase upstream/master
109
+ git push origin my-feature-branch -f
110
+ ```
111
+
112
+ #### Update CHANGELOG Again
113
+
114
+ Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
115
+
116
+ ```
117
+ * [#123](https://github.com/voltrb/volt/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
118
+ ```
119
+
120
+ Amend your previous commit and force push the changes.
121
+
122
+ ```
123
+ git commit --amend
124
+ git push origin my-feature-branch -f
125
+ ```
126
+
127
+ #### Check on Your Pull Request
128
+
129
+ Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
130
+
131
+ #### Thank You
132
+
133
+ Please do know that we really appreciate and value your time and work. We love you, really.
data/Gemfile CHANGED
@@ -6,7 +6,6 @@ group :development do
6
6
  # For testing the kitchen sink app
7
7
  # Twitter bootstrap
8
8
  gem 'volt-bootstrap'
9
- gem 'byebug'
10
9
 
11
10
  # Simple theme for bootstrap, remove to theme yourself.
12
11
  gem 'volt-bootstrap-jumbotron-theme'
data/Rakefile CHANGED
@@ -20,15 +20,23 @@ task :docs do
20
20
  # end
21
21
  end
22
22
 
23
- Opal::RSpec::RakeTask.new
23
+ # Setup the opal:rspec task
24
+ Opal::RSpec::RakeTask.new('opal:rspec') do |s|
25
+ # Add the app folder to the opal load path.
26
+ s.append_path('app')
27
+ end
28
+
24
29
 
25
30
  task default: [:test]
26
31
 
32
+ require 'rspec/core/rake_task'
33
+ RSpec::Core::RakeTask.new('ruby:rspec')
34
+
27
35
  task :test do
28
- puts "--------------------------\nRun specs in normal ruby\n--------------------------"
29
- system 'bundle exec rspec'
30
36
  puts "--------------------------\nRun specs in Opal\n--------------------------"
31
37
  Rake::Task['opal:rspec'].invoke
38
+ puts "--------------------------\nRun specs in normal ruby\n--------------------------"
39
+ Rake::Task['ruby:rspec'].invoke
32
40
  end
33
41
 
34
42
  # Rubocop task
data/Readme.md CHANGED
@@ -1,9 +1,8 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/volt.svg)](http://badge.fury.io/rb/volt)
2
2
  [![Code Climate](https://codeclimate.com/github/voltrb/volt/badges/gpa.svg)](https://codeclimate.com/github/voltrb/volt)
3
- [![Build Status](http://img.shields.io/travis/voltrb/volt/master.svg)](https://travis-ci.org/voltrb/volt)
3
+ [![Build Status](http://img.shields.io/travis/voltrb/volt/master.svg?style=flat)](https://travis-ci.org/voltrb/volt)
4
4
  [![Inline docs](http://inch-ci.org/github/voltrb/volt.svg?branch=master)](http://inch-ci.org/github/voltrb/volt)
5
5
  [![Volt Chat](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/voltrb/volt)
6
- [![Stories in Ready](https://badge.waffle.io/voltrb/volt.png?label=ready&title=Ready)](https://waffle.io/voltrb/volt)
7
6
 
8
7
  ** For the current status of volt, read: http://voltframework.com/blog
9
8
 
@@ -18,8 +17,9 @@ Pages HTML is written in a template language where you can put ruby between ```{
18
17
  See some demo videos here:
19
18
  - [Volt Todos Example](https://www.youtube.com/watch?v=Tg-EtRnMz7o)
20
19
  - [Pagination Example](https://www.youtube.com/watch?v=1uanfzMLP9g)
21
- - [Build a Blog with Volt](https://www.youtube.com/watch?v=c478sMlhx1o)
22
- ** Note: The blog video is outdated, expect an updated version soon.
20
+ - [Routes and Templates](https://www.youtube.com/watch?v=1yNMP3XR6jU)
21
+ - [Isomorphic App Development - Rubyconf 2014](https://www.youtube.com/watch?v=7i6AL7Walc4)
22
+ - [Build a Blog with Volt](https://www.youtube.com/watch?v=c478sMlhx1o) ** Note: The blog video is outdated, expect an updated version soon.
23
23
 
24
24
  Check out demo apps:
25
25
  - https://github.com/voltrb/todos3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.27.beta2
1
+ 0.8.27.beta3
@@ -1,10 +1,12 @@
1
- require 'bcrypt' if RUBY_PLATFORM != 'opal'
1
+ unless RUBY_PLATFORM == 'opal'
2
+ require 'bcrypt'
3
+ end
2
4
 
3
5
  module Volt
4
6
  class User < Model
5
- # returns true if the user configured using the username
7
+ # returns login field name depending on config settings
6
8
  def self.login_field
7
- if Volt.config.public.try(:auth).try(:use_username)
9
+ if Volt.config.try(:public).try(:auth).try(:use_username)
8
10
  :username
9
11
  else
10
12
  :email
@@ -24,6 +26,7 @@ module Volt
24
26
  # on the server, we bcrypt the password and store the result
25
27
  self._hashed_password = BCrypt::Password.create(val)
26
28
  else
29
+ # Assign the attribute
27
30
  self._password = val
28
31
  end
29
32
  end
@@ -1,19 +1,28 @@
1
1
  require 'pry'
2
2
 
3
3
  class Pry
4
- # To make the console more useful, we make it so we flush the event registry
5
- # after each line. This makes it so events are triggered after each line.
6
- # To accomplish this we monkey-patch pry.
7
- def rep(target = TOPLEVEL_BINDING)
8
- target = Pry.binding_for(target)
9
- result = re(target)
10
-
11
- Pry.critical_section do
12
- show_result(result)
4
+ class REPL
5
+ # To make the console more useful, we make it so we flush the event registry
6
+ # after each line. This makes it so events are triggered after each line.
7
+ # To accomplish this we monkey-patch pry.
8
+ def repl
9
+ loop do
10
+ case val = read
11
+ when :control_c
12
+ output.puts ""
13
+ pry.reset_eval_string
14
+ when :no_more_input
15
+ output.puts "" if output.tty?
16
+ break
17
+ else
18
+ output.puts "" if val.nil? && output.tty?
19
+ return pry.exit_value unless pry.eval(val)
20
+ end
21
+
22
+ # Flush after each line
23
+ Volt::Computation.flush!
24
+ end
13
25
  end
14
-
15
- # Automatically flush after each line
16
- Volt::Computation.flush!
17
26
  end
18
27
  end
19
28
 
@@ -12,4 +12,4 @@ module Volt
12
12
  end
13
13
  end
14
14
  end
15
- end
15
+ end
data/lib/volt/cli.rb CHANGED
@@ -48,7 +48,8 @@ module Volt
48
48
  # TODO: this is a work around for a bug when switching between
49
49
  # source maps and non-source maps.
50
50
  if File.exist?('config.ru') && File.exist?('Gemfile')
51
- FileUtils.rm_rf('tmp/.')
51
+ FileUtils.rm_rf('tmp/sass')
52
+ FileUtils.rm_rf('tmp/sprockets')
52
53
  else
53
54
  say('Current folder is not a Volt project', :red)
54
55
  return
@@ -82,9 +83,9 @@ module Volt
82
83
  method_option :bin, type: :boolean, default: false, aliases: '-b', banner: 'Generate a binary for your library.'
83
84
  method_option :test, type: :string, lazy_default: 'rspec', aliases: '-t', banner: "Generate a test directory for your library: 'rspec' is the default, but 'minitest' is also supported."
84
85
  method_option :edit, type: :string, aliases: '-e',
85
- lazy_default: [ENV['BUNDLER_EDITOR'], ENV['VISUAL'], ENV['EDITOR']].find { |e| !e.nil? && !e.empty? },
86
- required: false, banner: '/path/to/your/editor',
87
- desc: 'Open generated gemspec in the specified editor (defaults to $EDITOR or $BUNDLER_EDITOR)'
86
+ lazy_default: [ENV['BUNDLER_EDITOR'], ENV['VISUAL'], ENV['EDITOR']].find { |e| !e.nil? && !e.empty? },
87
+ required: false, banner: '/path/to/your/editor',
88
+ desc: 'Open generated gemspec in the specified editor (defaults to $EDITOR or $BUNDLER_EDITOR)'
88
89
 
89
90
  def gem(name)
90
91
  require 'volt/cli/new_gem'
data/lib/volt/config.rb CHANGED
@@ -13,14 +13,12 @@ if RUBY_PLATFORM == 'opal'
13
13
  module Volt
14
14
  class << self
15
15
  # Returns the config
16
- def config
17
- @config
18
- end
16
+ attr_reader :config
19
17
 
20
18
  # Called on page load to pass the backend config to the client
21
19
  def setup_client_config(config_hash)
22
20
  # Only Volt.config.public is passed from the server (for security reasons)
23
- @config = wrap_config({public: config_hash})
21
+ @config = wrap_config(public: config_hash)
24
22
  end
25
23
 
26
24
  # Wraps the config hash in an OpenStruct so it can be accessed in the same way
@@ -49,17 +47,17 @@ else
49
47
  def defaults
50
48
  app_name = File.basename(Dir.pwd)
51
49
  {
52
- app_name: app_name,
53
- db_name: ENV['DB_NAME'] || (app_name + '_' + Volt.env.to_s),
54
- db_host: ENV['DB_HOST'] || 'localhost',
55
- db_port: (ENV['DB_PORT'] || 27_017).to_i,
56
- db_driver: ENV['DB_DRIVER'] || 'mongo',
57
- }
50
+ app_name: app_name,
51
+ db_name: ENV['DB_NAME'] || (app_name + '_' + Volt.env.to_s),
52
+ db_host: ENV['DB_HOST'] || 'localhost',
53
+ db_port: (ENV['DB_PORT'] || 27_017).to_i,
54
+ db_driver: ENV['DB_DRIVER'] || 'mongo'
55
+ }
58
56
  end
59
57
 
60
58
  # Resets the configuration to the default (empty hash)
61
59
  def reset_config!
62
- self.configure do |c|
60
+ configure do |c|
63
61
  c.from_h(defaults)
64
62
  end
65
63
  end
@@ -6,6 +6,22 @@ module Volt
6
6
 
7
7
  reactive_accessor :current_model
8
8
 
9
+ # The section is assigned a reference to a "DomSection" which has
10
+ # the dom for the controllers view.
11
+ attr_accessor :section
12
+
13
+
14
+ # Container returns the node that is parent to all nodes in the section.
15
+ def container
16
+ section.container_node
17
+ end
18
+
19
+ def dom_nodes
20
+ section.range
21
+ end
22
+
23
+
24
+
9
25
  def self.model(val)
10
26
  @default_model = val
11
27
  end
@@ -4,7 +4,7 @@ module Volt
4
4
  class DataStore
5
5
  def self.fetch
6
6
  if Volt.config.db_driver == 'mongo'
7
- return MongoDriver.fetch
7
+ MongoDriver.fetch
8
8
  else
9
9
  fail "#{database_name} is not a supported database"
10
10
  end
@@ -1,10 +1,5 @@
1
1
  class Array
2
2
  def sum
3
- total = 0
4
- each do |val|
5
- total += val
6
- end
7
-
8
- total
3
+ inject(0, :+)
9
4
  end
10
5
  end
@@ -70,9 +70,7 @@ class String
70
70
  # ' '.blank? # => true
71
71
  # ' something here '.blank? # => false
72
72
  def blank?
73
- # self !~ /[^[:space:]]/
74
- # TODO: Opal fails with the previous regex
75
- strip == ''
73
+ self !~ /\S/
76
74
  end
77
75
  end
78
76
 
@@ -24,4 +24,4 @@ class Class
24
24
  undef_method(method)
25
25
  end
26
26
  end
27
- end
27
+ end
@@ -4,7 +4,6 @@ require 'volt/extra_core/object'
4
4
  require 'volt/extra_core/blank'
5
5
  require 'volt/extra_core/stringify_keys'
6
6
  require 'volt/extra_core/string'
7
- require 'volt/extra_core/numeric'
8
7
  require 'volt/extra_core/true_false'
9
8
  require 'volt/extra_core/class'
10
9
  if RUBY_PLATFORM == 'opal'
@@ -13,6 +13,83 @@ if RUBY_PLATFORM == 'opal'
13
13
  end
14
14
  end
15
15
  end
16
+
17
+ class VoltLogger < Logger
18
+ end
16
19
  else
17
20
  require 'logger'
18
- end
21
+
22
+ module Volt
23
+ class VoltLogger < Logger
24
+ def initialize(current={})
25
+ super(STDOUT)
26
+ @current = current
27
+ @formatter = Volt::VoltLoggerFormatter.new
28
+ end
29
+
30
+ def log_dispatch(class_name, method_name, run_time, args)
31
+ @current = {
32
+ args: args,
33
+ class_name: class_name,
34
+ method_name: method_name,
35
+ run_time: run_time
36
+ }
37
+
38
+ log(Logger::INFO, task_dispatch_message)
39
+ end
40
+
41
+ def args
42
+ @current[:args]
43
+ end
44
+
45
+ def class_name
46
+ colorize(@current[:class_name].to_s, :light_blue)
47
+ end
48
+
49
+ def method_name
50
+ colorize(@current[:method_name].to_s, :green)
51
+ end
52
+
53
+ def run_time
54
+ colorize(@current[:run_time].to_s + 'ms', :green)
55
+ end
56
+
57
+
58
+ private
59
+
60
+ def colorize(string, color)
61
+ if STDOUT.tty? && string
62
+ case color
63
+ when :cyan
64
+ "\e[1;34m" + string + "\e[0;37m"
65
+ when :green
66
+ "\e[0;32m" + string + "\e[0;37m"
67
+ when :light_blue
68
+ "\e[1;34m" + string + "\e[0;37m"
69
+ when :purple
70
+ "\e[1;35m" + string + "\e[0;37m"
71
+ when :red
72
+ "\e[1;31m" + string + "\e[0;37m"
73
+ end
74
+ else
75
+ string.to_s
76
+ end
77
+ end
78
+
79
+ def task_dispatch_message
80
+ msg = "task #{class_name}##{method_name} in #{run_time}\n"
81
+ if args.size > 0
82
+ arg_str = args.map {|v| v.inspect }.join(', ')
83
+ msg += "with args: #{arg_str}\n"
84
+ end
85
+ msg
86
+ end
87
+ end
88
+
89
+ class VoltLoggerFormatter < Logger::Formatter
90
+ def call(severity, time, progname, msg)
91
+ "\n\n[#{severity}] #{msg2str(msg)}\n"
92
+ end
93
+ end
94
+ end
95
+ end
@@ -9,18 +9,18 @@ class Object
9
9
  # Provides the same functionality as ||, but treats a nil model as falsy
10
10
  def or(other)
11
11
  if self && !self.nil?
12
- return self
12
+ self
13
13
  else
14
- return other
14
+ other
15
15
  end
16
16
  end
17
17
 
18
18
  # Provides the same functionality as &&, treats a nil model as falsy
19
19
  def and(other)
20
20
  if self && !self.nil?
21
- return other
21
+ other
22
22
  else
23
- return self
23
+ self
24
24
  end
25
25
  end
26
26
 
@@ -29,7 +29,7 @@ module Volt
29
29
  if @persistor.respond_to?(method_name)
30
30
  @persistor.send(method_name, *args, &block)
31
31
  else
32
- raise "this model's persistance layer does not support #{method_name}, try using store"
32
+ fail "this model's persistance layer does not support #{method_name}, try using store"
33
33
  end
34
34
  end
35
35
  end
@@ -77,7 +77,7 @@ module Volt
77
77
 
78
78
  # Works like << except it returns a promise
79
79
  def append(model)
80
- promise, model = self.send(:<<, model)
80
+ promise, model = send(:<<, model)
81
81
 
82
82
  # Return a promise if one doesn't exist
83
83
  promise ||= Promise.new.resolve(model)
@@ -85,7 +85,6 @@ module Volt
85
85
  promise
86
86
  end
87
87
 
88
-
89
88
  # Find one does a query, but only returns the first item or
90
89
  # nil if there is no match. Unlike #find, #find_one does not
91
90
  # return another cursor that you can call .then on.
@@ -1,6 +1,5 @@
1
1
  module Volt
2
2
  module Buffer
3
-
4
3
  def save!
5
4
  # Compute the erros once
6
5
  errors = self.errors
@@ -72,4 +71,4 @@ module Volt
72
71
  model
73
72
  end
74
73
  end
75
- end
74
+ end
@@ -1,13 +1,13 @@
1
1
  # Provides a method to setup a field on a model.
2
2
  module FieldHelpers
3
- class InvalidFieldClass < RuntimeError ; end
3
+ class InvalidFieldClass < RuntimeError; end
4
4
 
5
5
  module ClassMethods
6
6
  # field lets you declare your fields instead of using the underscore syntax.
7
7
  # An optional class restriction can be passed in.
8
- def field(name, klass=nil)
8
+ def field(name, klass = nil)
9
9
  if klass && ![String, Numeric].include?(klass)
10
- raise FieldHelpers::InvalidFieldClass, "valid field types is currently limited to String or Numeric"
10
+ fail FieldHelpers::InvalidFieldClass, 'valid field types is currently limited to String or Numeric'
11
11
  end
12
12
 
13
13
  define_method(name) do
@@ -33,5 +33,4 @@ module FieldHelpers
33
33
  def self.included(base)
34
34
  base.send :extend, ClassMethods
35
35
  end
36
-
37
- end
36
+ end