activeadmin_settings_cached 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a234d2b3c9d9c19458b00ee6ebe8af9a7e3fc059
4
- data.tar.gz: 5e36ecdc24654ac093f47d535d4ca41ff7a32bbc
3
+ metadata.gz: 93deb43bc251b8519edab152fd3384bd5919cda5
4
+ data.tar.gz: c1961c0ad4cc34c1b1dc0d8b01fea2fbf6e7463a
5
5
  SHA512:
6
- metadata.gz: eb3960656d5aea1fa39585d632242bc3e333b7735c64eb88324ec5cd4941632218a5e25abf7f0da75dc060bcc9105a7e2ff4a032cef7bef4384712fad3dc4b17
7
- data.tar.gz: c5be99fd6db507ab68462b8056f9c379566ec5e6406e87961b0b2782ba91fe90c0c1f46e91fcecb424cc6b51d08664c30aa53e2126705b7f37001b9f82ad976c
6
+ metadata.gz: d2a7704a63453e64e58ea07d7abe6eb3c03755e7f648837ac8266d2587b6483af551799a4c32629b1d1ca71b2c316b2119017f2f19f5dc1b63a090ed0be391c6
7
+ data.tar.gz: e74d53cdb81779620046399605d29b1e4ad27e82d21b232f47b2f6db60b6eb6e78d43fc38f7cf8234268366f9dfd4ea01bf9d3da326e2c0108dd3fd0cb929e96
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/activeadmin_settings_cached.svg)](http://badge.fury.io/rb/activeadmin_settings_cached)
4
4
 
5
- Gem for Rails provides ui interface for rails-settings-cached gem in Active Admin
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 you settings model:
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 you default values in model Settings like this:
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
- And in your appication admin avaliable new page with this settings
39
+ In your application's admin interface, there will now be a new page with this setting
40
40
 
41
- # Localization
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 settings model named not Settings, you can define model name in
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.settings_class = 'AdvancedSetting'
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
- For how use Settings in you application see documentation fo rails-settings-cached gem https://github.com/huacnlee/rails-settings-cached
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 |spec|
7
- spec.name = "activeadmin_settings_cached"
8
- spec.version = ActiveadminSettingsCached::VERSION
9
- spec.authors = ["Semyon Pupkov"]
10
- spec.email = ["semen.pupkov@gmail.com"]
11
- spec.summary = %q{UI interface for rails-settings-cached in active admin}
12
- spec.description = ""
13
- spec.homepage = ""
14
- spec.license = "MIT"
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
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
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
- spec.add_dependency 'activeadmin'
22
- spec.add_dependency 'rails-settings-cached'
21
+ s.add_dependency 'activeadmin'
22
+ s.add_dependency 'rails-settings-cached'
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.7"
25
- spec.add_development_dependency "rake", "~> 10.0"
24
+ s.add_development_dependency "bundler"
25
+ s.add_development_dependency "rake"
26
26
  end
@@ -8,9 +8,6 @@ ActiveAdmin.register_page "Settings" do
8
8
  end
9
9
 
10
10
  controller do
11
- def settings_list
12
- settings = ActiveadminSettingsCached.settings_klass
13
- settings.defaults.merge!(settings.get_all)
14
- end
11
+ helper :settings
15
12
  end
16
13
  end
@@ -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
- settings[name] = value
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
- settings_keys = ActiveadminSettingsCached.settings_klass.defaults.keys
15
+ params.require(:settings).permit(settings_model.defaults.keys)
16
+ end
18
17
 
19
- params.require(:settings).permit(settings_keys)
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
- <% controller.settings_list.each_pair do |name, value| %>
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, label: false, input_html: { value: value } %></ol>
16
+ <ol><%= f.input name, settings_field_options(name) %></ol>
17
17
  </div>
18
18
  </td>
19
19
  </tr>
@@ -1,3 +1,3 @@
1
1
  module ActiveadminSettingsCached
2
- VERSION = "0.1.1"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -1,12 +1,43 @@
1
1
  require "activeadmin_settings_cached/engine"
2
2
 
3
3
  module ActiveadminSettingsCached
4
- mattr_accessor :settings_class
5
- self.settings_class = "Settings"
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 settings_klass
9
- settings_class.constantize
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.1.1
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-08-31 00:00:00.000000000 Z
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: '1.7'
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: '1.7'
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: '10.0'
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: '10.0'
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: {}