rails_admin_settings 0.8.0 → 0.9.0.pre
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/.ruby-version +1 -2
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +173 -22
- data/README.md +20 -5
- data/app/models/rails_admin_settings/setting.rb +19 -16
- data/lib/generators/rails_admin_settings/migration_generator.rb +15 -0
- data/lib/generators/rails_admin_settings/templates/migration.rb +26 -0
- data/lib/rails_admin_settings/engine.rb +4 -2
- data/lib/rails_admin_settings/{types.rb → kinds.rb} +5 -1
- data/lib/rails_admin_settings/mongoid.rb +19 -0
- data/lib/rails_admin_settings/namespaced.rb +8 -3
- data/lib/rails_admin_settings/processing.rb +33 -27
- data/lib/rails_admin_settings/rails_admin_config.rb +6 -6
- data/lib/rails_admin_settings/require_helpers.rb +3 -3
- data/lib/rails_admin_settings/settings.rb +7 -0
- data/lib/rails_admin_settings/uploads.rb +13 -3
- data/lib/rails_admin_settings/validation.rb +19 -17
- data/lib/rails_admin_settings/version.rb +2 -1
- data/lib/rails_admin_settings.rb +54 -4
- data/rails_admin_settings.gemspec +4 -3
- data/spec/carrierwave_spec.rb +4 -4
- data/spec/defaults_spec.rb +3 -3
- data/spec/migration_spec.rb +15 -0
- data/spec/model_spec.rb +3 -3
- data/spec/namespaced_spec.rb +5 -5
- data/spec/paperclip_spec.rb +4 -4
- data/spec/settings_spec.rb +7 -7
- data/spec/spec_helper.rb +5 -1
- data/spec/support/defaults.yml +2 -2
- data/spec/support/defaults_w_file.yml +3 -3
- data/spec/types_spec.rb +20 -20
- metadata +27 -9
- data/lib/rails_admin_settings/railtie.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77ff229c1b71b0265ce4d23d2da8853c6cbb9203
|
4
|
+
data.tar.gz: d86ab6c49fefb97a5582a1b7d1c13c2c6d568f66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31ea6d4cad521443024a0572e8cb3b10b7488d4afe9e5bb3da691aa31d9b0034f6282891af3e9928d046aa69b20432ac6ba47ca8e4e0d9fd2f1100aa326437bf
|
7
|
+
data.tar.gz: c1d935b38d5564e0cf5514b8180807f5adbe27adcf95c5a76649c2f8f8c764c89eb509f96422b1306c801fcbab719fdac8f23b544e67397d68abc61c0d16fe48
|
data/.ruby-version
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
2.1.
|
2
|
-
|
1
|
+
2.1.3
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,19 +1,40 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rails_admin_settings (0.
|
5
|
-
mongoid (>= 3.0, < 4.1)
|
4
|
+
rails_admin_settings (0.9.0.pre)
|
6
5
|
|
7
6
|
GEM
|
8
7
|
remote: https://rubygems.org/
|
9
8
|
specs:
|
9
|
+
actionmailer (3.2.19)
|
10
|
+
actionpack (= 3.2.19)
|
11
|
+
mail (~> 2.5.4)
|
12
|
+
actionpack (3.2.19)
|
13
|
+
activemodel (= 3.2.19)
|
14
|
+
activesupport (= 3.2.19)
|
15
|
+
builder (~> 3.0.0)
|
16
|
+
erubis (~> 2.7.0)
|
17
|
+
journey (~> 1.0.4)
|
18
|
+
rack (~> 1.4.5)
|
19
|
+
rack-cache (~> 1.2)
|
20
|
+
rack-test (~> 0.6.1)
|
21
|
+
sprockets (~> 2.2.1)
|
10
22
|
activemodel (3.2.19)
|
11
23
|
activesupport (= 3.2.19)
|
12
24
|
builder (~> 3.0.0)
|
25
|
+
activerecord (3.2.19)
|
26
|
+
activemodel (= 3.2.19)
|
27
|
+
activesupport (= 3.2.19)
|
28
|
+
arel (~> 3.0.2)
|
29
|
+
tzinfo (~> 0.3.29)
|
30
|
+
activeresource (3.2.19)
|
31
|
+
activemodel (= 3.2.19)
|
32
|
+
activesupport (= 3.2.19)
|
13
33
|
activesupport (3.2.19)
|
14
34
|
i18n (~> 0.6, >= 0.6.4)
|
15
35
|
multi_json (~> 1.0)
|
16
36
|
addressable (2.3.6)
|
37
|
+
arel (3.0.3)
|
17
38
|
builder (3.0.4)
|
18
39
|
carrierwave (0.10.0)
|
19
40
|
activemodel (>= 3.2.0)
|
@@ -29,19 +50,25 @@ GEM
|
|
29
50
|
database_cleaner (1.3.0)
|
30
51
|
diff-lcs (1.2.5)
|
31
52
|
docile (1.1.5)
|
53
|
+
erubis (2.7.0)
|
32
54
|
factory_girl (4.4.0)
|
33
55
|
activesupport (>= 3.0.0)
|
34
|
-
geocoder (1.2.
|
56
|
+
geocoder (1.2.5)
|
35
57
|
glebtv-carrierwave-mongoid (0.8.0)
|
36
58
|
carrierwave (>= 0.8.0, < 0.11.0)
|
37
59
|
mongoid (>= 3.0, < 5.0)
|
38
60
|
glebtv-mongoid-paperclip (0.2.4)
|
39
61
|
mongoid (>= 3.0, < 5.0)
|
40
62
|
paperclip (>= 2.3.6)
|
63
|
+
hike (1.2.3)
|
41
64
|
i18n (0.6.11)
|
65
|
+
journey (1.0.4)
|
42
66
|
json (1.8.1)
|
67
|
+
mail (2.5.4)
|
68
|
+
mime-types (~> 1.16)
|
69
|
+
treetop (~> 1.4.8)
|
43
70
|
method_source (0.8.2)
|
44
|
-
mime-types (
|
71
|
+
mime-types (1.25.1)
|
45
72
|
mini_portile (0.6.0)
|
46
73
|
mongoid (3.1.6)
|
47
74
|
activemodel (~> 3.2)
|
@@ -56,7 +83,7 @@ GEM
|
|
56
83
|
multi_json (1.10.1)
|
57
84
|
nokogiri (1.6.3.1)
|
58
85
|
mini_portile (= 0.6.0)
|
59
|
-
nokogumbo (1.1.
|
86
|
+
nokogumbo (1.1.12)
|
60
87
|
nokogiri
|
61
88
|
origin (1.1.0)
|
62
89
|
paperclip (4.2.0)
|
@@ -64,38 +91,160 @@ GEM
|
|
64
91
|
activesupport (>= 3.0.0)
|
65
92
|
cocaine (~> 0.5.3)
|
66
93
|
mime-types
|
67
|
-
|
94
|
+
polyglot (0.3.5)
|
95
|
+
pry (0.10.1)
|
68
96
|
coderay (~> 1.1.0)
|
69
97
|
method_source (~> 0.8.1)
|
70
98
|
slop (~> 3.4)
|
99
|
+
rack (1.4.5)
|
100
|
+
rack-cache (1.2)
|
101
|
+
rack (>= 0.4)
|
102
|
+
rack-ssl (1.3.4)
|
103
|
+
rack
|
104
|
+
rack-test (0.6.2)
|
105
|
+
rack (>= 1.0)
|
106
|
+
rails (3.2.19)
|
107
|
+
actionmailer (= 3.2.19)
|
108
|
+
actionpack (= 3.2.19)
|
109
|
+
activerecord (= 3.2.19)
|
110
|
+
activeresource (= 3.2.19)
|
111
|
+
activesupport (= 3.2.19)
|
112
|
+
bundler (~> 1.0)
|
113
|
+
railties (= 3.2.19)
|
114
|
+
railties (3.2.19)
|
115
|
+
actionpack (= 3.2.19)
|
116
|
+
activesupport (= 3.2.19)
|
117
|
+
rack-ssl (~> 1.3.2)
|
118
|
+
rake (>= 0.8.7)
|
119
|
+
rdoc (~> 3.4)
|
120
|
+
thor (>= 0.14.6, < 2.0)
|
71
121
|
rake (10.3.2)
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
rspec-
|
76
|
-
|
77
|
-
rspec-
|
78
|
-
rspec-
|
122
|
+
rdoc (3.12.2)
|
123
|
+
json (~> 1.4)
|
124
|
+
rspec (3.1.0)
|
125
|
+
rspec-core (~> 3.1.0)
|
126
|
+
rspec-expectations (~> 3.1.0)
|
127
|
+
rspec-mocks (~> 3.1.0)
|
128
|
+
rspec-core (3.1.4)
|
129
|
+
rspec-support (~> 3.1.0)
|
130
|
+
rspec-expectations (3.1.1)
|
79
131
|
diff-lcs (>= 1.2.0, < 2.0)
|
80
|
-
rspec-support (~> 3.
|
81
|
-
rspec-mocks (3.
|
82
|
-
rspec-support (~> 3.
|
83
|
-
rspec-support (3.0
|
132
|
+
rspec-support (~> 3.1.0)
|
133
|
+
rspec-mocks (3.1.1)
|
134
|
+
rspec-support (~> 3.1.0)
|
135
|
+
rspec-support (3.1.0)
|
84
136
|
russian_phone (0.4.1)
|
85
137
|
mongoid (>= 3.0.0)
|
86
138
|
safe_yaml (1.0.3)
|
87
|
-
sanitize (3.0.
|
139
|
+
sanitize (3.0.2)
|
88
140
|
crass (~> 0.2.0)
|
89
141
|
nokogiri (>= 1.4.4)
|
90
|
-
nokogumbo (= 1.1.
|
91
|
-
simplecov (0.9.
|
142
|
+
nokogumbo (= 1.1.12)
|
143
|
+
simplecov (0.9.1)
|
92
144
|
docile (~> 1.1.0)
|
93
|
-
multi_json
|
145
|
+
multi_json (~> 1.0)
|
94
146
|
simplecov-html (~> 0.8.0)
|
95
147
|
simplecov-html (0.8.0)
|
96
148
|
slop (3.6.0)
|
149
|
+
sprockets (2.2.2)
|
150
|
+
hike (~> 1.2)
|
151
|
+
multi_json (~> 1.0)
|
152
|
+
rack (~> 1.0)
|
153
|
+
tilt (~> 1.1, != 1.3.0)
|
154
|
+
thor (0.19.1)
|
155
|
+
tilt (1.4.1)
|
156
|
+
treetop (1.4.15)
|
157
|
+
polyglot
|
158
|
+
polyglot
|
159
|
+
polyglot
|
160
|
+
polyglot
|
161
|
+
polyglot
|
162
|
+
polyglot
|
163
|
+
polyglot
|
164
|
+
polyglot
|
165
|
+
polyglot
|
166
|
+
polyglot
|
167
|
+
polyglot
|
168
|
+
polyglot
|
169
|
+
polyglot
|
170
|
+
polyglot
|
171
|
+
polyglot
|
172
|
+
polyglot
|
173
|
+
polyglot
|
174
|
+
polyglot (>= 0.3.1)
|
175
|
+
polyglot (>= 0.3.1)
|
176
|
+
polyglot (>= 0.3.1)
|
177
|
+
polyglot (>= 0.3.1)
|
178
|
+
polyglot (>= 0.3.1)
|
179
|
+
polyglot (>= 0.3.1)
|
180
|
+
polyglot (>= 0.3.1)
|
181
|
+
polyglot (>= 0.3.1)
|
182
|
+
polyglot (>= 0.3.1)
|
183
|
+
polyglot (>= 0.3.1)
|
184
|
+
polyglot (>= 0.3.1)
|
185
|
+
polyglot (>= 0.3.1)
|
186
|
+
polyglot (>= 0.3.1)
|
187
|
+
polyglot (>= 0.3.1)
|
188
|
+
polyglot (>= 0.3.1)
|
189
|
+
polyglot (>= 0.3.1)
|
190
|
+
polyglot (>= 0.3.1)
|
191
|
+
polyglot (>= 0.3.1)
|
192
|
+
polyglot (>= 0.3.1)
|
193
|
+
polyglot (>= 0.3.1)
|
194
|
+
polyglot (>= 0.3.1)
|
195
|
+
polyglot (>= 0.3.1)
|
196
|
+
polyglot (>= 0.3.1)
|
197
|
+
polyglot (>= 0.3.1)
|
198
|
+
polyglot (>= 0.3.1)
|
199
|
+
polyglot (>= 0.3.1)
|
200
|
+
polyglot (>= 0.3.1)
|
201
|
+
polyglot (>= 0.3.1)
|
202
|
+
polyglot (>= 0.3.1)
|
203
|
+
polyglot (>= 0.3.1)
|
204
|
+
polyglot (>= 0.3.1)
|
205
|
+
polyglot (>= 0.3.1)
|
206
|
+
polyglot (>= 0.3.1)
|
207
|
+
polyglot (>= 0.3.1)
|
208
|
+
polyglot (>= 0.3.1)
|
209
|
+
polyglot (>= 0.3.1)
|
210
|
+
polyglot (>= 0.3.1)
|
211
|
+
polyglot (>= 0.3.1)
|
212
|
+
polyglot (>= 0.3.1)
|
213
|
+
polyglot (>= 0.3.1)
|
214
|
+
polyglot (>= 0.3.1)
|
215
|
+
polyglot (>= 0.3.1)
|
216
|
+
polyglot (>= 0.3.1)
|
217
|
+
polyglot (>= 0.3.1)
|
218
|
+
polyglot (>= 0.3.1)
|
219
|
+
polyglot (>= 0.3.1)
|
220
|
+
polyglot (>= 0.3.1)
|
221
|
+
polyglot (>= 0.3.1)
|
222
|
+
polyglot (>= 0.3.1)
|
223
|
+
polyglot (>= 0.3.1)
|
224
|
+
polyglot (>= 0.3.1)
|
225
|
+
polyglot (>= 0.3.1)
|
226
|
+
polyglot (>= 0.3.1)
|
227
|
+
polyglot (>= 0.3.1)
|
228
|
+
polyglot (>= 0.3.1)
|
229
|
+
polyglot (>= 0.3.1)
|
230
|
+
polyglot (>= 0.3.1)
|
231
|
+
polyglot (>= 0.3.1)
|
232
|
+
polyglot (>= 0.3.1)
|
233
|
+
polyglot (>= 0.3.1)
|
234
|
+
polyglot (>= 0.3.1)
|
235
|
+
polyglot (>= 0.3.1)
|
236
|
+
polyglot (>= 0.3.1)
|
237
|
+
polyglot (>= 0.3.1)
|
238
|
+
polyglot (>= 0.3.1)
|
239
|
+
polyglot (>= 0.3.1)
|
240
|
+
polyglot (>= 0.3.1)
|
241
|
+
polyglot (>= 0.3.1)
|
242
|
+
polyglot (>= 0.3.1)
|
243
|
+
polyglot (>= 0.3.1)
|
244
|
+
polyglot (>= 0.3.1)
|
97
245
|
tzinfo (0.3.41)
|
98
|
-
validates_email_format_of (1.
|
246
|
+
validates_email_format_of (1.6.1)
|
247
|
+
i18n
|
99
248
|
|
100
249
|
PLATFORMS
|
101
250
|
ruby
|
@@ -108,8 +257,10 @@ DEPENDENCIES
|
|
108
257
|
geocoder
|
109
258
|
glebtv-carrierwave-mongoid
|
110
259
|
glebtv-mongoid-paperclip
|
260
|
+
mongoid (>= 3.0, < 4.1)
|
111
261
|
mongoid-rspec
|
112
262
|
pry
|
263
|
+
rails
|
113
264
|
rails_admin_settings!
|
114
265
|
rake
|
115
266
|
rspec
|
data/README.md
CHANGED
@@ -7,12 +7,19 @@ Note: This gem currently supports Mongoid 3/4 only, as I don't need AR support.
|
|
7
7
|
|
8
8
|
Pull request with AR support will be welcome
|
9
9
|
|
10
|
+
## 0.9.0 is not backwards-compatible with 0.8
|
11
|
+
|
12
|
+
Type renamed to Kind to avoid messing with AR STI column
|
13
|
+
Column should be renamed automatically upon first app startup with new gem version.
|
14
|
+
|
15
|
+
Also, active record is now supported in addition to mongoid.
|
16
|
+
|
10
17
|
## Features
|
11
18
|
|
12
19
|
- Lazy loading - loads settings only if they are needed during request
|
13
20
|
- Loads all settings at once and caches them for the duration of request
|
14
|
-
- Supports lots of setting
|
15
|
-
- Each setting can be enabled and disabled within rails_admin, if it's disabled it returns default value for
|
21
|
+
- Supports lots of setting kinds - yaml, html with ckeditor, phone numbers etc
|
22
|
+
- Each setting can be enabled and disabled within rails_admin, if it's disabled it returns default value for kind
|
16
23
|
|
17
24
|
## Installation
|
18
25
|
|
@@ -20,6 +27,14 @@ Add this line to your application's Gemfile:
|
|
20
27
|
|
21
28
|
gem 'rails_admin_settings'
|
22
29
|
|
30
|
+
For activerecord, generage migration:
|
31
|
+
|
32
|
+
rails g rails_admin_settings:migration
|
33
|
+
|
34
|
+
Then migrate:
|
35
|
+
|
36
|
+
rake db:migrate
|
37
|
+
|
23
38
|
## Gemfile order matters
|
24
39
|
|
25
40
|
- Put it after rails_admin to get built-in support
|
@@ -49,11 +64,11 @@ Or install it yourself as:
|
|
49
64
|
|
50
65
|
## Advanced Usage
|
51
66
|
|
52
|
-
Settings.content_block_1(
|
53
|
-
Settings.data(
|
67
|
+
Settings.content_block_1(kind: 'html', default: 'test')
|
68
|
+
Settings.data(kind: 'yaml')
|
54
69
|
Settings.data = [1, 2, 3]
|
55
70
|
|
56
|
-
Settings.enabled?(:phone,
|
71
|
+
Settings.enabled?(:phone, kind: 'phone', default: '906 111-11-11') # also creates setting if it doesn't exist
|
57
72
|
Settings.phone.area
|
58
73
|
Settings.phone.subscriber
|
59
74
|
|
@@ -1,23 +1,22 @@
|
|
1
|
-
|
1
|
+
if RailsAdminSettings.active_record?
|
2
|
+
module RailsAdminSettings
|
3
|
+
class Setting < ActiveRecord::Base
|
4
|
+
end
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
2
8
|
module RailsAdminSettings
|
3
9
|
class Setting
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
field :enabled, type: Mongoid::VERSION.to_i < 4 ? Boolean : Mongoid::Boolean, default: true
|
10
|
-
scope :enabled, -> { where(enabled: true) }
|
11
|
-
|
12
|
-
field :type, type: String, default: RailsAdminSettings.types.first
|
13
|
-
|
14
|
-
field :ns, type: String, default: 'main'
|
15
|
-
field :key, type: String
|
16
|
-
index({ns: 1, key: 1}, {unique: true, sparse: true})
|
10
|
+
#binding.pry
|
11
|
+
if RailsAdminSettings.mongoid?
|
12
|
+
include RailsAdminSettings::Mongoid
|
13
|
+
end
|
17
14
|
|
18
|
-
|
19
|
-
|
15
|
+
if RailsAdminSettings.active_record?
|
16
|
+
self.table_name = "rails_admin_settings"
|
17
|
+
end
|
20
18
|
|
19
|
+
scope :enabled, -> { where(enabled: true) }
|
21
20
|
scope :ns, ->(ns) { where(ns: ns) }
|
22
21
|
|
23
22
|
include RailsAdminSettings::RequireHelpers
|
@@ -37,6 +36,10 @@ module RailsAdminSettings
|
|
37
36
|
label.blank? ? key : label
|
38
37
|
end
|
39
38
|
|
39
|
+
def type
|
40
|
+
kind
|
41
|
+
end
|
42
|
+
|
40
43
|
def to_path
|
41
44
|
if value.nil?
|
42
45
|
nil
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/active_record'
|
3
|
+
|
4
|
+
module RailsAdminSettings
|
5
|
+
class MigrationGenerator < Rails::Generators::Base
|
6
|
+
include ActiveRecord::Generators::Migration
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
|
9
|
+
desc 'RocketCMS migration generator'
|
10
|
+
def install
|
11
|
+
migration_template "migration.rb", "db/migrate/create_rails_admin_settings.rb"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class CreateRailsAdminSettings < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :rails_admin_settings do |t|
|
4
|
+
t.boolean :enabled, default: true
|
5
|
+
t.string :type, null: false, default: 'string'
|
6
|
+
t.string :ns, default: 'main'
|
7
|
+
t.string :key, null: false
|
8
|
+
if Object.const_defined?('Geocoder')
|
9
|
+
t.float :latitude
|
10
|
+
t.float :longitude
|
11
|
+
end
|
12
|
+
t.text :raw
|
13
|
+
t.string :label
|
14
|
+
if defined?(Paperclip)
|
15
|
+
t.attachment :file
|
16
|
+
elsif defined?(CarrierWave)
|
17
|
+
t.string :file
|
18
|
+
end
|
19
|
+
t.timestamps
|
20
|
+
end
|
21
|
+
|
22
|
+
add_index :rails_admin_settings, :key
|
23
|
+
add_index :rails_admin_settings, [:ns, :key], unique: true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -1,5 +1,9 @@
|
|
1
1
|
module RailsAdminSettings
|
2
2
|
class Engine < ::Rails::Engine
|
3
|
+
rake_tasks do
|
4
|
+
require File.expand_path('../tasks', __FILE__)
|
5
|
+
end
|
6
|
+
|
3
7
|
initializer 'RailsAdminSettings Install after_filter' do |app|
|
4
8
|
require File.dirname(__FILE__) + '/../../app/models/rails_admin_settings/setting.rb'
|
5
9
|
|
@@ -8,8 +12,6 @@ module RailsAdminSettings
|
|
8
12
|
after_filter { Settings.unload! }
|
9
13
|
end
|
10
14
|
end
|
11
|
-
|
12
|
-
RailsAdminSettings::Setting.where(:ns.exists => false).update_all(ns: 'main')
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module RailsAdminSettings
|
2
|
+
module Mongoid
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
included do
|
5
|
+
include ::Mongoid::Document
|
6
|
+
include ::Mongoid::Timestamps::Short
|
7
|
+
|
8
|
+
store_in collection: "rails_admin_settings"
|
9
|
+
field :enabled, type: ::Mongoid::VERSION.to_i < 4 ? Boolean : ::Mongoid::Boolean, default: true
|
10
|
+
field :kind, type: String, default: RailsAdminSettings.types.first
|
11
|
+
field :ns, type: String, default: 'main'
|
12
|
+
field :key, type: String
|
13
|
+
field :raw, type: String
|
14
|
+
field :label, type: String
|
15
|
+
index({ns: 1, key: 1}, {unique: true, sparse: true})
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -133,10 +133,15 @@ module RailsAdminSettings
|
|
133
133
|
elsif key.end_with?('_enabled=')
|
134
134
|
key = key[0..-10]
|
135
135
|
v = get(key)
|
136
|
-
if ::
|
137
|
-
|
136
|
+
if ::RailsAdminSettings.mongoid?
|
137
|
+
if ::Mongoid::VERSION >= "4.0.0"
|
138
|
+
v.set(enabled: args.first)
|
139
|
+
else
|
140
|
+
v.set("enabled", args.first)
|
141
|
+
end
|
138
142
|
else
|
139
|
-
v.
|
143
|
+
v.enabled = args.first
|
144
|
+
v.save!
|
140
145
|
end
|
141
146
|
v.enabled
|
142
147
|
elsif key.end_with?('=')
|
@@ -1,25 +1,31 @@
|
|
1
1
|
module RailsAdminSettings
|
2
2
|
module Processing
|
3
|
-
RailsAdminSettings.
|
4
|
-
define_method "#{
|
5
|
-
|
3
|
+
RailsAdminSettings.kinds.each do |dkind|
|
4
|
+
define_method "#{dkind}_kind?" do
|
5
|
+
dkind == kind
|
6
|
+
end
|
7
|
+
define_method "#{dkind}_type?" do
|
8
|
+
dkind == kind
|
6
9
|
end
|
7
10
|
end
|
8
11
|
|
9
|
-
def
|
10
|
-
(RailsAdminSettings.
|
12
|
+
def text_kind?
|
13
|
+
(RailsAdminSettings.kinds - ['phone', 'phones', 'integer', 'yaml']).include? kind
|
11
14
|
end
|
12
15
|
|
13
|
-
def
|
14
|
-
['file', 'image'].include?
|
16
|
+
def upload_kind?
|
17
|
+
['file', 'image'].include? kind
|
15
18
|
end
|
16
19
|
|
17
|
-
def
|
18
|
-
['html', 'sanitized'].include?
|
20
|
+
def html_kind?
|
21
|
+
['html', 'sanitized'].include? kind
|
19
22
|
end
|
23
|
+
alias_method :text_type?, :text_kind?
|
24
|
+
alias_method :upload_type?, :upload_kind?
|
25
|
+
alias_method :html_type?, :html_kind?
|
20
26
|
|
21
27
|
def value
|
22
|
-
if
|
28
|
+
if upload_kind?
|
23
29
|
if file?
|
24
30
|
file.url
|
25
31
|
else
|
@@ -33,7 +39,7 @@ module RailsAdminSettings
|
|
33
39
|
end
|
34
40
|
|
35
41
|
def blank?
|
36
|
-
if
|
42
|
+
if file_kind?
|
37
43
|
file.url.nil?
|
38
44
|
elsif raw.blank? || disabled?
|
39
45
|
true
|
@@ -43,7 +49,7 @@ module RailsAdminSettings
|
|
43
49
|
end
|
44
50
|
|
45
51
|
def to_s
|
46
|
-
if
|
52
|
+
if yaml_kind? || phone_kind? || integer_kind?
|
47
53
|
raw
|
48
54
|
else
|
49
55
|
value
|
@@ -59,19 +65,19 @@ module RailsAdminSettings
|
|
59
65
|
end
|
60
66
|
|
61
67
|
def default_value
|
62
|
-
if
|
68
|
+
if html_kind?
|
63
69
|
''.html_safe
|
64
|
-
elsif
|
70
|
+
elsif text_kind?
|
65
71
|
''
|
66
|
-
elsif
|
72
|
+
elsif integer_kind?
|
67
73
|
0
|
68
|
-
elsif
|
74
|
+
elsif yaml_kind?
|
69
75
|
nil
|
70
|
-
elsif
|
76
|
+
elsif phone_kind?
|
71
77
|
require_russian_phone do
|
72
78
|
RussianPhone::Number.new('')
|
73
79
|
end
|
74
|
-
elsif
|
80
|
+
elsif phones_kind?
|
75
81
|
[]
|
76
82
|
else
|
77
83
|
nil
|
@@ -79,7 +85,7 @@ module RailsAdminSettings
|
|
79
85
|
end
|
80
86
|
|
81
87
|
def default_serializable_value
|
82
|
-
if
|
88
|
+
if phones_kind?
|
83
89
|
''
|
84
90
|
else
|
85
91
|
default_value
|
@@ -96,7 +102,7 @@ module RailsAdminSettings
|
|
96
102
|
"#{$1}-#{Time.now.strftime('%Y')}"
|
97
103
|
end
|
98
104
|
end
|
99
|
-
text = text.html_safe if
|
105
|
+
text = text.html_safe if html_kind?
|
100
106
|
text
|
101
107
|
end
|
102
108
|
|
@@ -119,20 +125,20 @@ module RailsAdminSettings
|
|
119
125
|
end
|
120
126
|
|
121
127
|
def processed_value
|
122
|
-
if
|
128
|
+
if text_kind?
|
123
129
|
process_text
|
124
|
-
elsif
|
130
|
+
elsif integer_kind?
|
125
131
|
raw.to_i
|
126
|
-
elsif
|
132
|
+
elsif yaml_kind?
|
127
133
|
load_yaml
|
128
|
-
elsif
|
134
|
+
elsif phone_kind?
|
129
135
|
load_phone
|
130
|
-
elsif
|
136
|
+
elsif phones_kind?
|
131
137
|
load_phones
|
132
|
-
elsif
|
138
|
+
elsif file_kind?
|
133
139
|
file.url
|
134
140
|
else
|
135
|
-
puts "[rails_admin_settings] Unknown field
|
141
|
+
puts "[rails_admin_settings] Unknown field kind: #{kind}"
|
136
142
|
nil
|
137
143
|
end
|
138
144
|
end
|
@@ -11,14 +11,14 @@ module RailsAdminSettings
|
|
11
11
|
else
|
12
12
|
field :enabled
|
13
13
|
end
|
14
|
-
field :
|
14
|
+
field :kind
|
15
15
|
field :ns
|
16
16
|
field :name
|
17
17
|
field :raw do
|
18
18
|
pretty_value do
|
19
|
-
if bindings[:object].
|
19
|
+
if bindings[:object].file_kind?
|
20
20
|
"<a href='#{CGI::escapeHTML(bindings[:object].file.url)}'>#{CGI::escapeHTML(bindings[:object].to_path)}</a>".html_safe
|
21
|
-
elsif bindings[:object].
|
21
|
+
elsif bindings[:object].image_kind?
|
22
22
|
"<a href='#{CGI::escapeHTML(bindings[:object].file.url)}'><img src='#{CGI::escapeHTML(bindings[:object].file.url)}' /></a>".html_safe
|
23
23
|
else
|
24
24
|
value
|
@@ -33,20 +33,20 @@ module RailsAdminSettings
|
|
33
33
|
read_only true
|
34
34
|
help false
|
35
35
|
end
|
36
|
-
field :
|
36
|
+
field :kind do
|
37
37
|
read_only true
|
38
38
|
help false
|
39
39
|
end
|
40
40
|
field :raw do
|
41
41
|
partial "setting_value"
|
42
42
|
visible do
|
43
|
-
!bindings[:object].
|
43
|
+
!bindings[:object].upload_kind?
|
44
44
|
end
|
45
45
|
end
|
46
46
|
if Settings.file_uploads_supported
|
47
47
|
field :file, Settings.file_uploads_engine do
|
48
48
|
visible do
|
49
|
-
bindings[:object].
|
49
|
+
bindings[:object].upload_kind?
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|