configurable_engine 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -12
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/configurable_engine.gemspec +6 -2
- data/lib/configurable_engine.rb +4 -0
- data/lib/generators/configurable_engine/install_generator.rb +24 -0
- data/lib/generators/configurable_engine/templates/configurable.yml +33 -0
- data/lib/generators/configurable_engine/templates/migration.rb +17 -0
- metadata +7 -3
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Configurable #
|
2
2
|
|
3
|
-
A Rails 3 configuration
|
3
|
+
A Rails 3 configuration engine. An update to [Behavior](http://github.com/paulca/behavior) for Rails 3.
|
4
4
|
|
5
5
|
## How it works ##
|
6
6
|
|
@@ -12,31 +12,31 @@ If you or your app users need to change these variables, Configurable stores new
|
|
12
12
|
|
13
13
|
Configurable is available as a Ruby gem. Simply add it to your Rails 3 app's `Gemfile`:
|
14
14
|
|
15
|
-
gem '
|
15
|
+
gem 'configurable_engine'
|
16
16
|
|
17
17
|
Then run the `configurable_engine:install` generator:
|
18
18
|
|
19
|
-
rails generate
|
19
|
+
rails generate configurable_engine:install
|
20
20
|
|
21
21
|
## Usage ##
|
22
22
|
|
23
|
-
There are two parts to how behavior works. First of all there is a config file, config/
|
23
|
+
There are two parts to how behavior 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.
|
24
24
|
|
25
|
-
For example, if you wanted to have access to a config variable "site_title", put this in
|
25
|
+
For example, if you wanted to have access to a config variable "site_title", put this in configurable.yml:
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
site_title:
|
28
|
+
name: Site Title
|
29
|
+
default: My Site
|
30
30
|
|
31
|
-
Now, within your app, you can access `Configurable[:
|
31
|
+
Now, within your app, you can access `Configurable[:site_title]` (or `Configurable.site_title` if you prefer).
|
32
32
|
|
33
|
-
|
33
|
+
Since Configurable is an ActiveRecord model, if you want to update the config, create a Configurable record in the database:
|
34
34
|
|
35
35
|
Configurable.create!(:name => 'site_title', :value => 'My New Site')
|
36
36
|
|
37
37
|
## Web Interface ##
|
38
38
|
|
39
|
-
|
39
|
+
Configurable comes with a web interface that is available to your app straight away at `http://localhost:3000/admin/configurable`.
|
40
40
|
|
41
41
|
If you want to add a layout, or protect the configurable controller, create `app/controllers/admin/application_controller.rb` which would look something like this:
|
42
42
|
|
@@ -83,7 +83,11 @@ Within the `dummy` folder, run:
|
|
83
83
|
bundle exec rspec spec
|
84
84
|
bundle exec cucumber features
|
85
85
|
|
86
|
-
|
86
|
+
## Contributing ##
|
87
|
+
|
88
|
+
All contributions are welcome. Just fork the code, ensure your changes include a test, ensure all the current tests pass and send a pull request.
|
89
|
+
|
90
|
+
## Copyright ##
|
87
91
|
|
88
92
|
Copyright (c) 2011 Paul Campbell. See LICENSE.txt for
|
89
93
|
further details.
|
data/Rakefile
CHANGED
@@ -22,7 +22,7 @@ Jeweler::Tasks.new do |gem|
|
|
22
22
|
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
23
|
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
24
|
gem.add_runtime_dependency 'rails', '~>3.0.0'
|
25
|
-
gem.files = FileList["[A-Za-z]*", "app/**/*", "config/*"]
|
25
|
+
gem.files = FileList["[A-Za-z]*", "lib/**/*", "app/**/*", "config/*"]
|
26
26
|
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
27
27
|
end
|
28
28
|
Jeweler::RubygemsDotOrgTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/configurable_engine.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{configurable_engine}
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Paul Campbell"]
|
@@ -28,7 +28,11 @@ Gem::Specification.new do |s|
|
|
28
28
|
"app/models/configurable.rb",
|
29
29
|
"app/views/admin/configurables/show.html.erb",
|
30
30
|
"config/routes.rb",
|
31
|
-
"configurable_engine.gemspec"
|
31
|
+
"configurable_engine.gemspec",
|
32
|
+
"lib/configurable_engine.rb",
|
33
|
+
"lib/generators/configurable_engine/install_generator.rb",
|
34
|
+
"lib/generators/configurable_engine/templates/configurable.yml",
|
35
|
+
"lib/generators/configurable_engine/templates/migration.rb"
|
32
36
|
]
|
33
37
|
s.homepage = %q{http://github.com/paulca/configurable_engine}
|
34
38
|
s.licenses = ["MIT"]
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
module Configurable
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
|
6
|
+
|
7
|
+
def self.source_root
|
8
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.next_migration_number(dirname)
|
12
|
+
if ActiveRecord::Base.timestamped_migrations
|
13
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
14
|
+
else
|
15
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_migration_file
|
20
|
+
copy_file 'configurable.yml', 'config/configurable.yml'
|
21
|
+
migration_template 'migration.rb', 'db/migrate/create_configurables.rb'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# This file controls what config variables you want to be able to allow your users
|
2
|
+
# to set, as well as those you'll be able to access from within the application.
|
3
|
+
#
|
4
|
+
# If you want to be able to access a string config[:site_title], for example:
|
5
|
+
#
|
6
|
+
# site_title:
|
7
|
+
# name: Site Title
|
8
|
+
# type: string
|
9
|
+
# default: My Site
|
10
|
+
#
|
11
|
+
# 'name' is the name that appears in the edit form
|
12
|
+
#
|
13
|
+
# 'type' can be 'string' for a text field, 'password' for a password field or 'text' for a text area
|
14
|
+
# 'type' defaults to 'string'
|
15
|
+
#
|
16
|
+
# 'default' is the default value to use if there's no entry in the database. Otherwise, nil will be returned
|
17
|
+
#
|
18
|
+
# Some Examples:
|
19
|
+
#
|
20
|
+
# site_title:
|
21
|
+
# name: Site Title
|
22
|
+
# default: My Site
|
23
|
+
# type: string
|
24
|
+
#
|
25
|
+
# site_description:
|
26
|
+
# name: Description for Google
|
27
|
+
# default: Lots of Awesomeness Here
|
28
|
+
# type: text
|
29
|
+
#
|
30
|
+
# secret:
|
31
|
+
# name: Secret Password for Accessing Secret Areas
|
32
|
+
# default: secret
|
33
|
+
# type: password
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateConfigurables < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :configurables do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :value
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index :configurables, :name
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
remove_index :configurables, :name
|
15
|
+
drop_table :configurables
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
- 0
|
8
7
|
- 1
|
9
|
-
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Paul Campbell
|
@@ -106,6 +106,10 @@ files:
|
|
106
106
|
- app/views/admin/configurables/show.html.erb
|
107
107
|
- config/routes.rb
|
108
108
|
- configurable_engine.gemspec
|
109
|
+
- lib/configurable_engine.rb
|
110
|
+
- lib/generators/configurable_engine/install_generator.rb
|
111
|
+
- lib/generators/configurable_engine/templates/configurable.yml
|
112
|
+
- lib/generators/configurable_engine/templates/migration.rb
|
109
113
|
has_rdoc: true
|
110
114
|
homepage: http://github.com/paulca/configurable_engine
|
111
115
|
licenses:
|
@@ -120,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
124
|
requirements:
|
121
125
|
- - ">="
|
122
126
|
- !ruby/object:Gem::Version
|
123
|
-
hash:
|
127
|
+
hash: 2354103642827299759
|
124
128
|
segments:
|
125
129
|
- 0
|
126
130
|
version: "0"
|