volt 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 151e9fd7b7262c2b6ae7dc51fe4974ffb1c65628
4
- data.tar.gz: d43d340ea71cb98295ec0d3c5682676254b23ad5
3
+ metadata.gz: 3901f1ded564b432e705d7e1a024c3928c78d47a
4
+ data.tar.gz: 28af2588df6aefc650102f363e24f1ec92a28359
5
5
  SHA512:
6
- metadata.gz: ffbae1aa4a8653a2a9a7b36ef302aa32cbf81fe1f4aeb1d8f86e471d22bb27083cf1c018d3d5e6f89aa520f72e1f89a4b0ae21391701d6f1916726b909cbc3e8
7
- data.tar.gz: b6eefeb6b8fc07eabcc9f65ad6c0d28d577ff54409c8a16afdfdc13ef48b0f2b4296cd4c3c8c1734abe875f366c543fdcd1f1491454fdba45efd6020684e72cb
6
+ metadata.gz: 0259a07ecc92434d0c840c58323326ff7d0af81816c43dc3d13b7fced08656bdfd012231d2e88d6b4df01996dedf7529725a18e11d1fa4faacac2772dcdf4aa7
7
+ data.tar.gz: 6fe287443de67207d5e91a9e5739479454ff12750f6ae5b86533a36cfe899a6893dddffb09a9a2150326072a3377448b11970e587ba8cc43224d786a4c2cb961
data/Readme.md CHANGED
@@ -99,6 +99,7 @@ You can access the Volt console with:
99
99
  10. [Testing](#testing)
100
100
  11. [Volt Helpers](#volt-helpers)
101
101
  1. [Logging](#logging)
102
+ 2. [App Configuration](#app-configuration)
102
103
 
103
104
  # Getting Help
104
105
 
@@ -480,15 +481,18 @@ To convert a Model or an ArrayModel back to a normal hash, call .to_h or .to_a r
480
481
  user = Model.new
481
482
  user._name = 'Ryan'
482
483
  user._profiles = {
483
- twitter: 'http://www.twitter.com/ryanstout',
484
- dribbble: 'http://dribbble.com/ryanstout'
484
+ _twitter: 'http://www.twitter.com/ryanstout',
485
+ _dribbble: 'http://dribbble.com/ryanstout'
485
486
  }
486
487
 
487
488
  user._profiles.to_h
488
- # => {twitter: 'http://www.twitter.com/ryanstout', dribbble: 'http://dribbble.com/ryanstout'}
489
+ # => {_twitter: 'http://www.twitter.com/ryanstout', _dribbble: 'http://dribbble.com/ryanstout'}
489
490
 
490
491
  items = ArrayModel.new([1,2,3,4])
491
- items
492
+ # => #<ArrayModel:70226521081980 [1, 2, 3, 4]>
493
+
494
+ items.to_a
495
+ # => [1,2,3,4]
492
496
  ```
493
497
 
494
498
  You can get a normal array again by calling .to_a on an ArrayModel.
@@ -834,6 +838,22 @@ You can change the logger with:
834
838
  Volt.logger = Logger.new
835
839
  ```
836
840
 
841
+ ## App Configuration
842
+
843
+ Like many frameworks, Volt changes some default settings based on an environment flag. You can set the volt environment with the VOLT_ENV environment variable.
844
+
845
+ All files in the app's ```config``` folder are loaded when Volt boots. This is similar to the ```initializers``` folder in Rails.
846
+
847
+ Volt does its best to start with useful defaults. You can configure things like your database and app name in the config/app.rb file. The following are the current configuration options:
848
+
849
+ | name | default | description |
850
+ |-----------|---------------------------|---------------------------------------------------------------|
851
+ | app_name | the current folder name | This is used internally for things like logging. |
852
+ | db_driver | 'mongo' | Currently mongo is the only supported driver, more coming soon|
853
+ | db_name | "#{app_name}_#{Volt.env} | The name of the mongo database. |
854
+ | db_host | 'localhost' | The hostname for the mongo database. |
855
+ | db_port | 27017 | The port for the mongo database. |
856
+ | compress_deflate | false | If true, will run deflate in the app server, its better to let something like nginx do this though |
837
857
 
838
858
  ## Accessing DOM section in a controller
839
859
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.2
1
+ 0.8.3
@@ -2,8 +2,7 @@ require 'mongo'
2
2
 
3
3
  class DataStore
4
4
  def initialize
5
- @@mongo_db ||= Mongo::MongoClient.new("localhost", 27017)
6
- @@db ||= @@mongo_db.db("development")
5
+ @@db = Volt::DataStore.fetch
7
6
  end
8
7
 
9
8
  def query(collection, query)
@@ -3,8 +3,7 @@ require 'query_tasks'
3
3
 
4
4
  class StoreTasks
5
5
  def initialize(channel=nil, dispatcher=nil)
6
- @@mongo_db ||= Mongo::MongoClient.new("localhost", 27017)
7
- @@db ||= @@mongo_db.db("development")
6
+ @@db = Volt::DataStore.fetch
8
7
 
9
8
  @channel = channel
10
9
  @dispatcher = dispatcher
@@ -2,6 +2,11 @@ require 'volt/volt/environment'
2
2
  require 'volt/extra_core/extra_core'
3
3
  require 'volt/reactive/computation'
4
4
  require 'volt/reactive/dependency'
5
+ if RUBY_PLATFORM == 'opal'
6
+ else
7
+ require 'volt/config'
8
+ require 'volt/data_stores/data_store'
9
+ end
5
10
 
6
11
  class Volt
7
12
  if RUBY_PLATFORM == 'opal'
@@ -45,4 +50,5 @@ class Volt
45
50
  def self.in_browser?
46
51
  @@in_browser
47
52
  end
53
+
48
54
  end
@@ -8,6 +8,9 @@ end
8
8
 
9
9
  class Volt
10
10
  def self.boot(app_path)
11
+ # Run the app config to load all users config files
12
+ Volt.run_files_in_config_folder
13
+
11
14
  component_paths = ComponentPaths.new(app_path)
12
15
  component_paths.require_in_components
13
16
 
@@ -0,0 +1,31 @@
1
+ # Config lets a user set global config options for Volt.
2
+ class Volt
3
+
4
+ def self.setup
5
+ yield self.config
6
+ end
7
+
8
+ def self.config
9
+ @config || self.reset_config!
10
+ end
11
+
12
+ # Resets the configuration to the default (empty hash)
13
+ def self.reset_config!
14
+ app_name = File.basename(Dir.pwd)
15
+
16
+ @config = OpenStruct.new({
17
+ app_name: app_name,
18
+ db_name: ENV['DB_NAME'] || (app_name + '_' + Volt.env.to_s),
19
+ db_host: ENV['DB_HOST'] || 'localhost',
20
+ db_port: (ENV['DB_PORT'] || 27017).to_i,
21
+ db_driver: ENV['DB_DRIVER'] || 'mongo'
22
+ })
23
+ end
24
+
25
+ # Load in all .rb files in the config folder
26
+ def self.run_files_in_config_folder
27
+ Dir[Dir.pwd + '/config/*.rb'].each do |config_file|
28
+ require(config_file)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,13 @@
1
+ require 'volt/data_stores/mongo_driver'
2
+
3
+ class Volt
4
+ class DataStore
5
+ def self.fetch
6
+ if Volt.config.db_driver == 'mongo'
7
+ return MongoDriver.fetch
8
+ else
9
+ raise "#{database_name} is not a supported database"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ require 'mongo'
2
+
3
+ class Volt
4
+ class DataStore
5
+ class MongoDriver
6
+ def self.fetch
7
+ @@mongo_db ||= Mongo::MongoClient.new(Volt.config.db_host, Volt.config.db_path)
8
+ @@db ||= @@mongo_db.db(Volt.config.db_name)
9
+
10
+ return @@db
11
+ end
12
+ end
13
+ end
14
+ end
@@ -80,9 +80,11 @@ class Server
80
80
  @app = Rack::Builder.new
81
81
 
82
82
  # Should only be used in production
83
- # @app.use Rack::Deflater
83
+ if Volt.config.deflate
84
+ @app.use Rack::Deflater
85
+ @app.use Rack::Chunked
86
+ end
84
87
 
85
- # @app.use Rack::Chunked
86
88
  @app.use Rack::ContentLength
87
89
 
88
90
  @app.use Rack::KeepAlive
@@ -34,5 +34,9 @@ class Volt
34
34
  def inspect
35
35
  @env.inspect
36
36
  end
37
+
38
+ def to_s
39
+ @env
40
+ end
37
41
  end
38
42
  end
@@ -8,7 +8,7 @@
8
8
  <:nav href="/" text="Home" />
9
9
  <:nav href="/about" text="About" />
10
10
  </ul>
11
- <h3 class="text-muted">Project name</h3>
11
+ <h3 class="text-muted"><%= config[:name].titleize %></h3>
12
12
  </div>
13
13
 
14
14
  <:volt:notices />
@@ -0,0 +1,20 @@
1
+ Volt.setup do |config|
2
+ # Setup your global app config here.
3
+
4
+ # The app name defaults to the folder it is run in.
5
+ # config.app_name = '<%= config[:name] %>'
6
+
7
+ # Database config all start with db_ and can be set either in the config
8
+ # file or with an environment variable (DB_NAME for example).
9
+
10
+ # config.db_driver = 'mongo'
11
+ # config.db_name = (config.app_name + '_' + Volt.env.to_s)
12
+ # config.db_host = 'localhost'
13
+ # config.db_port = 27017
14
+
15
+ # Compression options
16
+
17
+ # If you are not running behind something like nginx in production, you can
18
+ # have rack deflate all files.
19
+ # config.deflate = true
20
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: volt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Stout
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-03 00:00:00.000000000 Z
11
+ date: 2014-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -377,8 +377,11 @@ files:
377
377
  - lib/volt/cli.rb
378
378
  - lib/volt/cli/asset_compile.rb
379
379
  - lib/volt/cli/new_gem.rb
380
+ - lib/volt/config.rb
380
381
  - lib/volt/console.rb
381
382
  - lib/volt/controllers/model_controller.rb
383
+ - lib/volt/data_stores/data_store.rb
384
+ - lib/volt/data_stores/mongo_driver.rb
382
385
  - lib/volt/extra_core/array.rb
383
386
  - lib/volt/extra_core/blank.rb
384
387
  - lib/volt/extra_core/extra_core.rb
@@ -566,8 +569,9 @@ files:
566
569
  - templates/project/app/main/models/.empty_directory
567
570
  - templates/project/app/main/views/main/about.html
568
571
  - templates/project/app/main/views/main/index.html
569
- - templates/project/app/main/views/main/main.html
572
+ - templates/project/app/main/views/main/main.html.tt
570
573
  - templates/project/config.ru
574
+ - templates/project/config/app.rb.tt
571
575
  - templates/project/lib/.empty_directory
572
576
  - templates/project/public/index.html
573
577
  - templates/project/spec/sample_spec.rb