rails_admin_settings 0.2.0 → 0.3.0
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.
- data/{lib → app/models}/rails_admin_settings/setting.rb +3 -1
- data/app/views/rails_admin/main/_setting_value.html.haml +1 -1
- data/config/locales/en.rails_admin_settings.yml +15 -1
- data/lib/rails_admin_settings.rb +2 -1
- data/lib/rails_admin_settings/rails_admin_config.rb +29 -25
- data/lib/rails_admin_settings/settings.rb +4 -1
- data/lib/rails_admin_settings/validation.rb +1 -1
- data/lib/rails_admin_settings/version.rb +1 -1
- data/spec/settings_spec.rb +12 -0
- metadata +5 -5
@@ -33,8 +33,10 @@ module RailsAdminSettings
|
|
33
33
|
|
34
34
|
index(key: 1)
|
35
35
|
|
36
|
-
if
|
36
|
+
if Object.const_defined?('RailsAdmin')
|
37
37
|
include RailsAdminSettings::RailsAdminConfig
|
38
|
+
else
|
39
|
+
puts "[rails_admin_settings] Rails Admin not detected -- put this gem after rails_admin in gemfile"
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
@@ -10,7 +10,7 @@
|
|
10
10
|
= form.text_area :raw, :value => field.value, :rows => 10, :cols => 80
|
11
11
|
|
12
12
|
= javascript_include_tag "rich/base.js"
|
13
|
-
javascript
|
13
|
+
:javascript
|
14
14
|
var instance = CKEDITOR.instances['#{form.dom_id(field)}'];
|
15
15
|
if(instance) { CKEDITOR.remove(instance); }
|
16
16
|
CKEDITOR.replace('#{form.dom_id(field)}', #{Rich.options().to_json.html_safe});
|
@@ -1,4 +1,18 @@
|
|
1
1
|
ru:
|
2
2
|
admin:
|
3
3
|
settings:
|
4
|
-
label: 'Settings'
|
4
|
+
label: 'Settings'
|
5
|
+
no_ckeditor_detected: CKEditor not found — showing as text input
|
6
|
+
phone_invalid: Incorrect phone
|
7
|
+
email_invalid: Incorrect email
|
8
|
+
yaml_invalid: Incorrect YAML
|
9
|
+
mongoid:
|
10
|
+
models:
|
11
|
+
rails_admin_settings/setting: Settings
|
12
|
+
|
13
|
+
attributes:
|
14
|
+
rails_admin_settings/setting:
|
15
|
+
key: Key
|
16
|
+
raw: Value
|
17
|
+
type: Type
|
18
|
+
|
data/lib/rails_admin_settings.rb
CHANGED
@@ -5,7 +5,6 @@ module RailsAdminSettings
|
|
5
5
|
autoload :Validation, "rails_admin_settings/validation"
|
6
6
|
autoload :RequireHelpers, "rails_admin_settings/require_helpers"
|
7
7
|
autoload :RailsAdminConfig, "rails_admin_settings/rails_admin_config"
|
8
|
-
autoload :Setting, "rails_admin_settings/setting"
|
9
8
|
end
|
10
9
|
|
11
10
|
require "rails_admin_settings/types"
|
@@ -13,4 +12,6 @@ require "rails_admin_settings/settings"
|
|
13
12
|
|
14
13
|
if Object.const_defined?('Rails')
|
15
14
|
require "rails_admin_settings/engine"
|
15
|
+
else
|
16
|
+
require File.dirname(__FILE__) + '/../app/models/rails_admin_settings/setting.rb'
|
16
17
|
end
|
@@ -1,38 +1,42 @@
|
|
1
1
|
module RailsAdminSettings
|
2
2
|
module RailsAdminConfig
|
3
3
|
def self.included(base)
|
4
|
-
base.rails_admin
|
5
|
-
|
4
|
+
if base.respond_to?(:rails_admin)
|
5
|
+
base.rails_admin do
|
6
|
+
navigation_label I18n.t('admin.settings.label')
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
list do
|
12
|
-
if Object.const_defined?('RailsAdminToggleable')
|
13
|
-
field :enabled, :toggle
|
14
|
-
else
|
15
|
-
field :enabled
|
8
|
+
object_label_method do
|
9
|
+
:key
|
16
10
|
end
|
17
11
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
12
|
+
list do
|
13
|
+
if Object.const_defined?('RailsAdminToggleable')
|
14
|
+
field :enabled, :toggle
|
15
|
+
else
|
16
|
+
field :enabled
|
17
|
+
end
|
18
|
+
field :key
|
19
|
+
field :raw
|
20
|
+
field :type
|
27
21
|
end
|
28
22
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
23
|
+
edit do
|
24
|
+
field :enabled
|
25
|
+
field :key do
|
26
|
+
read_only true
|
27
|
+
help false
|
28
|
+
end
|
29
|
+
field :type do
|
30
|
+
read_only true
|
31
|
+
help false
|
32
|
+
end
|
33
|
+
field :raw do
|
34
|
+
partial "setting_value"
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
38
|
+
else
|
39
|
+
puts "[rails_admin_settings] Problem: model does not respond to rails_admin: this should not happen"
|
36
40
|
end
|
37
41
|
end
|
38
42
|
end
|
@@ -3,6 +3,9 @@ class Settings
|
|
3
3
|
def load!
|
4
4
|
unless @@loaded
|
5
5
|
@@settings = {}
|
6
|
+
RailsAdminSettings::Setting.all.each do |setting|
|
7
|
+
@@settings[setting.key] = setting
|
8
|
+
end
|
6
9
|
@@loaded = true
|
7
10
|
end
|
8
11
|
end
|
@@ -86,7 +89,7 @@ class Settings
|
|
86
89
|
load!
|
87
90
|
options.symbolize_keys!
|
88
91
|
options[:raw] = options.delete(:default)
|
89
|
-
@@settings[key] = RailsAdminSettings::Setting.create(options.merge(key: key)) if @@settings[key].nil?
|
92
|
+
@@settings[key] = RailsAdminSettings::Setting.create!(options.merge(key: key)) if @@settings[key].nil?
|
90
93
|
end
|
91
94
|
|
92
95
|
# to satisfy rspec
|
@@ -11,7 +11,7 @@ module RailsAdminSettings
|
|
11
11
|
|
12
12
|
base.validate if: :phone_type? do
|
13
13
|
require_russian_phone do
|
14
|
-
errors.add(:raw, I18n.t('admin.settings.phone_invalid')) unless raw.blank? || RussianPhone::Number.new(
|
14
|
+
errors.add(:raw, I18n.t('admin.settings.phone_invalid')) unless raw.blank? || RussianPhone::Number.new(raw).valid?
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
data/spec/settings_spec.rb
CHANGED
@@ -29,6 +29,18 @@ describe Settings do
|
|
29
29
|
Settings.loaded.should eq false
|
30
30
|
end
|
31
31
|
|
32
|
+
it 'should properly store settings to DB' do
|
33
|
+
Settings.class_eval { cattr_accessor :loaded }
|
34
|
+
Settings.unload!
|
35
|
+
Settings.loaded.should eq false
|
36
|
+
Settings.temp = '123'
|
37
|
+
Settings.loaded.should eq true
|
38
|
+
Settings.unload!
|
39
|
+
Settings.loaded.should eq false
|
40
|
+
Settings.temp.should eq '123'
|
41
|
+
Settings.loaded.should eq true
|
42
|
+
end
|
43
|
+
|
32
44
|
it 'should support yaml type' do
|
33
45
|
Settings.tdata(type: 'yaml')
|
34
46
|
Settings.tdata = ['one', 'two', 'three']
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_admin_settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|
@@ -202,6 +202,7 @@ files:
|
|
202
202
|
- LICENSE.txt
|
203
203
|
- README.md
|
204
204
|
- Rakefile
|
205
|
+
- app/models/rails_admin_settings/setting.rb
|
205
206
|
- app/views/rails_admin/main/_setting_value.html.haml
|
206
207
|
- config/locales/en.rails_admin_settings.yml
|
207
208
|
- config/locales/ru.rails_admin_settings.yml
|
@@ -210,7 +211,6 @@ files:
|
|
210
211
|
- lib/rails_admin_settings/processing.rb
|
211
212
|
- lib/rails_admin_settings/rails_admin_config.rb
|
212
213
|
- lib/rails_admin_settings/require_helpers.rb
|
213
|
-
- lib/rails_admin_settings/setting.rb
|
214
214
|
- lib/rails_admin_settings/settings.rb
|
215
215
|
- lib/rails_admin_settings/types.rb
|
216
216
|
- lib/rails_admin_settings/validation.rb
|
@@ -239,7 +239,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
239
239
|
version: '0'
|
240
240
|
segments:
|
241
241
|
- 0
|
242
|
-
hash:
|
242
|
+
hash: -2625523890821583171
|
243
243
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
244
244
|
none: false
|
245
245
|
requirements:
|
@@ -248,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
248
248
|
version: '0'
|
249
249
|
segments:
|
250
250
|
- 0
|
251
|
-
hash:
|
251
|
+
hash: -2625523890821583171
|
252
252
|
requirements: []
|
253
253
|
rubyforge_project:
|
254
254
|
rubygems_version: 1.8.25
|