behavior 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,102 @@
1
+ Behavior
2
+ ========
3
+
4
+ Behavior is a Ruby on Rails plugin for storing application configuration variables in the database. You can use it to store things like a Site's Title, description and keywords, or for user definable things like a currency exchange rate, or minimum and maximum values.
5
+
6
+ The benefits of storing configuration in the database are:
7
+
8
+ - End users can easily edit the values
9
+ - Configuration is decoupled from the codebase
10
+
11
+ This is particularly useful for open source projects, where application settings shouldn't be stored in source code.
12
+
13
+ It's designed to be simple to use and get up and running, and to be flexible in that it's both end user and developer friendly.
14
+
15
+ Although all config variables are ultimately stored in the database, you can set sensible defaults in a configuration file.
16
+
17
+ Installation
18
+ ============
19
+
20
+ Behavior is easy to install.
21
+
22
+ As a plugin:
23
+
24
+ ./script/plugin install git://github.com/paulca/behavior.git
25
+
26
+ Or as a gem. Add this to your environment.rb:
27
+
28
+ config.gem 'behavior'
29
+
30
+ Then generate the migration and sample behavior.yml:
31
+
32
+ ./script/generate behavior
33
+
34
+ And run the migration:
35
+
36
+ rake db:migrate
37
+
38
+ Basic Usage
39
+ ===========
40
+
41
+ There are two parts to how behavior works. First of all there is a config file, `config/behavior.yml`. This file controls the variables that are allowed to be set in the app.
42
+
43
+ For example, if you wanted to have access to a config variable "site_title", put this in behavior.yml:
44
+
45
+ site_title:
46
+ default:
47
+
48
+ Now, within your app controllers and views, you can access `config[:site_title]`. In your models, you can access `Behavior.config[:site_title]`.
49
+
50
+ If you want to update the config, call `config.update(:site_title => "My New Title")`
51
+
52
+ Web Interface
53
+ =============
54
+
55
+ Using Rails' Engines feature, behavior comes with a web interface that is available to your app straight away at `http://localhost:3000/admin/config`.
56
+
57
+ By default, this comes with no styling, but you can create a layout in `app/layouts/admin.html.erb`, or set a layout by setting `Behavior::Setting.layout`
58
+
59
+ For example, to use your standard application layout, create a `config/initializers/behavior.rb` like this:
60
+
61
+ Behavior::Settings.layout = 'application'
62
+
63
+ You can also add before_filters to protect the controller from outsiders:
64
+
65
+ Behavior::Settings.before_filters << 'require_admin_user'
66
+
67
+ If you want to control how the fields in the admin interface appear, you can add additional params in your behavior.yml file:
68
+
69
+ site_title:
70
+ name: Name of Your Site # sets the edit label
71
+ default: My Site # sets the default value
72
+ type: string # uses input type="text"
73
+
74
+ site_description:
75
+ name: Describe Your Site # sets the edit label
76
+ default: My Site # sets the default value
77
+ type: text # uses textarea
78
+
79
+ secret:
80
+ name: A Secret Passphrase # sets the edit label
81
+ default: passpass # sets the default value
82
+ type: password # uses input type="password"
83
+
84
+ Running the tests
85
+ =================
86
+
87
+ You can run the tests by checking out the code into vendor/plugins of a Rails app and running:
88
+
89
+ rake
90
+
91
+ It also comes with a set of cucumber features:
92
+
93
+ cucumber
94
+
95
+ About me
96
+ ========
97
+
98
+ I'm Paul Campbell. I'm an avid Ruby on Rails web developer. Follow my ramblings at [http://www.pabcas.com](http://www.pabcas.com)
99
+
100
+ Follow me on Twitter [http://twitter.com/paulca](http://twitter.com/paulca)
101
+
102
+ Copyright (c) 2009 Paul Campbell, released under the MIT license
data/Rakefile CHANGED
@@ -25,7 +25,7 @@ begin
25
25
  require 'jeweler'
26
26
  Jeweler::Tasks.new do |s|
27
27
  s.name = "behavior"
28
- s.version = "0.1.0"
28
+ s.version = "0.1.1"
29
29
  s.author = "Paul Campbell"
30
30
  s.email = "paul@rslw.com"
31
31
  s.homepage = "http://www.github.com/paulca/behavior"
@@ -1,11 +1,5 @@
1
1
  <h2>Edit Configuration</h2>
2
2
 
3
- <%- if !flash[:notice].blank? -%>
4
- <div class="notice">
5
- <%= flash[:notice] %>
6
- </div>
7
- <%- end -%>
8
-
9
3
  <%- form_tag admin_config_path, :method => :put do -%>
10
4
 
11
5
  <fieldset>
@@ -6,6 +6,12 @@
6
6
 
7
7
  <body>
8
8
  <h1>Site Admin</h1>
9
+ <%- if !flash[:notice].blank? -%>
10
+ <div class="notice">
11
+ <%= flash[:notice] %>
12
+ </div>
13
+ <%- end -%>
14
+
9
15
  <%= yield %>
10
16
  </body>
11
17
  </html>
data/behavior.gemspec CHANGED
@@ -5,17 +5,14 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{behavior}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
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"]
12
12
  s.date = %q{2009-12-11}
13
13
  s.email = %q{paul@rslw.com}
14
- s.extra_rdoc_files = [
15
- "README.textile"
16
- ]
17
14
  s.files = [
18
- "README.textile",
15
+ "README.md",
19
16
  "Rakefile",
20
17
  "app/controllers/admin/configs_controller.rb",
21
18
  "app/helpers/behavior_helper.rb",
data/spec/debug.log CHANGED
@@ -1729,3 +1729,95 @@
1729
1729
  BehaviorConfig Load (0.2ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."key" = 'email_name') LIMIT 1
1730
1730
  BehaviorConfig Load (0.2ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."key" = 'password') LIMIT 1
1731
1731
  BehaviorConfig Load (0.1ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."key" = 'description') LIMIT 1
1732
+ SQL (0.2ms) select sqlite_version(*)
1733
+ SQL (0.3ms)  SELECT name
1734
+ FROM sqlite_master
1735
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
1736
+ 
1737
+ SQL (2.7ms) DROP TABLE "behavior_configs"
1738
+ SQL (1.7ms) CREATE TABLE "behavior_configs" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "key" varchar(255), "value" varchar(255)) 
1739
+ SQL (0.2ms)  SELECT name
1740
+ FROM sqlite_master
1741
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
1742
+ 
1743
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
1744
+ SQL (0.1ms) select sqlite_version(*)
1745
+ SQL (0.3ms)  SELECT name
1746
+ FROM sqlite_master
1747
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
1748
+ 
1749
+ SQL (1.5ms) DROP TABLE "behavior_configs"
1750
+ SQL (1.4ms) CREATE TABLE "behavior_configs" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "key" varchar(255), "value" varchar(255)) 
1751
+ SQL (0.2ms)  SELECT name
1752
+ FROM sqlite_master
1753
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
1754
+ 
1755
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
1756
+ BehaviorConfig Load (0.2ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."key" = 'email_name') LIMIT 1
1757
+ BehaviorConfig Load (0.1ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."key" = 'email_address') LIMIT 1
1758
+ BehaviorConfig Load (0.1ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."key" = 'description') LIMIT 1
1759
+ BehaviorConfig Load (0.1ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."key" = 'password') LIMIT 1
1760
+ BehaviorConfig Load (0.2ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."key" = 'email_name') LIMIT 1
1761
+ BehaviorConfig Create (2.7ms) INSERT INTO "behavior_configs" ("value", "key") VALUES(NULL, 'email_name')
1762
+ BehaviorConfig Update (0.1ms) UPDATE "behavior_configs" SET "value" = 'Site Administrator' WHERE "id" = 1
1763
+ BehaviorConfig Load (0.1ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."key" = 'email_address') LIMIT 1
1764
+ BehaviorConfig Create (0.1ms) INSERT INTO "behavior_configs" ("value", "key") VALUES(NULL, 'email_address')
1765
+ BehaviorConfig Update (0.1ms) UPDATE "behavior_configs" SET "value" = 'paul@rslw.com' WHERE "id" = 2
1766
+ BehaviorConfig Load (0.1ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."key" = 'description') LIMIT 1
1767
+ BehaviorConfig Create (0.1ms) INSERT INTO "behavior_configs" ("value", "key") VALUES(NULL, 'description')
1768
+ BehaviorConfig Update (0.2ms) UPDATE "behavior_configs" SET "value" = 'My Awesome Site' WHERE "id" = 3
1769
+ BehaviorConfig Load (0.2ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."key" = 'password') LIMIT 1
1770
+ BehaviorConfig Create (0.2ms) INSERT INTO "behavior_configs" ("value", "key") VALUES(NULL, 'password')
1771
+ BehaviorConfig Update (0.2ms) UPDATE "behavior_configs" SET "value" = 'password' WHERE "id" = 4
1772
+ BehaviorConfig Load (0.3ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."key" = 'email_name') LIMIT 1
1773
+ BehaviorConfig Load (0.1ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."key" = 'email_address') LIMIT 1
1774
+ BehaviorConfig Load (0.1ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."key" = 'description') LIMIT 1
1775
+ BehaviorConfig Load (0.1ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."key" = 'password') LIMIT 1
1776
+ SQL (0.2ms)  SELECT name
1777
+ FROM sqlite_master
1778
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
1779
+ 
1780
+ SQL (0.0ms) DELETE FROM "behavior_configs";
1781
+ SQL (0.2ms) select sqlite_version(*)
1782
+ SQL (0.3ms)  SELECT name
1783
+ FROM sqlite_master
1784
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
1785
+ 
1786
+ SQL (1.6ms) DROP TABLE "behavior_configs"
1787
+ SQL (1.5ms) CREATE TABLE "behavior_configs" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "key" varchar(255), "value" varchar(255)) 
1788
+ SQL (0.2ms)  SELECT name
1789
+ FROM sqlite_master
1790
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
1791
+ 
1792
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
1793
+ SQL (0.2ms) select sqlite_version(*)
1794
+ SQL (0.3ms)  SELECT name
1795
+ FROM sqlite_master
1796
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
1797
+ 
1798
+ SQL (1.2ms) DROP TABLE "behavior_configs"
1799
+ SQL (1.4ms) CREATE TABLE "behavior_configs" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "key" varchar(255), "value" varchar(255)) 
1800
+ SQL (0.2ms)  SELECT name
1801
+ FROM sqlite_master
1802
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
1803
+ 
1804
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
1805
+ BehaviorConfig Create (0.4ms) INSERT INTO "behavior_configs" ("value", "key") VALUES('paul@rslw.com', 'email_address')
1806
+ BehaviorConfig Load (0.3ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."id" = 1) 
1807
+ BehaviorConfig Load (0.1ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."key" = 'email_address') LIMIT 1
1808
+ BehaviorConfig Update (0.1ms) UPDATE "behavior_configs" SET "value" = 'joe@putplace.com' WHERE "id" = 1
1809
+ BehaviorConfig Load (0.1ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."key" = 'email_address') LIMIT 1
1810
+ BehaviorConfig Create (0.3ms) INSERT INTO "behavior_configs" ("value", "key") VALUES('paul@rslw.com', 'email_address')
1811
+ BehaviorConfig Load (0.2ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."id" = 1) 
1812
+ BehaviorConfig Create (0.3ms) INSERT INTO "behavior_configs" ("value", "key") VALUES('paul@rslw.com', 'email_address')
1813
+ BehaviorConfig Load (0.2ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."id" = 1) 
1814
+ BehaviorConfig Create (0.4ms) INSERT INTO "behavior_configs" ("value", "key") VALUES('paul@rslw.com', 'email_address')
1815
+ BehaviorConfig Load (0.2ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."id" = 1) 
1816
+ BehaviorConfig Create (0.3ms) INSERT INTO "behavior_configs" ("value", "key") VALUES('paul@rslw.com', 'email_address')
1817
+ BehaviorConfig Load (0.2ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."id" = 1) 
1818
+ BehaviorConfig Load (0.1ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."key" = 'email_address') LIMIT 1
1819
+ BehaviorConfig Create (0.3ms) INSERT INTO "behavior_configs" ("value", "key") VALUES('paul@rslw.com', 'email_address')
1820
+ BehaviorConfig Load (0.1ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."id" = 1) 
1821
+ BehaviorConfig Load (0.1ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."key" = 'email_name') LIMIT 1
1822
+ BehaviorConfig Load (0.1ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."key" = 'password') LIMIT 1
1823
+ BehaviorConfig Load (0.2ms) SELECT * FROM "behavior_configs" WHERE ("behavior_configs"."key" = 'description') LIMIT 1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: behavior
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Campbell
@@ -19,10 +19,10 @@ executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
- extra_rdoc_files:
23
- - README.textile
22
+ extra_rdoc_files: []
23
+
24
24
  files:
25
- - README.textile
25
+ - README.md
26
26
  - Rakefile
27
27
  - app/controllers/admin/configs_controller.rb
28
28
  - app/helpers/behavior_helper.rb
data/README.textile DELETED
@@ -1,97 +0,0 @@
1
- h1. Behavior
2
-
3
- Behavior is a Ruby on Rails plugin for storing application configuration variables in the database. You can use it to store things like a Site's Title, description and keywords, or for user definable things like a currency exchange rate, or minimum and maximum values.
4
-
5
- The benefits of storing configuration in the database are:
6
-
7
- - End users can easily edit the values
8
- - Configuration is decoupled from the codebase
9
-
10
- This is particularly useful for open source projects, where application settings shouldn't be stored in source code.
11
-
12
- It's designed to be as simple to use and get up and running, and to be flexible in that it's both end user and developer friendly.
13
-
14
- Although all config variables are ultimately stored in the database, you can set sensible defaults in a configuration file in the source code.
15
-
16
- h2. Installation
17
-
18
- Behavior is easy to install.
19
-
20
- As a plugin:
21
-
22
- <pre><code>./script/plugin install git://github.com/paulca/behavior.git</code></pre>
23
-
24
- Or as a gem. Add this to your environment.rb:
25
-
26
- <pre><code>config.gem 'behavior'</code></pre>
27
-
28
- Generate the migration and sample behavior.yml:
29
-
30
- <pre><code>./script/generate behavior</code></pre>
31
-
32
- And run the migration:
33
-
34
- <pre><code>rake db:migrate</code></pre>
35
-
36
- h2. Basic Usage
37
-
38
- There are two parts to how behavior works. First of all there is a config file, config/behavior.yml. This file controls the variables that are allowed to be set in the app.
39
-
40
- For example, if you wanted to have access to a config variable "site_title", put this in behavior.yml:
41
-
42
- <pre><code>site_title:
43
- default: My Site</code></pre>
44
-
45
- Now, within your app, you can access <pre><code>config[:site_title]</code></pre>.
46
-
47
- If you want to update the config, call <pre><code>config.update(:site_title => "My New Title")</code></pre>
48
-
49
- h2. Web Interface
50
-
51
- behavior comes with a web interface that is available to your app straight away at <pre><code>http://localhost:3000/admin/config</code></pre>.
52
-
53
- By default, this comes with no styling, but you can create a layout in <pre><code>app/layouts/admin.html.erb</code></pre>, or set a layout by setting <pre><code>Behavior::Setting.layout</code></pre>
54
-
55
- For example, to use your standard application layout, create a <pre><code>config/initializers/behavior.rb</code></pre> like this:
56
-
57
- <pre><code>Behavior::Settings.layout = 'application'</code></pre>
58
-
59
- You can also add before_filters to protect the controller from outsiders:
60
-
61
- <pre><code>Behavior::Settings.before_filters << 'require_admin_user'</code></pre>
62
-
63
- If you want to control how the fields in the admin interface appear, you can add additional params in your behavior.yml file:
64
-
65
- <pre><code>site_title:
66
- name: Name of Your Site # sets the edit label
67
- default: My Site # sets the default value
68
- type: string # uses input type="text"
69
-
70
- site_description:
71
- name: Describe Your Site # sets the edit label
72
- default: My Site # sets the default value
73
- type: text # uses textarea
74
-
75
- secret:
76
- name: A Secret Passphrase # sets the edit label
77
- default: passpass # sets the default value
78
- type: password # uses input type="password"
79
- </code></pre>
80
-
81
- h2. Running the tests
82
-
83
- You can run the tests by checking out the code into vendor/plugins of a Rails app and running:
84
-
85
- <pre><code>rake</code></pre>
86
-
87
- It also comes with a set of cucumber features:
88
-
89
- <pre><code>cucumber</code></pre>
90
-
91
- h2. About me
92
-
93
- I'm Paul Campbell. I'm an avid Ruby on Rails web developer. Follow my ramblings at "http://www.pabcas.com":http://www.pabcas.com
94
-
95
- Follow me on Twitter "http://twitter.com/paulca":http://twitter.com/paulca
96
-
97
- Copyright (c) 2009 Paul Campbell, released under the MIT license