ack_rails_admin_settings 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +17 -0
- data/CHANGELOG.md +53 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +192 -0
- data/LICENSE.txt +22 -0
- data/README.md +133 -0
- data/Rakefile +9 -0
- data/app/models/rails_admin_settings/setting.rb +78 -0
- data/app/views/rails_admin/main/_setting_value.html.haml +104 -0
- data/config/locales/en.yml +28 -0
- data/config/locales/ru.yml +28 -0
- data/gemfiles/mongoid-3.1.gemfile +5 -0
- data/gemfiles/mongoid-4.0.gemfile +5 -0
- data/lib/ack_rails_admin_settings.rb +1 -0
- 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/dumper.rb +12 -0
- data/lib/rails_admin_settings/engine.rb +17 -0
- data/lib/rails_admin_settings/fallback.rb +21 -0
- data/lib/rails_admin_settings/hex_color_validator.rb +11 -0
- data/lib/rails_admin_settings/kinds.rb +30 -0
- data/lib/rails_admin_settings/mongoid.rb +31 -0
- data/lib/rails_admin_settings/namespaced.rb +218 -0
- data/lib/rails_admin_settings/processing.rb +159 -0
- data/lib/rails_admin_settings/rails_admin_config.rb +74 -0
- data/lib/rails_admin_settings/require_helpers.rb +65 -0
- data/lib/rails_admin_settings/settings.rb +113 -0
- data/lib/rails_admin_settings/storage/carrierwave.rb +9 -0
- data/lib/rails_admin_settings/tasks.rb +35 -0
- data/lib/rails_admin_settings/uploads.rb +45 -0
- data/lib/rails_admin_settings/validation.rb +84 -0
- data/lib/rails_admin_settings/version.rb +3 -0
- data/lib/rails_admin_settings.rb +81 -0
- data/rails_admin_settings.gemspec +40 -0
- data/release.sh +6 -0
- data/spec/advanced_usage_spec.rb +11 -0
- data/spec/carrierwave_spec.rb +41 -0
- data/spec/database_trickery_spec.rb +48 -0
- data/spec/defaults_spec.rb +87 -0
- data/spec/enabling_spec.rb +29 -0
- data/spec/factories/setting.rb +8 -0
- data/spec/label_spec.rb +18 -0
- data/spec/migration_spec.rb +15 -0
- data/spec/model_spec.rb +45 -0
- data/spec/namespaced_spec.rb +67 -0
- data/spec/paperclip_spec.rb +39 -0
- data/spec/settings_spec.rb +75 -0
- data/spec/spec_helper.rb +42 -0
- data/spec/support/1024x768.gif +0 -0
- data/spec/support/database_cleaner.rb +10 -0
- data/spec/support/defaults.yml +23 -0
- data/spec/support/defaults_w_file.yml +19 -0
- data/spec/support/mongoid.rb +6 -0
- data/spec/support/mongoid.yml +6 -0
- data/spec/types_spec.rb +88 -0
- metadata +383 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3d087838734945c883c25cc53738e4722d73851c
|
4
|
+
data.tar.gz: 36b4b5de1c9d4f3e0309d1de9945836465c3791b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cad7bce8c0a6f37e7f7ec8ab0be59514f7f82f0b579c5d1bf8401b3c678404abac9808958ec7058705401a2d03c640c3681f81c52ebf50f2ef449d4724ceb0c6
|
7
|
+
data.tar.gz: 3a681269e2b9f5519928462276a2129bc97ab5a075168bfae8a17b91f5795b2f4ae1dcff9e5a56e42ec8202839d6d2601e764ff3380df346440cddf9f723a15d
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ack_rails_admin_settings
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.1
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
## 1.1.3
|
2
|
+
|
3
|
+
- Fix for namespace tabs when database table does not exist yet.
|
4
|
+
|
5
|
+
## 1.1.2
|
6
|
+
|
7
|
+
- Add namespace tabs in rails_admin
|
8
|
+
- Add code type with codemirror (requires glebtv-ckeditor)
|
9
|
+
- Fixed Paperclip installation checking #6. Thx @tanelj
|
10
|
+
- Add boolean data type #2. Thx @teonimesic
|
11
|
+
|
12
|
+
## 1.1.0
|
13
|
+
|
14
|
+
- Fix file type
|
15
|
+
|
16
|
+
## 1.0.0
|
17
|
+
|
18
|
+
- Support ActiveRecord
|
19
|
+
|
20
|
+
## 1.0.0.pre.1
|
21
|
+
|
22
|
+
Disable auto migrate. To migrate from 0.8 run:
|
23
|
+
|
24
|
+
```
|
25
|
+
RailsAdminSettings.migrate!
|
26
|
+
```
|
27
|
+
|
28
|
+
## 0.9.1
|
29
|
+
|
30
|
+
Settings.ns(ns) now defaults to fallback to Settings.ns_fallback
|
31
|
+
If you want an NS without fallback, specify nil:
|
32
|
+
Settings.ns(ns, fallback: nil)
|
33
|
+
|
34
|
+
## 0.9.0
|
35
|
+
|
36
|
+
- Added ActiveRecord support
|
37
|
+
- [!!!] Type renamed to Kind to avoid messing with AR STI column
|
38
|
+
|
39
|
+
Rename it in all invocations, then run migrate DB with:
|
40
|
+
|
41
|
+
RailsAdminSettings.migrate!
|
42
|
+
|
43
|
+
## 0.6.0
|
44
|
+
|
45
|
+
- Added namespaced settings
|
46
|
+
- Added loading of default settings from config/settings.yml
|
47
|
+
- Settings.label(key) is removed
|
48
|
+
- Added Settings.apply_defaults! to load settings from yml file without
|
49
|
+
overwriting current settings.
|
50
|
+
*note*: If setting type is changed and old value does not pass validation for
|
51
|
+
new type, value will be reset to nil.
|
52
|
+
- Added rake settings:save_defaults to dump current settings to
|
53
|
+
config/defaults.yml
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ack_rails_admin_settings (1.1.4)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
actionmailer (3.2.22.4)
|
10
|
+
actionpack (= 3.2.22.4)
|
11
|
+
mail (~> 2.5.4)
|
12
|
+
actionpack (3.2.22.4)
|
13
|
+
activemodel (= 3.2.22.4)
|
14
|
+
activesupport (= 3.2.22.4)
|
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)
|
22
|
+
activemodel (3.2.22.4)
|
23
|
+
activesupport (= 3.2.22.4)
|
24
|
+
builder (~> 3.0.0)
|
25
|
+
activerecord (3.2.22.4)
|
26
|
+
activemodel (= 3.2.22.4)
|
27
|
+
activesupport (= 3.2.22.4)
|
28
|
+
arel (~> 3.0.2)
|
29
|
+
tzinfo (~> 0.3.29)
|
30
|
+
activeresource (3.2.22.4)
|
31
|
+
activemodel (= 3.2.22.4)
|
32
|
+
activesupport (= 3.2.22.4)
|
33
|
+
activesupport (3.2.22.4)
|
34
|
+
i18n (~> 0.6, >= 0.6.4)
|
35
|
+
multi_json (~> 1.0)
|
36
|
+
addressable (2.4.0)
|
37
|
+
arel (3.0.3)
|
38
|
+
builder (3.0.4)
|
39
|
+
carrierwave (0.10.0)
|
40
|
+
activemodel (>= 3.2.0)
|
41
|
+
activesupport (>= 3.2.0)
|
42
|
+
json (>= 1.7)
|
43
|
+
mime-types (>= 1.16)
|
44
|
+
climate_control (0.0.3)
|
45
|
+
activesupport (>= 3.0)
|
46
|
+
cocaine (0.5.8)
|
47
|
+
climate_control (>= 0.0.3, < 1.0)
|
48
|
+
coderay (1.1.1)
|
49
|
+
crass (1.0.2)
|
50
|
+
database_cleaner (1.5.3)
|
51
|
+
diff-lcs (1.2.5)
|
52
|
+
docile (1.1.5)
|
53
|
+
erubis (2.7.0)
|
54
|
+
factory_girl (4.7.0)
|
55
|
+
activesupport (>= 3.0.0)
|
56
|
+
geocoder (1.3.7)
|
57
|
+
glebtv-carrierwave-mongoid (0.8.0)
|
58
|
+
carrierwave (>= 0.8.0, < 0.11.0)
|
59
|
+
mongoid (>= 3.0, < 5.0)
|
60
|
+
glebtv-mongoid-paperclip (0.4.1)
|
61
|
+
mongoid (>= 3.0, < 6.1)
|
62
|
+
paperclip (~> 4.3.1)
|
63
|
+
hike (1.2.3)
|
64
|
+
i18n (0.7.0)
|
65
|
+
journey (1.0.4)
|
66
|
+
json (1.8.3)
|
67
|
+
mail (2.5.4)
|
68
|
+
mime-types (~> 1.16)
|
69
|
+
treetop (~> 1.4.8)
|
70
|
+
method_source (0.8.2)
|
71
|
+
mime-types (1.25.1)
|
72
|
+
mimemagic (0.3.0)
|
73
|
+
mini_portile2 (2.1.0)
|
74
|
+
mongoid (3.1.7)
|
75
|
+
activemodel (~> 3.2)
|
76
|
+
moped (~> 1.4)
|
77
|
+
origin (~> 1.0)
|
78
|
+
tzinfo (~> 0.3.29)
|
79
|
+
mongoid-rspec (1.13.0)
|
80
|
+
mongoid (~> 3.1)
|
81
|
+
rake
|
82
|
+
rspec (~> 3.1)
|
83
|
+
moped (1.5.3)
|
84
|
+
multi_json (1.12.1)
|
85
|
+
nokogiri (1.6.8)
|
86
|
+
mini_portile2 (~> 2.1.0)
|
87
|
+
pkg-config (~> 1.1.7)
|
88
|
+
nokogumbo (1.4.9)
|
89
|
+
nokogiri
|
90
|
+
origin (1.1.0)
|
91
|
+
paperclip (4.3.7)
|
92
|
+
activemodel (>= 3.2.0)
|
93
|
+
activesupport (>= 3.2.0)
|
94
|
+
cocaine (~> 0.5.5)
|
95
|
+
mime-types
|
96
|
+
mimemagic (= 0.3.0)
|
97
|
+
pkg-config (1.1.7)
|
98
|
+
polyglot (0.3.5)
|
99
|
+
pry (0.10.4)
|
100
|
+
coderay (~> 1.1.0)
|
101
|
+
method_source (~> 0.8.1)
|
102
|
+
slop (~> 3.4)
|
103
|
+
rack (1.4.7)
|
104
|
+
rack-cache (1.6.1)
|
105
|
+
rack (>= 0.4)
|
106
|
+
rack-ssl (1.3.4)
|
107
|
+
rack
|
108
|
+
rack-test (0.6.3)
|
109
|
+
rack (>= 1.0)
|
110
|
+
rails (3.2.22.4)
|
111
|
+
actionmailer (= 3.2.22.4)
|
112
|
+
actionpack (= 3.2.22.4)
|
113
|
+
activerecord (= 3.2.22.4)
|
114
|
+
activeresource (= 3.2.22.4)
|
115
|
+
activesupport (= 3.2.22.4)
|
116
|
+
bundler (~> 1.0)
|
117
|
+
railties (= 3.2.22.4)
|
118
|
+
railties (3.2.22.4)
|
119
|
+
actionpack (= 3.2.22.4)
|
120
|
+
activesupport (= 3.2.22.4)
|
121
|
+
rack-ssl (~> 1.3.2)
|
122
|
+
rake (>= 0.8.7)
|
123
|
+
rdoc (~> 3.4)
|
124
|
+
thor (>= 0.14.6, < 2.0)
|
125
|
+
rake (11.2.2)
|
126
|
+
rdoc (3.12.2)
|
127
|
+
json (~> 1.4)
|
128
|
+
rspec (3.5.0)
|
129
|
+
rspec-core (~> 3.5.0)
|
130
|
+
rspec-expectations (~> 3.5.0)
|
131
|
+
rspec-mocks (~> 3.5.0)
|
132
|
+
rspec-core (3.5.3)
|
133
|
+
rspec-support (~> 3.5.0)
|
134
|
+
rspec-expectations (3.5.0)
|
135
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
136
|
+
rspec-support (~> 3.5.0)
|
137
|
+
rspec-mocks (3.5.0)
|
138
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
139
|
+
rspec-support (~> 3.5.0)
|
140
|
+
rspec-support (3.5.0)
|
141
|
+
russian_phone (0.5.3)
|
142
|
+
safe_yaml (1.0.4)
|
143
|
+
sanitize (4.2.0)
|
144
|
+
crass (~> 1.0.2)
|
145
|
+
nokogiri (>= 1.4.4)
|
146
|
+
nokogumbo (~> 1.4.1)
|
147
|
+
simplecov (0.12.0)
|
148
|
+
docile (~> 1.1.0)
|
149
|
+
json (>= 1.8, < 3)
|
150
|
+
simplecov-html (~> 0.10.0)
|
151
|
+
simplecov-html (0.10.0)
|
152
|
+
slop (3.6.0)
|
153
|
+
sprockets (2.2.3)
|
154
|
+
hike (~> 1.2)
|
155
|
+
multi_json (~> 1.0)
|
156
|
+
rack (~> 1.0)
|
157
|
+
tilt (~> 1.1, != 1.3.0)
|
158
|
+
thor (0.19.1)
|
159
|
+
tilt (1.4.1)
|
160
|
+
treetop (1.4.15)
|
161
|
+
polyglot
|
162
|
+
polyglot (>= 0.3.1)
|
163
|
+
tzinfo (0.3.51)
|
164
|
+
validates_email_format_of (1.6.3)
|
165
|
+
i18n
|
166
|
+
|
167
|
+
PLATFORMS
|
168
|
+
ruby
|
169
|
+
|
170
|
+
DEPENDENCIES
|
171
|
+
ack_rails_admin_settings!
|
172
|
+
addressable
|
173
|
+
bundler
|
174
|
+
database_cleaner
|
175
|
+
factory_girl
|
176
|
+
geocoder
|
177
|
+
glebtv-carrierwave-mongoid
|
178
|
+
glebtv-mongoid-paperclip
|
179
|
+
mongoid (>= 3.0, < 6.0)
|
180
|
+
mongoid-rspec
|
181
|
+
pry
|
182
|
+
rails
|
183
|
+
rake
|
184
|
+
rspec
|
185
|
+
russian_phone
|
186
|
+
safe_yaml
|
187
|
+
sanitize
|
188
|
+
simplecov
|
189
|
+
validates_email_format_of
|
190
|
+
|
191
|
+
BUNDLED WITH
|
192
|
+
1.12.5
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 Alexander Kiseliev
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
# AckRailsAdminSettings
|
2
|
+
|
3
|
+
Fork of [RailsAdminSettings](https://github.com/rs-pro/rails_admin_settings)
|
4
|
+
|
5
|
+
App settings editable via RailsAdmin with support for ActiveRecord and Mongoid.
|
6
|
+
|
7
|
+
Supports images, files, html with or without sanitization, code with codemirror, etc.
|
8
|
+
|
9
|
+
## Features
|
10
|
+
|
11
|
+
- Lazy loading - loads settings only if they are needed during request
|
12
|
+
- Loads all settings at once and caches them for the duration of request
|
13
|
+
- Supports lots of setting kinds - yaml, html with ckeditor, phone numbers etc
|
14
|
+
- Each setting can be enabled and disabled within rails_admin, if it's disabled it returns default value for kind
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
gem 'rails_admin_settings'
|
21
|
+
|
22
|
+
For activerecord, generage migration:
|
23
|
+
|
24
|
+
rails g rails_admin_settings:migration
|
25
|
+
|
26
|
+
Then migrate:
|
27
|
+
|
28
|
+
rake db:migrate
|
29
|
+
|
30
|
+
## Gemfile order matters
|
31
|
+
|
32
|
+
- Put it after rails_admin to get built-in support
|
33
|
+
- Put it after rails_admin_toggleable to get built-in support
|
34
|
+
- Put it after ckeditor/glebtv-ckeditor/rich to get built-in support
|
35
|
+
- Put it after russian_phone to get built-in support
|
36
|
+
- Put it after sanitized to get built-in support
|
37
|
+
- Put it after safe_yaml to get built-in support
|
38
|
+
- Put it after validates_email_format_of to get built-in support
|
39
|
+
- Put it after geocoder to get built-in support
|
40
|
+
- Put it after carrierwave / paperclip to get built-in support
|
41
|
+
- Put it after addressable to get built-in support
|
42
|
+
|
43
|
+
And then execute:
|
44
|
+
|
45
|
+
$ bundle
|
46
|
+
|
47
|
+
Or install it yourself as:
|
48
|
+
|
49
|
+
$ gem install rails_admin_settings
|
50
|
+
|
51
|
+
## Basic Usage (like RailsSettings)
|
52
|
+
|
53
|
+
Settings.admin_email = 'test@example.com'
|
54
|
+
Settings.admin_email
|
55
|
+
|
56
|
+
|
57
|
+
## Advanced Usage
|
58
|
+
|
59
|
+
Settings.content_block_1(kind: 'html', default: 'test')
|
60
|
+
Settings.data(kind: 'yaml')
|
61
|
+
Settings.data = [1, 2, 3]
|
62
|
+
|
63
|
+
Settings.enabled?(:phone, kind: 'phone', default: '906 111-11-11') # also creates setting if it doesn't exist
|
64
|
+
Settings.phone.area
|
65
|
+
Settings.phone.subscriber
|
66
|
+
|
67
|
+
See more here: https://github.com/rs-pro/rails_admin_settings/blob/master/spec/advanced_usage_spec.rb
|
68
|
+
|
69
|
+
## Namespacing
|
70
|
+
|
71
|
+
Settings can have namespaces (useful for locale, etc)
|
72
|
+
|
73
|
+
Settings.ns('test').s1 = 123
|
74
|
+
Settings.ns('test').s1
|
75
|
+
> "123"
|
76
|
+
Settings.ns('main').s1
|
77
|
+
> ""
|
78
|
+
Settings.s1
|
79
|
+
> ""
|
80
|
+
Settings.ns_default = 'test'
|
81
|
+
Settings.s1
|
82
|
+
> "123"
|
83
|
+
Settings.ns_default = 'main'
|
84
|
+
Settings.ns_fallback = 'test'
|
85
|
+
Settings.s1
|
86
|
+
> "123"
|
87
|
+
|
88
|
+
|
89
|
+
## Cache control
|
90
|
+
|
91
|
+
Settings.content_block_1(kind: 'html', default: 'test', cache_keys: ["block_name1", "block_name2", :other_block])
|
92
|
+
Settings.content_block_1(kind: 'html', default: 'test', cache_keys: "block_name1 block_name2 other_block")
|
93
|
+
|
94
|
+
And Rails cache for this keys will be delete after each saving ('clear_cache' method). Also you can edit it in rails_admin panel.
|
95
|
+
|
96
|
+
## Value types
|
97
|
+
|
98
|
+
Supported types:
|
99
|
+
|
100
|
+
string (input)
|
101
|
+
text (textarea)
|
102
|
+
boolean (checkbox)
|
103
|
+
color (uses built-in RailsAdmin color picker)
|
104
|
+
html (supports Rich, glebtv-ckeditor, ckeditor, but does not require any of them)
|
105
|
+
sanitized (requires sanitize -- sanitizes HTML before saving to DB [Warning: uses RELAXED config!])
|
106
|
+
integer (stored as string)
|
107
|
+
yaml (requires safe_yaml)
|
108
|
+
phone (requires russian_phone)
|
109
|
+
email (requires validates_email_format_of)
|
110
|
+
address (requires geocoder)
|
111
|
+
file (requires paperclip or carrierwave)
|
112
|
+
url (requires addressable)
|
113
|
+
domain (requires addressable)
|
114
|
+
js (requires codemirror)
|
115
|
+
css (requires codemirror)
|
116
|
+
|
117
|
+
|
118
|
+
Strings and html support following replacement patterns:
|
119
|
+
|
120
|
+
{{year}} -> current year
|
121
|
+
{{year|2013}} -> 2013 in 2013, 2013-2014 in 2014, etc
|
122
|
+
|
123
|
+
## Usage with Rails Admin
|
124
|
+
|
125
|
+
Rails admin management for settings is supported out of the box
|
126
|
+
|
127
|
+
## Contributing
|
128
|
+
|
129
|
+
1. Fork it
|
130
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
131
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
132
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
133
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
if RailsAdminSettings.active_record?
|
2
|
+
module RailsAdminSettings
|
3
|
+
class Setting < ActiveRecord::Base
|
4
|
+
end
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
module RailsAdminSettings
|
9
|
+
class Setting
|
10
|
+
#binding.pry
|
11
|
+
if RailsAdminSettings.mongoid?
|
12
|
+
include RailsAdminSettings::Mongoid
|
13
|
+
end
|
14
|
+
|
15
|
+
if RailsAdminSettings.active_record?
|
16
|
+
self.table_name = "rails_admin_settings".freeze
|
17
|
+
end
|
18
|
+
|
19
|
+
scope :enabled, -> { where(enabled: true) }
|
20
|
+
scope :ns, ->(ns) { where(ns: ns) }
|
21
|
+
|
22
|
+
include RailsAdminSettings::RequireHelpers
|
23
|
+
include RailsAdminSettings::Processing
|
24
|
+
include RailsAdminSettings::Uploads
|
25
|
+
include RailsAdminSettings::Validation
|
26
|
+
|
27
|
+
def disabled?
|
28
|
+
!enabled
|
29
|
+
end
|
30
|
+
|
31
|
+
def enabled?
|
32
|
+
enabled
|
33
|
+
end
|
34
|
+
|
35
|
+
def name
|
36
|
+
label.blank? ? key : label
|
37
|
+
end
|
38
|
+
|
39
|
+
def type
|
40
|
+
kind
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_path
|
44
|
+
if value.nil?
|
45
|
+
nil
|
46
|
+
else
|
47
|
+
'public' + URI.parse(value).path
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def as_yaml(options = {})
|
52
|
+
v = {type: type, enabled: enabled, label: label}
|
53
|
+
if upload_type?
|
54
|
+
v[:value] = to_path
|
55
|
+
else
|
56
|
+
v[:value] = raw
|
57
|
+
end
|
58
|
+
v.stringify_keys!
|
59
|
+
v
|
60
|
+
end
|
61
|
+
|
62
|
+
# t = {_all: 'Все'}
|
63
|
+
if ::Settings.table_exists?
|
64
|
+
::RailsAdminSettings::Setting.pluck(:ns).uniq.each do |c|
|
65
|
+
s = "ns_#{c.gsub('-', '_')}".to_sym
|
66
|
+
scope s, -> { where(ns: c) }
|
67
|
+
# t[s] = c
|
68
|
+
end
|
69
|
+
end
|
70
|
+
# I18n.backend.store_translations(:ru, {admin: {scopes: {'rails_admin_settings/setting': t}}})
|
71
|
+
|
72
|
+
if Object.const_defined?('RailsAdmin')
|
73
|
+
include RailsAdminSettings::RailsAdminConfig
|
74
|
+
else
|
75
|
+
puts "[rails_admin_settings] Rails Admin not detected -- put this gem after rails_admin in gemfile".freeze
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
- if ['string', 'integer', 'phone', 'email', 'address', 'url', 'domain'].include?(@object.type)
|
2
|
+
= form.text_field :raw, :value => field.value
|
3
|
+
- if @object.type == 'boolean'
|
4
|
+
= form.check_box :raw, {:value => field.value}, 'true', 'false'
|
5
|
+
- if @object.type == 'color'
|
6
|
+
= form.text_field :raw, :value => field.value, 'data-color' => true, style: "background-color: ##{field.value}"
|
7
|
+
- elsif %w(text yaml phones).include?( @object.type )
|
8
|
+
= form.text_area :raw, :value => field.value, :rows => 10, :cols => 80
|
9
|
+
- elsif @object.type == 'code'
|
10
|
+
:ruby
|
11
|
+
#binding.pry
|
12
|
+
js_data = {
|
13
|
+
csspath: asset_path('codemirror.css'),
|
14
|
+
jspath: asset_path('codemirror.js'),
|
15
|
+
options: {
|
16
|
+
mode: 'htmlmixed',
|
17
|
+
theme: 'monokai',
|
18
|
+
lineNumbers: true
|
19
|
+
},
|
20
|
+
locations: {
|
21
|
+
mode: asset_path('codemirror/modes/htmlmixed.js'),
|
22
|
+
theme: asset_path('codemirror/themes/monokai.css')
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
= form.text_area field.method_name, field.html_attributes.reverse_merge(data: { richtext: 'codemirror', options: js_data.to_json }).reverse_merge({ value: field.form_value })
|
27
|
+
- elsif @object.type == 'html' || @object.type == 'sanitized'
|
28
|
+
- if form.respond_to?(:cktext_area)
|
29
|
+
= javascript_include_tag "ckeditor/init"
|
30
|
+
= form.cktext_area :raw, :value => field.value, :rows => 10, :cols => 80
|
31
|
+
- elsif Object.const_defined?('Rich')
|
32
|
+
= form.text_area :raw, :value => field.value, :rows => 10, :cols => 80
|
33
|
+
|
34
|
+
= javascript_include_tag "rich/base.js"
|
35
|
+
:javascript
|
36
|
+
var instance = CKEDITOR.instances['#{form.dom_id(field)}'];
|
37
|
+
if(instance) { CKEDITOR.remove(instance); }
|
38
|
+
CKEDITOR.replace('#{form.dom_id(field)}', #{Rich.options().to_json.html_safe});
|
39
|
+
- else
|
40
|
+
.alert.alert-error
|
41
|
+
= t('admin.settings.no_ckeditor_detected')
|
42
|
+
= form.text_area :raw, :value => field.value, :rows => 10, :cols => 80
|
43
|
+
|
44
|
+
|
45
|
+
- elsif @object.type == 'enum'
|
46
|
+
-# temporary
|
47
|
+
- unless @object.enum_multiple
|
48
|
+
= form.select :raw, @object.enum_collection, { include_blank: true, selected: @object.raw }, { data: { enumeration: true }, placeholder: t('admin.misc.search') }
|
49
|
+
- else
|
50
|
+
:ruby
|
51
|
+
js_data = {
|
52
|
+
xhr: false,
|
53
|
+
sortable: false,
|
54
|
+
cacheAll: true,
|
55
|
+
regional: {
|
56
|
+
chooseAll: t("admin.misc.chose_all"),
|
57
|
+
chosen: t("admin.misc.chosen", name: @object.enum_label),
|
58
|
+
clearAll: t("admin.misc.clear_all"),
|
59
|
+
search: t("admin.misc.search"),
|
60
|
+
up: t("admin.misc.up"),
|
61
|
+
down: t("admin.misc.down")
|
62
|
+
}
|
63
|
+
}
|
64
|
+
= form.select :raw, @object.enum_collection, { selected: @object.raw, object: @object }, {data: { filteringmultiselect: true, options: js_data.to_json }, multiple: true}
|
65
|
+
|
66
|
+
|
67
|
+
- elsif @object.type == 'js'
|
68
|
+
:ruby
|
69
|
+
#binding.pry
|
70
|
+
js_data = {
|
71
|
+
csspath: asset_path('codemirror.css'),
|
72
|
+
jspath: asset_path('codemirror.js'),
|
73
|
+
options: {
|
74
|
+
mode: 'js',
|
75
|
+
theme: 'night',
|
76
|
+
lineNumbers: true
|
77
|
+
},
|
78
|
+
locations: {
|
79
|
+
mode: asset_path('codemirror/modes/jsx.js'),
|
80
|
+
theme: asset_path('codemirror/themes/night.css')
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
= form.text_area field.method_name, field.html_attributes.reverse_merge(data: { richtext: 'codemirror', options: js_data.to_json }).reverse_merge({ value: field.form_value })
|
85
|
+
|
86
|
+
|
87
|
+
- elsif @object.type == 'css'
|
88
|
+
:ruby
|
89
|
+
#binding.pry
|
90
|
+
js_data = {
|
91
|
+
csspath: asset_path('codemirror.css'),
|
92
|
+
jspath: asset_path('codemirror.js'),
|
93
|
+
options: {
|
94
|
+
mode: 'css',
|
95
|
+
theme: 'night',
|
96
|
+
lineNumbers: true
|
97
|
+
},
|
98
|
+
locations: {
|
99
|
+
mode: asset_path('codemirror/modes/css.js'),
|
100
|
+
theme: asset_path('codemirror/themes/night.css')
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
= form.text_area field.method_name, field.html_attributes.reverse_merge(data: { richtext: 'codemirror', options: js_data.to_json }).reverse_merge({ value: field.form_value })
|
@@ -0,0 +1,28 @@
|
|
1
|
+
en:
|
2
|
+
admin:
|
3
|
+
settings:
|
4
|
+
label: 'Settings'
|
5
|
+
no_ckeditor_detected: CKEditor not found — showing as text input
|
6
|
+
phone_invalid: Incorrect phone
|
7
|
+
phones_invalid: "Incorrect phone: %{phones}"
|
8
|
+
email_invalid: Incorrect email
|
9
|
+
yaml_invalid: Incorrect YAML
|
10
|
+
color_invalid: Incorrect color
|
11
|
+
mongoid: &mongoid
|
12
|
+
models:
|
13
|
+
rails_admin_settings/setting: Settings
|
14
|
+
attributes:
|
15
|
+
rails_admin_settings/setting:
|
16
|
+
c_at: Created
|
17
|
+
u_at: Updated
|
18
|
+
enabled: Enabled
|
19
|
+
ns: Group
|
20
|
+
name: Name
|
21
|
+
key: Key
|
22
|
+
raw: Value
|
23
|
+
type: Type
|
24
|
+
kind: Type
|
25
|
+
label: Label
|
26
|
+
activerecord:
|
27
|
+
<<: *mongoid
|
28
|
+
|