configurable_engine 0.4.8 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +8 -0
- data/README.md +40 -7
- data/app/models/configurable.rb +15 -1
- data/app/views/admin/configurables/show.html.erb +29 -22
- data/lib/configurable_engine/version.rb +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5c5eba98b409a2a2af65b0b19578d651314496430ad5173b83961f78a10a9d2d
|
4
|
+
data.tar.gz: aaeb232e4b42c0a5882e1a3a881a919fccc9b31e4564dbc425ff1077621bb785
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4e7b9738c1468b45080116d430cba876f1b909cf35214a558f26c61da719e8a57dbef56f080809caafac75012102c19e0f62b3fffcabbda440b36ae3a36affb
|
7
|
+
data.tar.gz: 1aca46140fd086919a36d8d38de61e5603a131ec574e9e1ccb579d23a4d3a89fa975980d18d80cfcd36f011311977ee978086879e5a0e640538c28213569880a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
### v0.5.0 - August 3, 2018
|
2
|
+
**features**
|
3
|
+
Official rails 4.2 support (Thanks @ento)
|
4
|
+
|
5
|
+
**breaking changes**
|
6
|
+
No further support for rails < 4.2, and non-mri rubies. Happy to accept those back as PRs!
|
7
|
+
|
8
|
+
|
1
9
|
### v0.4.8 - March 4, 2015
|
2
10
|
**bug fix**
|
3
11
|
Cacheing was just totally broken. Whoops! (thanks, @antoshalee)
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Configurable [![Build Status](https://travis-ci.org/paulca/configurable_engine.png?branch=master)](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'
|
@@ -24,9 +24,9 @@ $ rails generate configurable_engine:install
|
|
24
24
|
|
25
25
|
## Usage ##
|
26
26
|
|
27
|
-
There are two parts to how configurable_engine works. First of all there is a config file, config/configurable.yml
|
27
|
+
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
28
|
|
29
|
-
For example, if you wanted to have access to a config variable
|
29
|
+
For example, if you wanted to have access to a config variable `site_title`, put this in `configurable.yml`:
|
30
30
|
|
31
31
|
```yaml
|
32
32
|
site_title:
|
@@ -100,16 +100,50 @@ Price:
|
|
100
100
|
type: decimal # coerces the value to a decimal
|
101
101
|
```
|
102
102
|
|
103
|
-
##
|
103
|
+
## Caching ##
|
104
104
|
|
105
105
|
If you want to use rails caching of Configurable updates, simply set
|
106
106
|
|
107
|
-
|
108
107
|
```ruby
|
109
108
|
config.use_cache = true
|
110
109
|
```
|
110
|
+
|
111
111
|
in your `config/application.rb` (or `config/production.rb`)
|
112
112
|
|
113
|
+
## Styling the interface ##
|
114
|
+
|
115
|
+
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:
|
116
|
+
|
117
|
+
```
|
118
|
+
@import 'bootstrap';
|
119
|
+
|
120
|
+
.configurable-container {
|
121
|
+
@extend .col-md-6;
|
122
|
+
|
123
|
+
.configurable-options {
|
124
|
+
form {
|
125
|
+
@extend .form-horizontal;
|
126
|
+
|
127
|
+
.configurable {
|
128
|
+
@extend .col-md-12;
|
129
|
+
@extend .form-group;
|
130
|
+
|
131
|
+
textarea, input[type=text], input[type=password] {
|
132
|
+
@extend .form-control;
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
input[type=submit] {
|
137
|
+
@extend .btn;
|
138
|
+
@extend .btn-primary;
|
139
|
+
}
|
140
|
+
}
|
141
|
+
}
|
142
|
+
}
|
143
|
+
```
|
144
|
+
|
145
|
+
Just save this into your rails assets and you're ready to go.
|
146
|
+
|
113
147
|
## Running the Tests ##
|
114
148
|
|
115
149
|
The tests for this rails engine are in the `spec` and `features` directories. They use the dummy rails app in `spec/dummy`
|
@@ -130,4 +164,3 @@ All contributions are welcome. Just fork the code, ensure your changes include a
|
|
130
164
|
|
131
165
|
Copyright (c) 2011 Paul Campbell. See LICENSE.txt for
|
132
166
|
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
|
|
@@ -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
|
@@ -1,24 +1,31 @@
|
|
1
|
-
<
|
1
|
+
<div class='configurable-container'>
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
3
|
+
<div class="header">
|
4
|
+
<h2>Config</h2>
|
5
|
+
</div>
|
6
|
+
|
7
|
+
<div class="configurable-options">
|
8
|
+
<%= form_tag(admin_configurable_path, :method => :put) do -%>
|
9
|
+
<%- @keys.each do |key| -%>
|
10
|
+
<%- options = Configurable.defaults[key] -%>
|
11
|
+
<div class="configurable">
|
12
|
+
<%= label_tag key, options[:name] %>
|
13
|
+
<%- if options[:type] == 'boolean' %>
|
14
|
+
<%= hidden_field_tag key, "0" %>
|
15
|
+
<%= check_box_tag key, "1", Configurable.send(key) %>
|
16
|
+
<%- elsif options[:type] == 'password' -%>
|
17
|
+
<%= password_field_tag key, Configurable.send(key) %>
|
18
|
+
<%- elsif options[:type] == 'text' -%>
|
19
|
+
<%= text_area_tag key, Configurable.send(key) %>
|
20
|
+
<%- elsif options[:type] == 'list' -%>
|
21
|
+
<%= text_area_tag key, Configurable.serialized_value(key) -%>
|
22
|
+
<%- else -%>
|
23
|
+
<%= text_field_tag key, Configurable.send(key) %>
|
24
|
+
<%- end -%>
|
25
|
+
</div>
|
19
26
|
<%- end -%>
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
27
|
+
|
28
|
+
<%= submit_tag 'Save' %>
|
29
|
+
<%- end -%>
|
30
|
+
</div>
|
31
|
+
</div>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configurable_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Campbell
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2018-08-03 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: 4.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: 4.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: []
|
@@ -69,8 +69,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
69
|
version: '0'
|
70
70
|
requirements: []
|
71
71
|
rubyforge_project:
|
72
|
-
rubygems_version: 2.
|
72
|
+
rubygems_version: 2.7.6
|
73
73
|
signing_key:
|
74
74
|
specification_version: 4
|
75
|
-
summary: Database-backed configuration for Rails
|
75
|
+
summary: Database-backed configuration for Rails 4, with defaults from config file.
|
76
76
|
test_files: []
|