configurable_engine 0.4.7 → 2.0.1

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
- SHA1:
3
- metadata.gz: 42b345dc60ccd203b5e50caa3a5c626d3db7b850
4
- data.tar.gz: f5cdc2bbefe5017c78db8ccb644da9daa7db638b
2
+ SHA256:
3
+ metadata.gz: 052c84d5fd01f589b20d96f859db8e9472ccc006e65e1169cfa856821d99c505
4
+ data.tar.gz: 0cad323593bc477cc75fdf4e5688b32bdc40f37f378bc87812944e2a3dac76f1
5
5
  SHA512:
6
- metadata.gz: 42b929c5021f20fa1eac5d5499007d077dad5148ab7928d2d2afc1cfdb7088011053c903faa2bba52842c7b4d85584ad175d366f0c64765f9c0d4e25e7c86e61
7
- data.tar.gz: 943f8e63591d88a8d21d9cd964bea594218999a2513f62027af6da1afb01bb400a862cc5ad05ad777765391b96e4f7aab221beea090b721dc9a56d69fbd25f74
6
+ metadata.gz: e49206f97f2db7ac059b4e9999d7de7e7d45aaebba6f16c3d41befdbf97ab6fba031149d5513cbc2c09d45db661f2703d39835d14713ccfac34fb668cb2950c6
7
+ data.tar.gz: 61f85de5aa43479682c21777d3b6929fb38f1a667dc94359de380c9622ada73676c9067ac594cc3ec2d4026bee5e210abc19bb4745687d0101c6137ed2d85963
@@ -1,3 +1,33 @@
1
+ ### v2.0.0 - August 20, 2020
2
+ **bug fixes**
3
+ Can render layout of parent application
4
+
5
+ ### v2.0.0 - August 20, 2020
6
+ **features**
7
+ Configurable_Engine is mountable. This allows folks to use it with a catch-all route
8
+
9
+ **breaking changes**
10
+ Existing users must add `mount ConfigurableEngine::Engine, at: "/admin/configurable"` to their routes.rb. Routing helpers may not work as they used to.
11
+
12
+ ### v1.0.0 - August 20, 2020
13
+ **features**
14
+ Official rails 5.2 support
15
+
16
+ **breaking changes**
17
+ No further support for rails < 5.2
18
+
19
+ ### v0.5.0 - August 3, 2018
20
+ **features**
21
+ Official rails 4.2 support (Thanks @ento)
22
+
23
+ **breaking changes**
24
+ No further support for rails < 4.2, and non-mri rubies. Happy to accept those back as PRs!
25
+
26
+
27
+ ### v0.4.8 - March 4, 2015
28
+ **bug fix**
29
+ Cacheing was just totally broken. Whoops! (thanks, @antoshalee)
30
+
1
31
  ### v0.4.7 - November 4, 2014
2
32
  **bug fix**
3
33
  Configurable broke for users using cacheing.
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:
@@ -58,7 +64,7 @@ and include `ConfigurableEngine::ConfigurablesController`, eg.
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
@@ -100,16 +106,50 @@ Price:
100
106
  type: decimal # coerces the value to a decimal
101
107
  ```
102
108
 
103
- ## Cacheing ##
109
+ ## Caching ##
104
110
 
105
111
  If you want to use rails caching of Configurable updates, simply set
106
112
 
107
-
108
113
  ```ruby
109
114
  config.use_cache = true
110
115
  ```
116
+
111
117
  in your `config/application.rb` (or `config/production.rb`)
112
118
 
119
+ ## Styling the interface ##
120
+
121
+ 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:
122
+
123
+ ```
124
+ @import 'bootstrap';
125
+
126
+ .configurable-container {
127
+ @extend .col-md-6;
128
+
129
+ .configurable-options {
130
+ form {
131
+ @extend .form-horizontal;
132
+
133
+ .configurable {
134
+ @extend .col-md-12;
135
+ @extend .form-group;
136
+
137
+ textarea, input[type=text], input[type=password] {
138
+ @extend .form-control;
139
+ }
140
+ }
141
+
142
+ input[type=submit] {
143
+ @extend .btn;
144
+ @extend .btn-primary;
145
+ }
146
+ }
147
+ }
148
+ }
149
+ ```
150
+
151
+ Just save this into your rails assets and you're ready to go.
152
+
113
153
  ## Running the Tests ##
114
154
 
115
155
  The tests for this rails engine are in the `spec` and `features` directories. They use the dummy rails app in `spec/dummy`
@@ -130,4 +170,3 @@ All contributions are welcome. Just fork the code, ensure your changes include a
130
170
 
131
171
  Copyright (c) 2011 Paul Campbell. See LICENSE.txt for
132
172
  further details.
133
-
@@ -0,0 +1,10 @@
1
+ module ConfigurableEngine
2
+ class ConfigurablesController < ApplicationController
3
+ # this allows us to render url_helpers from parent app's layout
4
+ helper Rails.application.routes.url_helpers
5
+ # this ensures our local routes override any parent routes
6
+ helper ConfigurableEngine::Engine.routes.url_helpers
7
+
8
+ include ConfigurableEngine::ConfigurablesControllerMethods
9
+ end
10
+ 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
 
@@ -51,7 +53,7 @@ class Configurable < ActiveRecord::Base
51
53
  else
52
54
  database_finder.call
53
55
  if found
54
- Rails.cache.store cache_key(key), value
56
+ Rails.cache.write cache_key(key), value
55
57
  end
56
58
  end
57
59
  else
@@ -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,31 @@
1
+ <div class='configurable-container'>
2
+
3
+ <div class="header">
4
+ <h2>Config</h2>
5
+ </div>
6
+
7
+ <div class="configurable-options">
8
+ <%= form_tag(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>
26
+ <%- end -%>
27
+
28
+ <%= submit_tag 'Save' %>
29
+ <%- end -%>
30
+ </div>
31
+ </div>
@@ -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: '/'
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,5 +1,5 @@
1
1
  module ConfigurableEngine
2
- module ConfigurablesController
2
+ module ConfigurablesControllerMethods
3
3
  def show
4
4
  @keys = Configurable.keys
5
5
  end
@@ -15,11 +15,11 @@ module ConfigurableEngine
15
15
  end
16
16
 
17
17
  if failures.empty?
18
- redirect_to admin_configurable_path, :notice => "Changes successfully updated"
18
+ redirect_to configurable_path, :notice => "Changes successfully updated"
19
19
  else
20
20
  flash[:error] = failures.flat_map(&:errors).flat_map(&:full_messages).join(',')
21
- redirect_to admin_configurable_path
21
+ redirect_to configurable_path
22
22
  end
23
23
  end
24
24
  end
25
- end
25
+ 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.7'
3
- end
2
+ VERSION = '2.0.1'
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"'
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.7
4
+ version: 2.0.1
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: 2014-11-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,12 @@ 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/configurables_controller.rb
42
42
  - app/models/configurable.rb
43
- - app/views/admin/configurables/show.html.erb
43
+ - app/views/configurable_engine/configurables/show.html.erb
44
44
  - config/routes.rb
45
45
  - lib/configurable_engine.rb
46
- - lib/configurable_engine/configurables_controller.rb
46
+ - lib/configurable_engine/configurables_controller_methods.rb
47
47
  - lib/configurable_engine/engine.rb
48
48
  - lib/configurable_engine/version.rb
49
49
  - lib/generators/configurable_engine/install_generator.rb
@@ -53,7 +53,7 @@ homepage: http://github.com/paulca/configurable_engine
53
53
  licenses:
54
54
  - MIT
55
55
  metadata: {}
56
- post_install_message:
56
+ post_install_message:
57
57
  rdoc_options: []
58
58
  require_paths:
59
59
  - lib
@@ -68,9 +68,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  requirements: []
71
- rubyforge_project:
72
- rubygems_version: 2.4.2
73
- signing_key:
71
+ rubygems_version: 3.0.3
72
+ signing_key:
74
73
  specification_version: 4
75
- summary: Database-backed configuration for Rails 3, with defaults from config file.
74
+ summary: Database-backed configuration for Rails 4, with defaults from config file.
76
75
  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 -%>