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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fa9a553b5686f2be89941fb0d8662cdd9c12d030
4
- data.tar.gz: 0ac4f3f329a280a57747250eddc73f965fe3d221
2
+ SHA256:
3
+ metadata.gz: 35d8e042be21d9ecc3832fcf236bec6145e58ee6a545185121cda190f26a935e
4
+ data.tar.gz: 5d3619555b52de54a69da528aec0e92a9b5911425ea06f244a01082e6cfd588d
5
5
  SHA512:
6
- metadata.gz: 240d819eb7f2c6caaee975de94b372b705a6bb97a0e506c187ae59b68bc49a1d9b412b633726d994f389eee16ff79b5136b70cacf26f6e35dcc7bb0223eaae9c
7
- data.tar.gz: a6341025e1c7cc59c19dfcbb66755f6ea55c0e19b9e0c92eff8e453ca43291233f0ce0da33a339863a424359af8cc5f9a3ba41efca59dc6a974611eb455ffa71
6
+ metadata.gz: ebc8c63d1ea3ac3722dd7632ab38ecba3cd60dd0b2a23b6595f9905e7aaa947aa8b069f0f8de5e0f275ca69cd09b786ee9f866aba82c6c7672f02f937116bdaf
7
+ data.tar.gz: b09227577c08b4e35523d134dbf7dbeff3ff2c1c45f6f01c536985c446239ec2ee8ee39b8c649e334c4bd9ee5a3a165a85b3c3fbdabbc2332fba4cbb2aec7f5e
@@ -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 [![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/4 configuration engine. An update to [Behavior](http://github.com/paulca/behavior) for Rails 3 and 4.
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 3 app's `Gemfile`:
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. This file controls the variables that are allowed to be set in the app.
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 "site_title", put this in configurable.yml:
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
- and include `ConfigurableEngine::ConfigurablesController`, eg.
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::ConfigurablesController
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
- ## Cacheing ##
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
-
@@ -0,0 +1,6 @@
1
+ module ConfigurableEngine
2
+ class ApplicationController < ActionController::Base
3
+ layout "configurable_engine/application"
4
+ protect_from_forgery with: :exception
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module ConfigurableEngine
2
+ class ConfigurablesController < ::ConfigurableEngine::ApplicationController
3
+ include ConfigurableEngine::ConfigurablesControllerMethods
4
+ end
5
+ end
@@ -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 key, defaults[key][:default]
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.new(value.to_s)
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>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Configurable engine</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+ </head>
8
+ <body>
9
+
10
+ <%= yield %>
11
+
12
+ </body>
13
+ </html>
@@ -1,5 +1,3 @@
1
- Rails.application.routes.draw do
2
- namespace :admin do
3
- resource :configurable
4
- end
5
- end
1
+ ConfigurableEngine::Engine.routes.draw do
2
+ resource :configurable, path: '/', only: [:show, :update]
3
+ end
@@ -1,2 +1,2 @@
1
1
  require 'configurable_engine/engine'
2
- require 'configurable_engine/configurables_controller'
2
+ require 'configurable_engine/configurables_controller_methods'
@@ -1,7 +1,8 @@
1
1
  module ConfigurableEngine
2
- module ConfigurablesController
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 admin_configurable_path, :notice => "Changes successfully updated"
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 admin_configurable_path
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
@@ -1,3 +1,3 @@
1
1
  module ConfigurableEngine
2
- VERSION = '0.4.8'
2
+ VERSION = '2.0.2'
3
3
  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.8
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: 2015-03-04 00:00:00.000000000 Z
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: 3.1.0
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: 3.1.0
28
- description: 'Configurable is a Rails 3/4 engine that allows you to set up config
29
- variables in a config file, specifying default values for all environmentspec. These
30
- variables can then be set on a per-app basis using a user facing configuration screen. '
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/admin/configurables_controller.rb
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/admin/configurables/show.html.erb
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/configurables_controller.rb
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
- rubyforge_project:
72
- rubygems_version: 2.4.2
73
- signing_key:
73
+ rubygems_version: 3.0.3
74
+ signing_key:
74
75
  specification_version: 4
75
- summary: Database-backed configuration for Rails 3, with defaults from config file.
76
+ summary: Database-backed configuration for Rails 4, with defaults from config file.
76
77
  test_files: []
@@ -1,3 +0,0 @@
1
- class Admin::ConfigurablesController < ApplicationController
2
- include ConfigurableEngine::ConfigurablesController
3
- end
@@ -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 -%>