ez-settings 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -15
- data/lib/ez/settings/version.rb +1 -1
- data/lib/generators/ez/settings/install_generator.rb +131 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9803a79f83de53644a0f14d809bd72a33622b58a
|
4
|
+
data.tar.gz: 3f29121922ee1fd0140b763e24a85d5176f3d010
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 273e190f3bdc066ab05c8316e84c9f64dcd3bc263560052c1d597b8518cc7f97a488e5b88abd053109d967866c6317b59ab5b882c5bd26c79d44f36108dea3dc
|
7
|
+
data.tar.gz: a4b530afaecbf6c8227e571b8555cfe3bfad8d919803b259ecc5c8dd7e7e34d239d3f7b4fbb74452dec8a167c354380c7771d91a161e90532b41838c155d3e45
|
data/README.md
CHANGED
@@ -8,11 +8,15 @@
|
|
8
8
|
- Convetion over configuration principles.
|
9
9
|
- Depends on [ez-core](https://github.com/ez-engines/ez-core)
|
10
10
|
|
11
|
+
If you are boring to read all this stuff maybe this video motivates you:
|
12
|
+
|
13
|
+
[YouTube demonstrates how easy we integrated ez-settings for our pivorak-web-app only by ±50 lines of code](https://www.youtube.com/watch?v=TiX0QDHEaKA&feature=youtu.be)
|
14
|
+
|
11
15
|
## Installation
|
12
16
|
Add this line to your application's Gemfile:
|
13
17
|
|
14
18
|
```ruby
|
15
|
-
gem 'ez-settings'
|
19
|
+
gem 'ez-settings', '~> 0.1'
|
16
20
|
```
|
17
21
|
|
18
22
|
And then execute:
|
@@ -25,16 +29,15 @@ Or install it yourself as:
|
|
25
29
|
$ gem install ez-settings
|
26
30
|
```
|
27
31
|
|
28
|
-
|
29
|
-
|
30
|
-
### Initializer
|
32
|
+
and `bundle install`
|
31
33
|
|
32
|
-
|
34
|
+
### Initialize
|
33
35
|
|
34
|
-
|
36
|
+
`rails generate ez:settings:install`
|
35
37
|
|
36
|
-
|
38
|
+
Generates initializer config file and I18n yaml file with english keys
|
37
39
|
|
40
|
+
`config/ez_settings.rb`
|
38
41
|
```ruby
|
39
42
|
# By default engine try to inherit from ApplicationController, but you could change this:
|
40
43
|
# Ez::Settings.config.base_controller = 'Admin::BaseController'
|
@@ -44,10 +47,9 @@ If you are boring to read all this stuff maybe this video motivates you:
|
|
44
47
|
#
|
45
48
|
# Interface DSL allows you to do this very declaratively
|
46
49
|
#
|
47
|
-
#
|
48
50
|
app = Ez::Settings::Interface.define :app do # :app - interface name
|
49
|
-
group :general do # :general
|
50
|
-
key :app_title, default: -> { 'Main app title' } # :app_title
|
51
|
+
group :general do # :general - name of the group
|
52
|
+
key :app_title, default: -> { 'Main app title' } # :app_title - key name for store value in :general group for :app interface
|
51
53
|
end
|
52
54
|
|
53
55
|
# And so on...
|
@@ -121,16 +123,18 @@ app.configure do |config|
|
|
121
123
|
# }
|
122
124
|
end
|
123
125
|
|
124
|
-
#
|
126
|
+
# Ez::Settings uses Ez::Registry from ez-core lib for storing all knowledges in one place.
|
125
127
|
# This place is registry records for :settings_interfaces registry
|
126
128
|
#
|
127
129
|
# Register `app` variable as settings interface
|
128
|
-
Ez::Registry.in(:settings_interfaces, by:
|
130
|
+
Ez::Registry.in(:settings_interfaces, by: 'YourAppName') do |registry|
|
129
131
|
registry.add app
|
130
132
|
end
|
131
133
|
```
|
134
|
+
|
132
135
|
### Routes
|
133
136
|
`config/routes.rb`
|
137
|
+
|
134
138
|
```ruby
|
135
139
|
Rails.application.routes.draw do
|
136
140
|
# your routes code before
|
@@ -226,7 +230,6 @@ If you need, create locale file with this structure:
|
|
226
230
|
|
227
231
|
## TODO
|
228
232
|
This features will be implemented in upcoming 0.2 and 0.3 releases:
|
229
|
-
- `rails g ez:settings:install` it creates `config/ez_settings.rb` and `config/locales/ez-settings.en.yml`
|
230
233
|
- Scoped settings (`:scope_id`, `:scope_type`)
|
231
234
|
- groups as defined methods for interface
|
232
235
|
- controller before actions as configured callbacks
|
@@ -234,8 +237,8 @@ This features will be implemented in upcoming 0.2 and 0.3 releases:
|
|
234
237
|
- Allow to config endpoints
|
235
238
|
- Interface description (and show at UI)
|
236
239
|
- Groups description (and show at UI)
|
237
|
-
- Database storage as backend
|
238
|
-
- Redis storage as backend
|
240
|
+
- Database storage as backend (ActiveRecord)
|
241
|
+
- Redis storage as backend (RedisRb)
|
239
242
|
|
240
243
|
## Contributing
|
241
244
|
Fork => Fix => MR warmly welcomed!
|
data/lib/ez/settings/version.rb
CHANGED
@@ -1 +1,131 @@
|
|
1
|
-
|
1
|
+
module Ez::Settings
|
2
|
+
class InstallGenerator < Rails::Generators::Base
|
3
|
+
def create_initializer_file
|
4
|
+
create_file "config/initializers/ez_settings.rb",
|
5
|
+
"# By default engine try to inherit from ApplicationController, but you could change this:
|
6
|
+
# Ez::Settings.config.base_controller = 'Admin::BaseController'
|
7
|
+
#
|
8
|
+
# Then you should define settings interfaces (you can create as much as you need)
|
9
|
+
# Ierachy is pretty simple: Interface -> Group -> Key
|
10
|
+
#
|
11
|
+
# Interface DSL allows you to do this very declaratively
|
12
|
+
#
|
13
|
+
app = Ez::Settings::Interface.define :app do # :app - interface name
|
14
|
+
group :general do # :general - name of the group
|
15
|
+
key :app_title, default: -> { 'Main app title' } # :app_title - key name for store value in :general group for :app interface
|
16
|
+
end
|
17
|
+
|
18
|
+
# And so on...
|
19
|
+
group :admin do
|
20
|
+
key :app_title, default: -> { 'Admin app title' }
|
21
|
+
end
|
22
|
+
|
23
|
+
# If you want to see all power of the engine, add this showcase:
|
24
|
+
group :showcase do
|
25
|
+
key :string, default: -> { 'simple string' }
|
26
|
+
key :bool, type: :boolean, default: -> { true }
|
27
|
+
key :integer, type: :integer, default: -> { 777 }
|
28
|
+
key :select, type: :select, default: -> { 'foo' }, collection: %w(foo bar baz)
|
29
|
+
key :not_validate, required: false, presence: false
|
30
|
+
key :not_for_ui, required: false, ui: false
|
31
|
+
end
|
32
|
+
# Keys could have:
|
33
|
+
# :type (string by default), now ez-settings supports only: string, boolean, integer and select
|
34
|
+
# :default value (as callable objects)
|
35
|
+
# :required - be or not (all keys are required by default)
|
36
|
+
# :ui visible or not (all keys are UI visible by default)
|
37
|
+
end
|
38
|
+
|
39
|
+
# After defining settings interface groups/keys you need to configure it:
|
40
|
+
app.configure do |config|
|
41
|
+
# Backend adapter to store all settings (in current version only file system)
|
42
|
+
config.backend = Ez::Settings::Backend::FileSystem.new(Rails.root.join('config', 'settings.yml'))
|
43
|
+
|
44
|
+
# Default path for redirect in controller
|
45
|
+
config.default_path = '/admin/settings'
|
46
|
+
|
47
|
+
# Pass your custom css classes through css_map config
|
48
|
+
# Defaults would be merged with yours:
|
49
|
+
# config.custom_css_map = {
|
50
|
+
# nav_label: 'ez-settings-nav-label',
|
51
|
+
# nav_menu: 'ez-settings-nav-menu',
|
52
|
+
# nav_menu_item: 'ez-settings-nav-menu-item',
|
53
|
+
# overview_page_wrapper: 'ez-settings-overview',
|
54
|
+
# overview_page_section: 'ez-settings-overview-section',
|
55
|
+
# overview_page_section_header: 'ez-settings-overview-section-header',
|
56
|
+
# overview_page_section_content: 'ez-settings-overview-section-content',
|
57
|
+
# overview_page_section_content_key: 'ez-settings-overview-section-content-key',
|
58
|
+
# overview_page_section_content_value: 'ez-settings-overview-section-content-value',
|
59
|
+
# group_page_wrapper: 'ez-settings-group-wrapper',
|
60
|
+
# group_page_inner_wrapper: 'ez-settings-group-inner-wrapper',
|
61
|
+
# group_page_header: 'ez-settings-group-header',
|
62
|
+
# group_page_form_wrapper: 'ez-settings-group-form-wrapper',
|
63
|
+
# group_page_form_inner: 'ez-settings-group-form-inner',
|
64
|
+
# group_page_form_field_row: 'ez-settings-group-form-field-row',
|
65
|
+
# group_page_form_string_wrapper: 'ez-settings-group-form-string-wrapper',
|
66
|
+
# group_page_form_boolean_wrapper: 'ez-settings-group-form-boolean-wrapper',
|
67
|
+
# group_page_form_select_wrapper: 'ez-settings-group-form-select-wrapper',
|
68
|
+
# group_page_actions_wrapper: 'ez-settings-group-actions-wrapper',
|
69
|
+
# group_page_actions_wrapper: 'ez-settings-group-actions-wrapper',
|
70
|
+
# group_page_actions_save_button: 'ez-settings-group-actions-save-btn',
|
71
|
+
# group_page_actions_cancel_link: 'ez-settings-group-actions-cancel-link'
|
72
|
+
# }
|
73
|
+
#
|
74
|
+
# Highly recommend inspecting settings page DOM.
|
75
|
+
# You can find there a lot of interesting id/class stuff
|
76
|
+
#
|
77
|
+
# You even can define dynamic map for allows to decide which CSS class could be added
|
78
|
+
# `if` must contain callable object that receives controller as a first argument and dynamic element as second one:
|
79
|
+
#
|
80
|
+
# In this example, you easily could add 'active' CSS class if route end with some fragment:
|
81
|
+
# config.dynamic_css_map = {
|
82
|
+
# nav_menu_item: {
|
83
|
+
# css_class: 'active',
|
84
|
+
# if: ->(controller, path_fragment) { controller.request.path.end_with?(path_fragment.to_s) }
|
85
|
+
# }
|
86
|
+
# }
|
87
|
+
end
|
88
|
+
|
89
|
+
# Register `app` variable as settings interface
|
90
|
+
Ez::Registry.in(:settings_interfaces, by: 'YourAppName') do |registry|
|
91
|
+
registry.add app
|
92
|
+
end"
|
93
|
+
end
|
94
|
+
|
95
|
+
def create_locale_file
|
96
|
+
create_file "config/locales/ez_settings.en.yml",
|
97
|
+
"en:
|
98
|
+
ez_settings:
|
99
|
+
label: Ez Settings
|
100
|
+
interfaces:
|
101
|
+
app:
|
102
|
+
label: App Settings
|
103
|
+
actions:
|
104
|
+
save:
|
105
|
+
label: Save Settings
|
106
|
+
cancel:
|
107
|
+
label: Cancel Settings
|
108
|
+
groups:
|
109
|
+
general:
|
110
|
+
label: General
|
111
|
+
admin:
|
112
|
+
label: Admin
|
113
|
+
showcase:
|
114
|
+
label: Showcase
|
115
|
+
keys:
|
116
|
+
string:
|
117
|
+
label: String
|
118
|
+
bool:
|
119
|
+
label: Bool
|
120
|
+
integer:
|
121
|
+
label: Integer
|
122
|
+
select:
|
123
|
+
label: Select
|
124
|
+
not_validate:
|
125
|
+
label: Not Validate
|
126
|
+
not_for_ui:
|
127
|
+
label: Not For UI
|
128
|
+
"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ez-settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Volodya Sveredyuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ez-core
|
@@ -192,6 +192,20 @@ dependencies:
|
|
192
192
|
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: generator_spec
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
195
209
|
description: Easy settings engine for Rails app.
|
196
210
|
email:
|
197
211
|
- sveredyuk@gmail.com
|