manageable_content 0.0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +10 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +92 -4
- data/Rakefile +2 -0
- data/app/models/manageable_content/page_content.rb +2 -2
- data/db/migrate/20110814003912_create_manageable_content_page_contents.rb +1 -0
- data/lib/manageable_content/controllers/dsl.rb +27 -4
- data/lib/manageable_content/manager.rb +9 -8
- data/lib/manageable_content/version.rb +1 -1
- data/spec/dummy/app/controllers/application_controller.rb +5 -2
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +2 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +42 -0
- data/spec/dummy/log/test.log +48477 -0
- data/spec/lib/manageable_content/controllers/dsl_spec.rb +10 -4
- data/spec/lib/manageable_content/manager_spec.rb +18 -13
- data/spec/models/manageable_content/page_content_spec.rb +2 -0
- metadata +23 -22
data/CHANGELOG.rdoc
ADDED
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -1,6 +1,94 @@
|
|
1
|
-
= ManageableContent
|
1
|
+
= ManageableContent http://travis-ci.org/fabiokr/manageable_content.png
|
2
2
|
|
3
|
-
|
3
|
+
Manageable Content is a Rails 3.1 Engine that provides a simple framework for content management. It works by providing a Page instance for each of your configured controllers, so that each controller can have it's own contents that will be available to the views. You can also have shared contents.
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
== Contributing
|
6
|
+
|
7
|
+
This engine is a work in progress and open for contributions! Please don't forget to add tests if you plan on contributing.
|
8
|
+
|
9
|
+
== Installation
|
10
|
+
|
11
|
+
This gem is compatible with Rails 3.1. To install it, add the following to your Gemfile:
|
12
|
+
|
13
|
+
gem 'manageable_content'
|
14
|
+
|
15
|
+
After that, run the 'bundle' command to install the gem.
|
16
|
+
|
17
|
+
The next step is to import the engine migrations to your application. Just run this:
|
18
|
+
|
19
|
+
bundle exec rake manageable_content_engine:install:migrations
|
20
|
+
|
21
|
+
Then migrate your database with the usual command:
|
22
|
+
|
23
|
+
bundle exec rake db:migrate
|
24
|
+
|
25
|
+
The last step is to include the Dsl in where you want to make the ManageableContent engine available. For example, you might want to add the following code to your ApplicationController:
|
26
|
+
|
27
|
+
include ManageableContent::Controllers::Dsl
|
28
|
+
|
29
|
+
== Getting Started
|
30
|
+
|
31
|
+
ManageableContent supports two types of contents: a controller content, and a layout content.
|
32
|
+
A controller content is a content that each controller will have by its own. For example, you might want to have a 'body' content, in which each controller will have a different value for it.
|
33
|
+
A layout content is a content that will be shared between controllers. For example, you might want to have a 'footer' content that will be shared accross all of your controllers.
|
34
|
+
|
35
|
+
=== Controller contents
|
36
|
+
|
37
|
+
Supposing that you have a controller named ContactController and you want it to have its own 'body' content. You will need to add this to the controller code:
|
38
|
+
|
39
|
+
manageable_content_for :body
|
40
|
+
|
41
|
+
After that, run the following rake task:
|
42
|
+
|
43
|
+
bundle exec rake manageable_content:generate
|
44
|
+
|
45
|
+
This rake task will check your controllers configurations and will generate the corresponding pages for each controller with their contents. This should be run everytime a new controller or page content is added. This rake task just calls the ManageableContent::Manager.generate! method. You might want to add some kind of hook so that when you deploy your application the generator will run.
|
46
|
+
|
47
|
+
You might also want to have an administration interface to edit you pages contents. Currently, this engine does not provide that, but you can check an admin example here: https://github.com/fabiokr/manageable_content_example_app/
|
48
|
+
|
49
|
+
Now, to use this in your views, you have to use the manageable_content_for helper:
|
50
|
+
|
51
|
+
manageable_content_for :body
|
52
|
+
|
53
|
+
This will print the content 'body' for the current controller, if it exists. This will print the content with html_safe.
|
54
|
+
|
55
|
+
If you need a content that all your controllers will have (for example, a 'title' content), you can add the configuration to your parent controller and all controllers that inherit from it will also have that content. For example, you could add this to your ApplicationController:
|
56
|
+
|
57
|
+
manageable_content_for :title
|
58
|
+
|
59
|
+
=== Layout contents
|
60
|
+
|
61
|
+
Supposing that your application will have a 'footer' content that should be the same in all of your controllers, you would add this to your ApplicationController:
|
62
|
+
|
63
|
+
manageable_layout_content_for :footer
|
64
|
+
|
65
|
+
In the views, to print it you need to use the manageable_layout_content_for helper:
|
66
|
+
|
67
|
+
manageable_layout_content_for :footer
|
68
|
+
|
69
|
+
==== Different layouts
|
70
|
+
|
71
|
+
In the previous example, the 'footer' content is available under the 'application' page. By default, manageable_layout_content_for uses the current controller default layout, which in the ApplicationController case is 'application'.
|
72
|
+
If you need to add a content to a different layout, you could use this:
|
73
|
+
|
74
|
+
manageable_layout_content_for :footer, :layout => 'my_custom_layout'
|
75
|
+
|
76
|
+
=== I18n
|
77
|
+
|
78
|
+
If you need different contents for multiple locales, you can generate multiple pages for each available locale. You just need to set the available locales for ManageableContent, and then when you run the generator task it will generate contents for all available locales. To do that, just add an initializer with this content:
|
79
|
+
|
80
|
+
ManageableContent::Engine.config.locales = [:en, :pt]
|
81
|
+
|
82
|
+
In your views, the helper calls will remain the same. The helpers use I18n.locale to get the current locale and than will use the content available for that locale.
|
83
|
+
|
84
|
+
== Contributors
|
85
|
+
|
86
|
+
https://github.com/fabiokr/manageable_content/contributors
|
87
|
+
|
88
|
+
== Maintainers
|
89
|
+
|
90
|
+
* Fabio Kreusch (https://github.com/fabiokr)
|
91
|
+
|
92
|
+
== License
|
93
|
+
|
94
|
+
MIT License. Copyright 2011 Fabio Kreusch http://www.kreusch.com.br
|
data/Rakefile
CHANGED
@@ -17,6 +17,8 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
17
17
|
rdoc.title = 'ManageableContent'
|
18
18
|
rdoc.options << '--line-numbers'
|
19
19
|
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('CHANGELOG.rdoc')
|
21
|
+
rdoc.rdoc_files.include('app/**/*.rb')
|
20
22
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
23
|
end
|
22
24
|
|
@@ -4,7 +4,7 @@ class ManageableContent::PageContent < ActiveRecord::Base
|
|
4
4
|
attr_accessible :content
|
5
5
|
|
6
6
|
validates :page_id, :presence => true
|
7
|
-
validates :key,
|
7
|
+
validates :key, :presence => true
|
8
8
|
|
9
|
-
default_scope order('key ASC')
|
9
|
+
default_scope order('short DESC, key ASC')
|
10
10
|
end
|
@@ -8,7 +8,7 @@ module ManageableContent
|
|
8
8
|
|
9
9
|
included do
|
10
10
|
class_attribute :manageable_content_keys
|
11
|
-
self.manageable_content_keys =
|
11
|
+
self.manageable_content_keys = {}
|
12
12
|
|
13
13
|
helper_method :manageable_layout_content_for
|
14
14
|
helper_method :manageable_content_for
|
@@ -31,13 +31,19 @@ module ManageableContent
|
|
31
31
|
#
|
32
32
|
# manageable_layout_content_for :footer_message, :footer_copyright, :layout => 'application'
|
33
33
|
#
|
34
|
+
# You can also set a content type for the given keys. By default they are :text content types.
|
35
|
+
# Available types are :text for long contents and :string for short contents.
|
36
|
+
#
|
37
|
+
# manageable_layout_content_for :footer_copyright, :type => :string
|
38
|
+
#
|
34
39
|
def manageable_layout_content_for(*keys)
|
35
40
|
options = keys.last.is_a?(Hash) ? keys.pop : {}
|
36
|
-
layout
|
41
|
+
layout = options[:layout] || self.controller_path
|
42
|
+
type = options[:type] || :text
|
37
43
|
|
38
44
|
unless keys.empty?
|
39
45
|
Dsl.manageable_layout_content_keys[layout] =
|
40
|
-
((Dsl.manageable_layout_content_keys[layout] ||
|
46
|
+
((Dsl.manageable_layout_content_keys[layout] || {}).merge(keys_for_type(type, keys)))
|
41
47
|
end
|
42
48
|
end
|
43
49
|
|
@@ -53,9 +59,26 @@ module ManageableContent
|
|
53
59
|
#
|
54
60
|
# manageable_content_for :title
|
55
61
|
#
|
62
|
+
# You can also set a content type for the given keys. By default they are :text content types.
|
63
|
+
# Available types are :text for long contents and :string for short contents.
|
64
|
+
#
|
65
|
+
# manageable_content_for :title, :type => :string
|
66
|
+
#
|
56
67
|
def manageable_content_for(*keys)
|
68
|
+
options = keys.last.is_a?(Hash) ? keys.pop : {}
|
69
|
+
type = options[:type] || :text
|
70
|
+
|
57
71
|
unless keys.empty?
|
58
|
-
self.manageable_content_keys = (self.manageable_content_keys
|
72
|
+
self.manageable_content_keys = (self.manageable_content_keys.merge(keys_for_type(type, keys)))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def keys_for_type(type, keys)
|
79
|
+
keys.inject({}) do |config, key|
|
80
|
+
config[key] = type
|
81
|
+
config
|
59
82
|
end
|
60
83
|
end
|
61
84
|
end
|
@@ -72,15 +72,17 @@ module ManageableContent
|
|
72
72
|
# This can be useful to check if a PageContent is still relevant
|
73
73
|
# based on the current configurations.
|
74
74
|
#
|
75
|
+
# This will return a list of page keys with it's corresponding content type (:string or :text).
|
76
|
+
#
|
75
77
|
def self.eligible_contents(key)
|
76
|
-
layout_content_keys = Controllers::Dsl.manageable_layout_content_keys[key] ||
|
78
|
+
layout_content_keys = Controllers::Dsl.manageable_layout_content_keys[key] || {}
|
77
79
|
content_keys = begin
|
78
80
|
"#{key.camelize}Controller".constantize.manageable_content_keys
|
79
81
|
rescue NameError
|
80
82
|
[]
|
81
83
|
end
|
82
84
|
|
83
|
-
(
|
85
|
+
layout_content_keys.merge(content_keys)
|
84
86
|
end
|
85
87
|
|
86
88
|
protected
|
@@ -89,7 +91,7 @@ module ManageableContent
|
|
89
91
|
#
|
90
92
|
def self.generate_page!(key, locale, content_keys)
|
91
93
|
Rails.logger.info "Generating ManageableContent::Page for key '#{key}',
|
92
|
-
locale '#{locale}' and keys [#{content_keys.join(',')}]"
|
94
|
+
locale '#{locale}' and keys [#{content_keys.keys.join(',')}]"
|
93
95
|
|
94
96
|
Page.transaction do
|
95
97
|
page = Manager.page(key, locale).first || Page.new
|
@@ -100,11 +102,10 @@ module ManageableContent
|
|
100
102
|
page.save!
|
101
103
|
end
|
102
104
|
|
103
|
-
content_keys.each do |content_key|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
end
|
105
|
+
content_keys.each do |content_key, content_type|
|
106
|
+
page_content = page.page_content(content_key) || page.page_contents.build
|
107
|
+
page_content.key = content_key
|
108
|
+
page_content.short = content_type == :string
|
108
109
|
end
|
109
110
|
|
110
111
|
page.save!
|
@@ -3,6 +3,9 @@ class ApplicationController < ActionController::Base
|
|
3
3
|
|
4
4
|
protect_from_forgery
|
5
5
|
|
6
|
-
manageable_layout_content_for :
|
7
|
-
|
6
|
+
manageable_layout_content_for :footer_contact, :type => :string
|
7
|
+
manageable_layout_content_for :footer_copyright, :type => :text
|
8
|
+
|
9
|
+
manageable_content_for :title, :type => :string
|
10
|
+
manageable_content_for :keywords, :type => :text
|
8
11
|
end
|
Binary file
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
# This file is auto-generated from the current state of the database. Instead
|
2
3
|
# of editing this file, please use the migrations feature of Active Record to
|
3
4
|
# incrementally modify your database, and then regenerate this schema definition.
|
@@ -15,6 +16,7 @@ ActiveRecord::Schema.define(:version => 20110814003912) do
|
|
15
16
|
create_table "manageable_content_page_contents", :force => true do |t|
|
16
17
|
t.integer "page_id"
|
17
18
|
t.string "key"
|
19
|
+
t.boolean "short", :default => false
|
18
20
|
t.text "content"
|
19
21
|
t.datetime "created_at"
|
20
22
|
t.datetime "updated_at"
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
@@ -1725,3 +1725,45 @@ Sprockets::FileNotFound: couldn't find file 'jquery'
|
|
1725
1725
|
(in /home/fabio/dev/manageable_content/spec/dummy/app/assets/javascripts/application.js:7)
|
1726
1726
|
Served asset /application.js - 500 Internal Server Error
|
1727
1727
|
|
1728
|
+
[1m[36m (0.1ms)[0m [1mselect sqlite_version(*)[0m
|
1729
|
+
[1m[35m (122.1ms)[0m CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
|
1730
|
+
[1m[36m (0.1ms)[0m [1mPRAGMA index_list("schema_migrations")[0m
|
1731
|
+
[1m[35m (121.1ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
1732
|
+
[1m[36m (0.2ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
1733
|
+
Migrating to CreateManageableContentPages (20110814002730)
|
1734
|
+
[1m[35m (0.8ms)[0m CREATE TABLE "manageable_content_pages" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "key" varchar(255), "locale" varchar(255), "created_at" datetime, "updated_at" datetime)
|
1735
|
+
[1m[36m (0.1ms)[0m [1mPRAGMA index_list("manageable_content_pages")[0m
|
1736
|
+
[1m[35m (0.5ms)[0m CREATE UNIQUE INDEX "index_manageable_content_pages_on_key_and_locale" ON "manageable_content_pages" ("key", "locale")
|
1737
|
+
[1m[36m (0.2ms)[0m [1mINSERT INTO "schema_migrations" ("version") VALUES ('20110814002730')[0m
|
1738
|
+
Migrating to CreateManageableContentPageContents (20110814003912)
|
1739
|
+
[1m[35m (0.5ms)[0m CREATE TABLE "manageable_content_page_contents" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "page_id" integer, "key" varchar(255), "type" varchar(255) DEFAULT 'text', "content" text, "created_at" datetime, "updated_at" datetime)
|
1740
|
+
[1m[36m (0.1ms)[0m [1mPRAGMA index_list("manageable_content_page_contents")[0m
|
1741
|
+
[1m[35m (0.3ms)[0m CREATE UNIQUE INDEX "index_manageable_content_page_contents_on_page_id_and_key" ON "manageable_content_page_contents" ("page_id", "key")
|
1742
|
+
[1m[36m (0.1ms)[0m [1mINSERT INTO "schema_migrations" ("version") VALUES ('20110814003912')[0m
|
1743
|
+
[1m[35m (0.4ms)[0m select sqlite_version(*)
|
1744
|
+
[1m[36m (0.1ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
1745
|
+
[1m[35m (0.1ms)[0m PRAGMA index_list("manageable_content_page_contents")
|
1746
|
+
[1m[36m (0.1ms)[0m [1mPRAGMA index_info('index_manageable_content_page_contents_on_page_id_and_key')[0m
|
1747
|
+
[1m[35m (0.0ms)[0m PRAGMA index_list("manageable_content_pages")
|
1748
|
+
[1m[36m (0.1ms)[0m [1mPRAGMA index_info('index_manageable_content_pages_on_key_and_locale')[0m
|
1749
|
+
[1m[36m (0.1ms)[0m [1mselect sqlite_version(*)[0m
|
1750
|
+
[1m[35m (207.7ms)[0m CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
|
1751
|
+
[1m[36m (0.1ms)[0m [1mPRAGMA index_list("schema_migrations")[0m
|
1752
|
+
[1m[35m (104.2ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
1753
|
+
[1m[36m (0.2ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
1754
|
+
Migrating to CreateManageableContentPages (20110814002730)
|
1755
|
+
[1m[35m (0.6ms)[0m CREATE TABLE "manageable_content_pages" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "key" varchar(255), "locale" varchar(255), "created_at" datetime, "updated_at" datetime)
|
1756
|
+
[1m[36m (0.1ms)[0m [1mPRAGMA index_list("manageable_content_pages")[0m
|
1757
|
+
[1m[35m (0.3ms)[0m CREATE UNIQUE INDEX "index_manageable_content_pages_on_key_and_locale" ON "manageable_content_pages" ("key", "locale")
|
1758
|
+
[1m[36m (0.2ms)[0m [1mINSERT INTO "schema_migrations" ("version") VALUES ('20110814002730')[0m
|
1759
|
+
Migrating to CreateManageableContentPageContents (20110814003912)
|
1760
|
+
[1m[35m (0.9ms)[0m CREATE TABLE "manageable_content_page_contents" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "page_id" integer, "key" varchar(255), "short" boolean DEFAULT 'f', "content" text, "created_at" datetime, "updated_at" datetime)
|
1761
|
+
[1m[36m (0.1ms)[0m [1mPRAGMA index_list("manageable_content_page_contents")[0m
|
1762
|
+
[1m[35m (0.4ms)[0m CREATE UNIQUE INDEX "index_manageable_content_page_contents_on_page_id_and_key" ON "manageable_content_page_contents" ("page_id", "key")
|
1763
|
+
[1m[36m (0.2ms)[0m [1mINSERT INTO "schema_migrations" ("version") VALUES ('20110814003912')[0m
|
1764
|
+
[1m[35m (0.5ms)[0m select sqlite_version(*)
|
1765
|
+
[1m[36m (0.2ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
1766
|
+
[1m[35m (0.1ms)[0m PRAGMA index_list("manageable_content_page_contents")
|
1767
|
+
[1m[36m (0.1ms)[0m [1mPRAGMA index_info('index_manageable_content_page_contents_on_page_id_and_key')[0m
|
1768
|
+
[1m[35m (0.1ms)[0m PRAGMA index_list("manageable_content_pages")
|
1769
|
+
[1m[36m (0.1ms)[0m [1mPRAGMA index_info('index_manageable_content_pages_on_key_and_locale')[0m
|