configurable_engine 0.4.8 → 2.0.2
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 +5 -5
- data/CHANGELOG.md +30 -0
- data/README.md +61 -9
- data/app/controllers/configurable_engine/application_controller.rb +6 -0
- data/app/controllers/configurable_engine/configurables_controller.rb +5 -0
- data/app/models/configurable.rb +16 -2
- data/app/views/configurable_engine/configurables/show.html.erb +30 -0
- data/app/views/layouts/configurable_engine/application.html.erb +13 -0
- data/config/routes.rb +3 -5
- data/lib/configurable_engine.rb +1 -1
- data/lib/configurable_engine/{configurables_controller.rb → configurables_controller_methods.rb} +5 -4
- data/lib/configurable_engine/engine.rb +4 -2
- data/lib/configurable_engine/version.rb +1 -1
- data/lib/generators/configurable_engine/install_generator.rb +5 -1
- data/lib/generators/configurable_engine/templates/migration.rb +2 -2
- metadata +17 -16
- data/app/controllers/admin/configurables_controller.rb +0 -3
- data/app/views/admin/configurables/show.html.erb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 35d8e042be21d9ecc3832fcf236bec6145e58ee6a545185121cda190f26a935e
|
4
|
+
data.tar.gz: 5d3619555b52de54a69da528aec0e92a9b5911425ea06f244a01082e6cfd588d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebc8c63d1ea3ac3722dd7632ab38ecba3cd60dd0b2a23b6595f9905e7aaa947aa8b069f0f8de5e0f275ca69cd09b786ee9f866aba82c6c7672f02f937116bdaf
|
7
|
+
data.tar.gz: b09227577c08b4e35523d134dbf7dbeff3ff2c1c45f6f01c536985c446239ec2ee8ee39b8c649e334c4bd9ee5a3a165a85b3c3fbdabbc2332fba4cbb2aec7f5e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,33 @@
|
|
1
|
+
### v2.0.2 - August 20, 2020
|
2
|
+
**bug fixes**
|
3
|
+
fix rendering with included module
|
4
|
+
|
5
|
+
### v2.0.1 - August 20, 2020
|
6
|
+
**bug fixes**
|
7
|
+
Can render layout of parent application
|
8
|
+
|
9
|
+
### v2.0.0 - August 20, 2020
|
10
|
+
**features**
|
11
|
+
Configurable_Engine is mountable. This allows folks to use it with a catch-all route
|
12
|
+
|
13
|
+
**breaking changes**
|
14
|
+
Existing users must add `mount ConfigurableEngine::Engine, at: "/admin/configurable"` to their routes.rb. Routing helpers may not work as they used to.
|
15
|
+
|
16
|
+
### v1.0.0 - August 20, 2020
|
17
|
+
**features**
|
18
|
+
Official rails 5.2 support
|
19
|
+
|
20
|
+
**breaking changes**
|
21
|
+
No further support for rails < 5.2
|
22
|
+
|
23
|
+
### v0.5.0 - August 3, 2018
|
24
|
+
**features**
|
25
|
+
Official rails 4.2 support (Thanks @ento)
|
26
|
+
|
27
|
+
**breaking changes**
|
28
|
+
No further support for rails < 4.2, and non-mri rubies. Happy to accept those back as PRs!
|
29
|
+
|
30
|
+
|
1
31
|
### v0.4.8 - March 4, 2015
|
2
32
|
**bug fix**
|
3
33
|
Cacheing was just totally broken. Whoops! (thanks, @antoshalee)
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Configurable [](https://travis-ci.org/paulca/configurable_engine)
|
2
2
|
|
3
|
-
A Rails
|
3
|
+
A Rails 4 configuration engine. An update to [Behavior](http://github.com/paulca/behavior) for Rails 4.
|
4
4
|
|
5
5
|
## How it works ##
|
6
6
|
|
@@ -10,7 +10,7 @@ If you or your app users need to change these variables, Configurable stores new
|
|
10
10
|
|
11
11
|
## Installation ##
|
12
12
|
|
13
|
-
Configurable is available as a Ruby gem. Simply add it to your Rails
|
13
|
+
Configurable is available as a Ruby gem. Simply add it to your Rails 4 app's `Gemfile`:
|
14
14
|
|
15
15
|
```ruby
|
16
16
|
gem 'configurable_engine'
|
@@ -22,11 +22,17 @@ Then run the `configurable_engine:install` generator:
|
|
22
22
|
$ rails generate configurable_engine:install
|
23
23
|
```
|
24
24
|
|
25
|
+
this will
|
26
|
+
- add config/configurable.yml
|
27
|
+
- create a migration for your configurable table
|
28
|
+
- mount the UI in your routes (defaulting to admin/configurables)
|
29
|
+
|
30
|
+
|
25
31
|
## Usage ##
|
26
32
|
|
27
|
-
There are two parts to how configurable_engine works. First of all there is a config file, config/configurable.yml
|
33
|
+
There are two parts to how configurable_engine works. First of all there is a config file, `config/configurable.yml`. This file controls the variables that are allowed to be set in the app.
|
28
34
|
|
29
|
-
For example, if you wanted to have access to a config variable
|
35
|
+
For example, if you wanted to have access to a config variable `site_title`, put this in `configurable.yml`:
|
30
36
|
|
31
37
|
```yaml
|
32
38
|
site_title:
|
@@ -53,12 +59,12 @@ If you want to add a layout, or protect the configurable controller, create `app
|
|
53
59
|
$ bundle exec rails generate controller admin/configurables
|
54
60
|
```
|
55
61
|
|
56
|
-
|
62
|
+
include `ConfigurableEngine::ConfigurablesController`, eg.
|
57
63
|
|
58
64
|
```ruby
|
59
65
|
class Admin::ConfigurablesController < ApplicationController
|
60
66
|
# include the engine controller actions
|
61
|
-
include ConfigurableEngine::
|
67
|
+
include ConfigurableEngine::ConfigurablesControllerMethods
|
62
68
|
|
63
69
|
# add your own filter(s) / layout
|
64
70
|
before_filter :protect_my_code
|
@@ -66,6 +72,19 @@ class Admin::ConfigurablesController < ApplicationController
|
|
66
72
|
end
|
67
73
|
```
|
68
74
|
|
75
|
+
and replace
|
76
|
+
```ruby
|
77
|
+
route 'mount ConfigurableEngine::Engine, at: "/admin/configurable", as: "configurable"'
|
78
|
+
```
|
79
|
+
|
80
|
+
with
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
namespace :admin do
|
84
|
+
resource :configurable, only: [:show, :update]
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
69
88
|
To ensure text areas are rendered correctly, ensure that your layout preserves whitespace. In haml, use the `~` operator
|
70
89
|
|
71
90
|
```haml
|
@@ -100,16 +119,50 @@ Price:
|
|
100
119
|
type: decimal # coerces the value to a decimal
|
101
120
|
```
|
102
121
|
|
103
|
-
##
|
122
|
+
## Caching ##
|
104
123
|
|
105
124
|
If you want to use rails caching of Configurable updates, simply set
|
106
125
|
|
107
|
-
|
108
126
|
```ruby
|
109
127
|
config.use_cache = true
|
110
128
|
```
|
129
|
+
|
111
130
|
in your `config/application.rb` (or `config/production.rb`)
|
112
131
|
|
132
|
+
## Styling the interface ##
|
133
|
+
|
134
|
+
To style the web interface you are advised to use Sass. Here's an example scss file that will make the interface bootstrap-3 ready:
|
135
|
+
|
136
|
+
```
|
137
|
+
@import 'bootstrap';
|
138
|
+
|
139
|
+
.configurable-container {
|
140
|
+
@extend .col-md-6;
|
141
|
+
|
142
|
+
.configurable-options {
|
143
|
+
form {
|
144
|
+
@extend .form-horizontal;
|
145
|
+
|
146
|
+
.configurable {
|
147
|
+
@extend .col-md-12;
|
148
|
+
@extend .form-group;
|
149
|
+
|
150
|
+
textarea, input[type=text], input[type=password] {
|
151
|
+
@extend .form-control;
|
152
|
+
}
|
153
|
+
}
|
154
|
+
|
155
|
+
input[type=submit] {
|
156
|
+
@extend .btn;
|
157
|
+
@extend .btn-primary;
|
158
|
+
}
|
159
|
+
}
|
160
|
+
}
|
161
|
+
}
|
162
|
+
```
|
163
|
+
|
164
|
+
Just save this into your rails assets and you're ready to go.
|
165
|
+
|
113
166
|
## Running the Tests ##
|
114
167
|
|
115
168
|
The tests for this rails engine are in the `spec` and `features` directories. They use the dummy rails app in `spec/dummy`
|
@@ -130,4 +183,3 @@ All contributions are welcome. Just fork the code, ensure your changes include a
|
|
130
183
|
|
131
184
|
Copyright (c) 2011 Paul Campbell. See LICENSE.txt for
|
132
185
|
further details.
|
133
|
-
|
data/app/models/configurable.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
class Configurable < ActiveRecord::Base
|
2
|
+
serialize :value
|
3
|
+
|
2
4
|
after_save :invalidate_cache, if: -> { ConfigurableEngine::Engine.config.use_cache }
|
3
5
|
after_destroy :invalidate_cache, if: -> { ConfigurableEngine::Engine.config.use_cache }
|
4
6
|
|
@@ -61,7 +63,11 @@ class Configurable < ActiveRecord::Base
|
|
61
63
|
if found
|
62
64
|
value
|
63
65
|
else
|
64
|
-
parse_value
|
66
|
+
parse_value(key, defaults[key][:default]).tap do |val|
|
67
|
+
if ConfigurableEngine::Engine.config.use_cache
|
68
|
+
Rails.cache.write cache_key(key), val
|
69
|
+
end
|
70
|
+
end
|
65
71
|
end
|
66
72
|
end
|
67
73
|
|
@@ -75,7 +81,7 @@ class Configurable < ActiveRecord::Base
|
|
75
81
|
[true, 1, "1", "t", "true"].include?(value)
|
76
82
|
when 'decimal'
|
77
83
|
value ||= 0
|
78
|
-
BigDecimal
|
84
|
+
BigDecimal(value.to_s)
|
79
85
|
when 'integer'
|
80
86
|
value.to_i
|
81
87
|
when 'list'
|
@@ -85,6 +91,12 @@ class Configurable < ActiveRecord::Base
|
|
85
91
|
else
|
86
92
|
value.split("\n").collect { |v| v =~ /,/ ? v.split(',') : v }
|
87
93
|
end
|
94
|
+
when 'date'
|
95
|
+
if value.is_a? Date
|
96
|
+
value
|
97
|
+
else
|
98
|
+
Date.parse(value) if value.present?
|
99
|
+
end
|
88
100
|
else
|
89
101
|
value
|
90
102
|
end
|
@@ -131,6 +143,8 @@ class Configurable < ActiveRecord::Base
|
|
131
143
|
Integer(value) rescue false
|
132
144
|
when 'list'
|
133
145
|
value.is_a?(Array)
|
146
|
+
when 'date'
|
147
|
+
value.is_a?(Date)
|
134
148
|
else
|
135
149
|
true
|
136
150
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<div class='configurable-container'>
|
2
|
+
<div class="header">
|
3
|
+
<h2>Config</h2>
|
4
|
+
</div>
|
5
|
+
|
6
|
+
<div class="configurable-options">
|
7
|
+
<%= form_tag({}, method: :put) do -%>
|
8
|
+
<%- @keys.each do |key| -%>
|
9
|
+
<%- options = Configurable.defaults[key] -%>
|
10
|
+
<div class="configurable">
|
11
|
+
<%= label_tag key, options[:name] %>
|
12
|
+
<%- if options[:type] == 'boolean' %>
|
13
|
+
<%= hidden_field_tag key, "0" %>
|
14
|
+
<%= check_box_tag key, "1", Configurable.send(key) %>
|
15
|
+
<%- elsif options[:type] == 'password' -%>
|
16
|
+
<%= password_field_tag key, Configurable.send(key) %>
|
17
|
+
<%- elsif options[:type] == 'text' -%>
|
18
|
+
<%= text_area_tag key, Configurable.send(key) %>
|
19
|
+
<%- elsif options[:type] == 'list' -%>
|
20
|
+
<%= text_area_tag key, Configurable.serialized_value(key) -%>
|
21
|
+
<%- else -%>
|
22
|
+
<%= text_field_tag key, Configurable.send(key) %>
|
23
|
+
<%- end -%>
|
24
|
+
</div>
|
25
|
+
<%- end -%>
|
26
|
+
|
27
|
+
<%= submit_tag 'Save' %>
|
28
|
+
<%- end -%>
|
29
|
+
</div>
|
30
|
+
</div>
|
data/config/routes.rb
CHANGED
data/lib/configurable_engine.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
require 'configurable_engine/engine'
|
2
|
-
require 'configurable_engine/
|
2
|
+
require 'configurable_engine/configurables_controller_methods'
|
data/lib/configurable_engine/{configurables_controller.rb → configurables_controller_methods.rb}
RENAMED
@@ -1,7 +1,8 @@
|
|
1
1
|
module ConfigurableEngine
|
2
|
-
module
|
2
|
+
module ConfigurablesControllerMethods
|
3
3
|
def show
|
4
4
|
@keys = Configurable.keys
|
5
|
+
render 'configurable_engine/configurables/show'
|
5
6
|
end
|
6
7
|
|
7
8
|
def update
|
@@ -15,11 +16,11 @@ module ConfigurableEngine
|
|
15
16
|
end
|
16
17
|
|
17
18
|
if failures.empty?
|
18
|
-
redirect_to
|
19
|
+
redirect_to(action: :show, :notice => "Changes successfully updated")
|
19
20
|
else
|
20
21
|
flash[:error] = failures.flat_map(&:errors).flat_map(&:full_messages).join(',')
|
21
|
-
redirect_to
|
22
|
+
redirect_to(action: :show)
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
25
|
-
end
|
26
|
+
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
module ConfigurableEngine
|
2
|
-
class Engine < Rails::Engine
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
engine_name "configurable"
|
4
|
+
isolate_namespace ConfigurableEngine
|
3
5
|
config.use_cache = false
|
4
6
|
config.generators do |g|
|
5
7
|
g.test_framework :rspec
|
6
8
|
end
|
7
9
|
end
|
8
|
-
end
|
10
|
+
end
|
@@ -20,5 +20,9 @@ class InstallGenerator < Rails::Generators::Base
|
|
20
20
|
copy_file 'configurable.yml', 'config/configurable.yml'
|
21
21
|
migration_template 'migration.rb', 'db/migrate/create_configurables.rb'
|
22
22
|
end
|
23
|
+
|
24
|
+
def mount_interface
|
25
|
+
route 'mount ConfigurableEngine::Engine, at: "/admin/configurable", as: "configurable"'
|
26
|
+
end
|
23
27
|
end
|
24
|
-
end
|
28
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class CreateConfigurables < ActiveRecord::Migration
|
1
|
+
class CreateConfigurables < ActiveRecord::Migration[5.2]
|
2
2
|
def self.up
|
3
3
|
create_table :configurables do |t|
|
4
4
|
t.string :name
|
@@ -14,4 +14,4 @@ class CreateConfigurables < ActiveRecord::Migration
|
|
14
14
|
remove_index :configurables, :name
|
15
15
|
drop_table :configurables
|
16
16
|
end
|
17
|
-
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configurable_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Campbell
|
8
8
|
- Michael Glass
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-08-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -17,17 +17,17 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 5.2.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ">"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
28
|
-
description: 'Configurable is a Rails
|
29
|
-
|
30
|
-
|
27
|
+
version: 5.2.0
|
28
|
+
description: 'Configurable is a Rails 4 engine that allows you to set up config variables
|
29
|
+
in a config file, specifying default values for all environmentspec. These variables
|
30
|
+
can then be set on a per-app basis using a user facing configuration screen. '
|
31
31
|
email: paul@rslw.com
|
32
32
|
executables: []
|
33
33
|
extensions: []
|
@@ -38,12 +38,14 @@ files:
|
|
38
38
|
- CHANGELOG.md
|
39
39
|
- LICENSE.txt
|
40
40
|
- README.md
|
41
|
-
- app/controllers/
|
41
|
+
- app/controllers/configurable_engine/application_controller.rb
|
42
|
+
- app/controllers/configurable_engine/configurables_controller.rb
|
42
43
|
- app/models/configurable.rb
|
43
|
-
- app/views/
|
44
|
+
- app/views/configurable_engine/configurables/show.html.erb
|
45
|
+
- app/views/layouts/configurable_engine/application.html.erb
|
44
46
|
- config/routes.rb
|
45
47
|
- lib/configurable_engine.rb
|
46
|
-
- lib/configurable_engine/
|
48
|
+
- lib/configurable_engine/configurables_controller_methods.rb
|
47
49
|
- lib/configurable_engine/engine.rb
|
48
50
|
- lib/configurable_engine/version.rb
|
49
51
|
- lib/generators/configurable_engine/install_generator.rb
|
@@ -53,7 +55,7 @@ homepage: http://github.com/paulca/configurable_engine
|
|
53
55
|
licenses:
|
54
56
|
- MIT
|
55
57
|
metadata: {}
|
56
|
-
post_install_message:
|
58
|
+
post_install_message:
|
57
59
|
rdoc_options: []
|
58
60
|
require_paths:
|
59
61
|
- lib
|
@@ -68,9 +70,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
70
|
- !ruby/object:Gem::Version
|
69
71
|
version: '0'
|
70
72
|
requirements: []
|
71
|
-
|
72
|
-
|
73
|
-
signing_key:
|
73
|
+
rubygems_version: 3.0.3
|
74
|
+
signing_key:
|
74
75
|
specification_version: 4
|
75
|
-
summary: Database-backed configuration for Rails
|
76
|
+
summary: Database-backed configuration for Rails 4, with defaults from config file.
|
76
77
|
test_files: []
|
@@ -1,24 +0,0 @@
|
|
1
|
-
<h2>Config</h2>
|
2
|
-
|
3
|
-
<%= form_tag(admin_configurable_path, :method => :put) do -%>
|
4
|
-
<%- @keys.each do |key| -%>
|
5
|
-
<%- options = Configurable.defaults[key] -%>
|
6
|
-
<div class="configurable">
|
7
|
-
<%= label_tag key, options[:name] %>
|
8
|
-
<%- if options[:type] == 'boolean' %>
|
9
|
-
<%= hidden_field_tag key, "0" %>
|
10
|
-
<%= check_box_tag key, "1", Configurable.send(key) %>
|
11
|
-
<%- elsif options[:type] == 'password' -%>
|
12
|
-
<%= password_field_tag key, Configurable.send(key) %>
|
13
|
-
<%- elsif options[:type] == 'text' -%>
|
14
|
-
<%= text_area_tag key, Configurable.send(key) %>
|
15
|
-
<%- elsif options[:type] == 'list' -%>
|
16
|
-
<%= text_area_tag key, Configurable.serialized_value(key) -%>
|
17
|
-
<%- else -%>
|
18
|
-
<%= text_field_tag key, Configurable.send(key) %>
|
19
|
-
<%- end -%>
|
20
|
-
</div>
|
21
|
-
<%- end -%>
|
22
|
-
|
23
|
-
<%= submit_tag 'Save' %>
|
24
|
-
<%- end -%>
|