activeadmin_settings_cached 0.1.1 → 1.0.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.
- checksums.yaml +4 -4
- data/README.md +28 -11
- data/activeadmin_settings_cached.gemspec +17 -17
- data/app/admin/settings.rb +1 -4
- data/app/controllers/activeadmin_settings_cached/settings_controller.rb +5 -5
- data/app/helpers/settings_helper.rb +20 -0
- data/app/views/admin/settings/_index.html.erb +2 -2
- data/lib/activeadmin_settings_cached/version.rb +1 -1
- data/lib/activeadmin_settings_cached.rb +35 -4
- metadata +13 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93deb43bc251b8519edab152fd3384bd5919cda5
|
4
|
+
data.tar.gz: c1961c0ad4cc34c1b1dc0d8b01fea2fbf6e7463a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2a7704a63453e64e58ea07d7abe6eb3c03755e7f648837ac8266d2587b6483af551799a4c32629b1d1ca71b2c316b2119017f2f19f5dc1b63a090ed0be391c6
|
7
|
+
data.tar.gz: e74d53cdb81779620046399605d29b1e4ad27e82d21b232f47b2f6db60b6eb6e78d43fc38f7cf8234268366f9dfd4ea01bf9d3da326e2c0108dd3fd0cb929e96
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[](http://badge.fury.io/rb/activeadmin_settings_cached)
|
4
4
|
|
5
|
-
|
5
|
+
Provides a nice UI interface for [rails-settings-cached](https://github.com/huacnlee/rails-settings-cached) gem in [Active Admin](http://activeadmin.info/).
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -16,19 +16,19 @@ And then execute:
|
|
16
16
|
|
17
17
|
$ bundle
|
18
18
|
|
19
|
-
Create
|
19
|
+
Create your settings model:
|
20
20
|
|
21
21
|
$ rails g settings Settings
|
22
22
|
$ bundle exec rake db:migrate
|
23
23
|
|
24
|
-
Add route in config/routes.rb
|
24
|
+
Add a route in config/routes.rb
|
25
25
|
|
26
26
|
``` ruby
|
27
27
|
ActiveAdmin.routes(self)
|
28
|
-
mount ActiveadminSettingsCached::Engine => '/admin'
|
28
|
+
mount ActiveadminSettingsCached::Engine => '/admin'
|
29
29
|
```
|
30
30
|
|
31
|
-
And configure
|
31
|
+
And configure your default values in your Settings model:
|
32
32
|
|
33
33
|
``` ruby
|
34
34
|
class Settings < RailsSettings::CachedSettings
|
@@ -36,9 +36,9 @@ class Settings < RailsSettings::CachedSettings
|
|
36
36
|
end
|
37
37
|
```
|
38
38
|
|
39
|
-
|
39
|
+
In your application's admin interface, there will now be a new page with this setting
|
40
40
|
|
41
|
-
|
41
|
+
## Localization
|
42
42
|
You can localize settings keys in local file
|
43
43
|
|
44
44
|
``` yml
|
@@ -48,12 +48,29 @@ en:
|
|
48
48
|
my_awesome_settings:
|
49
49
|
name: 'My Awesome Lolaized Setting'
|
50
50
|
```
|
51
|
+
## Model name
|
51
52
|
|
52
|
-
If you
|
53
|
-
`config/initializers/active_admin_settings_cached.rb`
|
53
|
+
By default the name of the mode is `Settings`. If you want to use a different name for the model, you can specify your that in `config/initializers/active_admin_settings_cached.rb`:
|
54
54
|
|
55
55
|
``` ruby
|
56
|
-
ActiveadminSettingsCached.
|
56
|
+
ActiveadminSettingsCached.configure do |config|
|
57
|
+
config.model_name = 'AdvancedSetting'
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
## Display options
|
62
|
+
|
63
|
+
If you need define display options for settings fields, eg textarea, url or :timestamp and etc., you can set `display` option in initializer.
|
64
|
+
|
65
|
+
|
66
|
+
``` ruby
|
67
|
+
ActiveadminSettingsCached.configure do |config|
|
68
|
+
condig.display = {
|
69
|
+
my_awesome_setting_name: :text,
|
70
|
+
my_awesome_setting_name_2: :timestamp,
|
71
|
+
my_awesome_setting_name_3: :select
|
72
|
+
}
|
73
|
+
end
|
57
74
|
```
|
58
75
|
|
59
|
-
|
76
|
+
Available options see [here](https://github.com/justinfrench/formtastic#the-available-inputs)
|
@@ -3,24 +3,24 @@ lib = File.expand_path('../lib', __FILE__)
|
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'activeadmin_settings_cached/version'
|
5
5
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "activeadmin_settings_cached"
|
8
|
+
s.version = ActiveadminSettingsCached::VERSION
|
9
|
+
s.authors = ["Semyon Pupkov"]
|
10
|
+
s.email = ["semen.pupkov@gmail.com"]
|
11
|
+
s.summary = "UI interface for rails-settings-cached in active admin"
|
12
|
+
s.description = "UI interface for rails-settings-cached in active admin"
|
13
|
+
s.homepage = "https://github.com/artofhuman/activeadmin_settings_cached"
|
14
|
+
s.license = "MIT"
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
s.files = `git ls-files -z`.split("\x0")
|
17
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
19
|
+
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
s.add_dependency 'activeadmin'
|
22
|
+
s.add_dependency 'rails-settings-cached'
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
s.add_development_dependency "bundler"
|
25
|
+
s.add_development_dependency "rake"
|
26
26
|
end
|
data/app/admin/settings.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
module ActiveadminSettingsCached
|
2
2
|
class SettingsController < ApplicationController
|
3
3
|
def update
|
4
|
-
settings = ActiveadminSettingsCached.settings_klass
|
5
|
-
|
6
4
|
settings_params.each_pair do |name, value|
|
7
|
-
|
5
|
+
settings_model[name] = value
|
8
6
|
end
|
9
7
|
|
10
8
|
flash[:success] = t('.success'.freeze)
|
@@ -14,9 +12,11 @@ module ActiveadminSettingsCached
|
|
14
12
|
private
|
15
13
|
|
16
14
|
def settings_params
|
17
|
-
|
15
|
+
params.require(:settings).permit(settings_model.defaults.keys)
|
16
|
+
end
|
18
17
|
|
19
|
-
|
18
|
+
def settings_model
|
19
|
+
ActiveadminSettingsCached.config.model_name
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module SettingsHelper
|
2
|
+
def settings_field_options(settings_name)
|
3
|
+
default_value = ActiveadminSettingsCached.defaults[settings_name]
|
4
|
+
value = ActiveadminSettingsCached.settings[settings_name]
|
5
|
+
|
6
|
+
input_opts = if default_value.is_a?(Array)
|
7
|
+
{
|
8
|
+
collection: default_value,
|
9
|
+
selected: value,
|
10
|
+
}
|
11
|
+
else
|
12
|
+
{
|
13
|
+
input_html: {value: value, placeholder: default_value},
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
{as: ActiveadminSettingsCached.config.display[settings_name], label: false}
|
18
|
+
.merge!(input_opts)
|
19
|
+
end
|
20
|
+
end
|
@@ -8,12 +8,12 @@
|
|
8
8
|
</tr>
|
9
9
|
</thead>
|
10
10
|
<tbody>
|
11
|
-
<%
|
11
|
+
<% ActiveadminSettingsCached.settings.each_pair do |name, value| %>
|
12
12
|
<tr class="odd">
|
13
13
|
<td><strong><%= f.label t("settings.attributes.#{name}.name", default: name) %></strong></td>
|
14
14
|
<td>
|
15
15
|
<div class='form'>
|
16
|
-
<ol><%= f.input name,
|
16
|
+
<ol><%= f.input name, settings_field_options(name) %></ol>
|
17
17
|
</div>
|
18
18
|
</td>
|
19
19
|
</tr>
|
@@ -1,12 +1,43 @@
|
|
1
1
|
require "activeadmin_settings_cached/engine"
|
2
2
|
|
3
3
|
module ActiveadminSettingsCached
|
4
|
-
|
5
|
-
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :model_name, :display
|
6
|
+
|
7
|
+
def model_name
|
8
|
+
(@model_name ||= 'Settings').constantize
|
9
|
+
end
|
10
|
+
|
11
|
+
def display
|
12
|
+
(@display ||= {}).with_indifferent_access
|
13
|
+
end
|
14
|
+
end
|
6
15
|
|
7
16
|
class << self
|
8
|
-
def
|
9
|
-
|
17
|
+
def config
|
18
|
+
@config ||= Configuration.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def configure
|
22
|
+
yield config
|
23
|
+
end
|
24
|
+
|
25
|
+
def settings
|
26
|
+
config.model_name.public_send(meth)
|
27
|
+
end
|
28
|
+
|
29
|
+
def defaults
|
30
|
+
config.model_name.defaults
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def meth
|
36
|
+
if Rails.version >= '4.1.0'
|
37
|
+
:get_all
|
38
|
+
else
|
39
|
+
:all
|
40
|
+
end
|
10
41
|
end
|
11
42
|
end
|
12
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin_settings_cached
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Semyon Pupkov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -41,32 +41,32 @@ dependencies:
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- -
|
44
|
+
- - '>='
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
46
|
+
version: '0'
|
47
47
|
name: bundler
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
requirements:
|
50
|
-
- -
|
50
|
+
- - '>='
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '
|
52
|
+
version: '0'
|
53
53
|
type: :development
|
54
54
|
prerelease: false
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- -
|
58
|
+
- - '>='
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
60
|
+
version: '0'
|
61
61
|
name: rake
|
62
62
|
requirement: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
|
-
- -
|
64
|
+
- - '>='
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: '
|
66
|
+
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
description:
|
69
|
+
description: UI interface for rails-settings-cached in active admin
|
70
70
|
email:
|
71
71
|
- semen.pupkov@gmail.com
|
72
72
|
executables: []
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- activeadmin_settings_cached.gemspec
|
82
82
|
- app/admin/settings.rb
|
83
83
|
- app/controllers/activeadmin_settings_cached/settings_controller.rb
|
84
|
+
- app/helpers/settings_helper.rb
|
84
85
|
- app/views/admin/settings/_index.html.erb
|
85
86
|
- config/locales/en.yml
|
86
87
|
- config/locales/ru.yml
|
@@ -88,7 +89,7 @@ files:
|
|
88
89
|
- lib/activeadmin_settings_cached.rb
|
89
90
|
- lib/activeadmin_settings_cached/engine.rb
|
90
91
|
- lib/activeadmin_settings_cached/version.rb
|
91
|
-
homepage:
|
92
|
+
homepage: https://github.com/artofhuman/activeadmin_settings_cached
|
92
93
|
licenses:
|
93
94
|
- MIT
|
94
95
|
metadata: {}
|