settings_js 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +2 -2
- data/README.markdown +55 -0
- data/lib/settings_js/{adapters → backends}/settings_logic.rb +1 -1
- data/lib/settings_js/config.rb +1 -1
- data/lib/settings_js/merger.rb +5 -5
- data/settings_js.gemspec +3 -3
- data/spec/fixtures/settings_js/{adapters → backends}/settings_logic.yml +0 -0
- data/spec/javascripts/support/jasmine_config.rb +2 -2
- data/spec/settings_js/{adapters → backends}/settings_js_spec.rb +7 -7
- data/spec/settings_js/config_spec.rb +1 -1
- data/spec/settings_js/merger_spec.rb +3 -3
- metadata +14 -12
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.markdown
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Welcome to Settings-js
|
2
|
+
|
3
|
+
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/kdisneur/settings-js)
|
4
|
+
[![Travis CI](https://secure.travis-ci.org/kdisneur/settings-js.png)](http://travis-ci.org/kdisneur/settings-js)
|
5
|
+
|
6
|
+
Use application specific settings with Javascript.
|
7
|
+
|
8
|
+
As modern web applications rely more and more on javascript and frameworks like backbone/angular, it can be quite a hussle to maintain duplicate values in javascript and ruby.
|
9
|
+
|
10
|
+
`Settings-js` is designed to work with different settings backends. As of today, only [Settingslogic](https://github.com/binarylogic/settingslogic) is supported.
|
11
|
+
|
12
|
+
## Getting started
|
13
|
+
|
14
|
+
Add this to your Gemfile
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'settings_js'
|
18
|
+
```
|
19
|
+
|
20
|
+
Add the following to an initializer:
|
21
|
+
|
22
|
+
* Settings Backend (for the moment, only [settingslogic](https://github.com/binarylogic/settingslogic) is implemented)
|
23
|
+
* Settings Class used by the application
|
24
|
+
* List the keys that must be accessible in the javascript
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
SettingsJs.configuration do |config|
|
28
|
+
config.backend = 'settings_logic' # backend used
|
29
|
+
config.klass = Settings # your own settings class
|
30
|
+
config.keys = %w(hosts custom.keys) # imported keys
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
Load the Javascript file and access the `Settings` class:
|
35
|
+
|
36
|
+
```javascript
|
37
|
+
// = require settings-js/settings
|
38
|
+
|
39
|
+
Settings.host_name
|
40
|
+
# => 'http://localhost:8080'
|
41
|
+
```
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Once you've made your great commits:
|
46
|
+
|
47
|
+
1. Fork settings_js
|
48
|
+
2. Create a topic branch - git checkout -b my_branch
|
49
|
+
3. Push to your branch - git push origin my_branch
|
50
|
+
4. Create a Pull Request from your branch
|
51
|
+
5. That's it!
|
52
|
+
|
53
|
+
## License
|
54
|
+
|
55
|
+
`Settings-js` is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
data/lib/settings_js/config.rb
CHANGED
data/lib/settings_js/merger.rb
CHANGED
@@ -9,7 +9,7 @@ module SettingsJs
|
|
9
9
|
raise TypeError.new('the configuration key "keys" must be reduceable')
|
10
10
|
end
|
11
11
|
|
12
|
-
config.keys.reduce({}) { |hash, base_key| hash.merge(
|
12
|
+
config.keys.reduce({}) { |hash, base_key| hash.merge(backend.to_hash(base_key)) }
|
13
13
|
end
|
14
14
|
|
15
15
|
def to_json
|
@@ -22,11 +22,11 @@ module SettingsJs
|
|
22
22
|
SettingsJs::Config.instance
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
26
|
-
|
25
|
+
def backend
|
26
|
+
backend_proxy_path = "settings_js/backends/#{config.backend}"
|
27
27
|
|
28
|
-
require
|
29
|
-
|
28
|
+
require backend_proxy_path
|
29
|
+
backend_proxy_path.classify.constantize.new(config.klass)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
data/settings_js.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'settings_js'
|
3
|
-
s.version = '0.0
|
3
|
+
s.version = '0.1.0'
|
4
4
|
s.date = '2012-11-30'
|
5
5
|
s.summary = 'Sharing same application settings between ruby and javascript'
|
6
6
|
s.authors = ['Kevin Disneur']
|
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.test_files = `git ls-files -- spec/*`.split(/\n/)
|
10
10
|
s.homepage = 'http://rubygems.org/gems/settings_js'
|
11
11
|
|
12
|
-
s.add_dependency 'active_support'
|
13
|
-
s.add_dependency 'json'
|
12
|
+
s.add_dependency 'active_support', '> 1.0'
|
13
|
+
s.add_dependency 'json', '> 0'
|
14
14
|
s.add_dependency 'sprockets'
|
15
15
|
|
16
16
|
s.add_development_dependency 'jasmine'
|
File without changes
|
@@ -8,7 +8,7 @@ require 'sprockets'
|
|
8
8
|
module Jasmine
|
9
9
|
|
10
10
|
class DummySettings < Settingslogic
|
11
|
-
source File.join(Spec_root, 'fixtures', 'settings_js', '
|
11
|
+
source File.join(Spec_root, 'fixtures', 'settings_js', 'backends', 'settings_logic.yml')
|
12
12
|
end
|
13
13
|
|
14
14
|
|
@@ -28,7 +28,7 @@ module Jasmine
|
|
28
28
|
|
29
29
|
def gem_configuration
|
30
30
|
SettingsJs.configuration do |config|
|
31
|
-
config.
|
31
|
+
config.backend = 'settings_logic'
|
32
32
|
config.keys = %w(key1 key2.sub_key2_2)
|
33
33
|
config.klass = DummySettings
|
34
34
|
end
|
@@ -1,22 +1,22 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'settingslogic'
|
3
|
-
require 'settings_js/
|
3
|
+
require 'settings_js/backends/settings_logic'
|
4
4
|
|
5
|
-
describe 'SettingsJs::
|
5
|
+
describe 'SettingsJs::Backends::SettingsLogic' do
|
6
6
|
|
7
7
|
let(:settings_klass) do
|
8
8
|
Class.new(Settingslogic) do
|
9
|
-
source File.join(Spec_root, 'fixtures', 'settings_js', '
|
9
|
+
source File.join(Spec_root, 'fixtures', 'settings_js', 'backends', 'settings_logic.yml')
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
let(:
|
13
|
+
let(:backend_instance) { SettingsJs::Backends::SettingsLogic.new(settings_klass) }
|
14
14
|
|
15
|
-
it {
|
15
|
+
it { backend_instance.should have_attr_accessor(:klass) }
|
16
16
|
|
17
17
|
describe '#to_hash' do
|
18
18
|
it 'returns subkeys when base key is in settings root' do
|
19
|
-
|
19
|
+
backend_instance.to_hash('key1').should == { 'sub_key1' => 'sub_value1' }
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'returns subkeys when base key is under the settings root' do
|
@@ -27,7 +27,7 @@ describe 'SettingsJs::Adapters::SettingsLogic' do
|
|
27
27
|
}
|
28
28
|
}
|
29
29
|
|
30
|
-
|
30
|
+
backend_instance.to_hash('key2.sub_key2_2').should == expected_hash
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe 'SettingsJs::Config' do
|
4
4
|
let(:config) { SettingsJs::Config.instance }
|
5
5
|
|
6
|
-
it { config.should have_attr_accessor :
|
6
|
+
it { config.should have_attr_accessor :backend }
|
7
7
|
it { config.should have_attr_accessor :keys }
|
8
8
|
it { config.should have_attr_accessor :klass }
|
9
9
|
end
|
@@ -28,14 +28,14 @@ describe SettingsJs::Merger do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'returns a hash which merge all keys hash response' do
|
31
|
-
|
32
|
-
|
31
|
+
backend = mock(:backend)
|
32
|
+
backend.stub(:to_hash).and_return({ key1: 'value1', key2: 'value2' }, { key2: { key2_1: 'value2_1', key2_2: 'value2_2' }})
|
33
33
|
|
34
34
|
config = mock(:config)
|
35
35
|
config.stub(:keys).and_return(%w(key1 key2))
|
36
36
|
|
37
37
|
merger.stub(:config).and_return(config)
|
38
|
-
merger.stub(:
|
38
|
+
merger.stub(:backend).and_return(backend)
|
39
39
|
|
40
40
|
expected_hash = {
|
41
41
|
key1: 'value1',
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: settings_js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -16,23 +16,23 @@ dependencies:
|
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- - ! '
|
19
|
+
- - ! '>'
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
21
|
+
version: '1.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- - ! '
|
27
|
+
- - ! '>'
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
29
|
+
version: '1.0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: json
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- - ! '
|
35
|
+
- - ! '>'
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: '0'
|
38
38
|
type: :runtime
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- - ! '
|
43
|
+
- - ! '>'
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
@@ -131,21 +131,23 @@ extra_rdoc_files: []
|
|
131
131
|
files:
|
132
132
|
- .gitignore
|
133
133
|
- .rvmrc
|
134
|
+
- .travis.yml
|
134
135
|
- Gemfile
|
135
136
|
- Gemfile.lock
|
137
|
+
- README.markdown
|
136
138
|
- Rakefile
|
137
139
|
- app/assets/javascripts/settings-js/settings.js.erb
|
138
140
|
- lib/settings_js.rb
|
139
|
-
- lib/settings_js/
|
141
|
+
- lib/settings_js/backends/settings_logic.rb
|
140
142
|
- lib/settings_js/config.rb
|
141
143
|
- lib/settings_js/merger.rb
|
142
144
|
- settings_js.gemspec
|
143
|
-
- spec/fixtures/settings_js/
|
145
|
+
- spec/fixtures/settings_js/backends/settings_logic.yml
|
144
146
|
- spec/javascripts/helpers/SpecHelper.js
|
145
147
|
- spec/javascripts/settings-js/settings_js_spec.js
|
146
148
|
- spec/javascripts/support/jasmine.yml
|
147
149
|
- spec/javascripts/support/jasmine_config.rb
|
148
|
-
- spec/settings_js/
|
150
|
+
- spec/settings_js/backends/settings_js_spec.rb
|
149
151
|
- spec/settings_js/config_spec.rb
|
150
152
|
- spec/settings_js/merger_spec.rb
|
151
153
|
- spec/settings_js_spec.rb
|
@@ -176,12 +178,12 @@ signing_key:
|
|
176
178
|
specification_version: 3
|
177
179
|
summary: Sharing same application settings between ruby and javascript
|
178
180
|
test_files:
|
179
|
-
- spec/fixtures/settings_js/
|
181
|
+
- spec/fixtures/settings_js/backends/settings_logic.yml
|
180
182
|
- spec/javascripts/helpers/SpecHelper.js
|
181
183
|
- spec/javascripts/settings-js/settings_js_spec.js
|
182
184
|
- spec/javascripts/support/jasmine.yml
|
183
185
|
- spec/javascripts/support/jasmine_config.rb
|
184
|
-
- spec/settings_js/
|
186
|
+
- spec/settings_js/backends/settings_js_spec.rb
|
185
187
|
- spec/settings_js/config_spec.rb
|
186
188
|
- spec/settings_js/merger_spec.rb
|
187
189
|
- spec/settings_js_spec.rb
|