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 ADDED
@@ -0,0 +1,10 @@
1
+ == 0.1.1
2
+
3
+ * README instructions
4
+
5
+ == 0.1.0
6
+
7
+ * ManageableContent::Controllers::Dsl
8
+ * ManageableContent::Manager
9
+ * ManageableContent::Page
10
+ * ManageableContent::PageContent
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2011 YOURNAME
1
+ Copyright 2011 Fabio Kreusch
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -1,6 +1,94 @@
1
- = ManageableContent
1
+ = ManageableContent http://travis-ci.org/fabiokr/manageable_content.png
2
2
 
3
- This project rocks and uses MIT-LICENSE.
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
- TODO Explain how to setup and use
6
- TODO Talk about multiple locale configuration
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, :presence => true
7
+ validates :key, :presence => true
8
8
 
9
- default_scope order('key ASC')
9
+ default_scope order('short DESC, key ASC')
10
10
  end
@@ -3,6 +3,7 @@ class CreateManageableContentPageContents < ActiveRecord::Migration
3
3
  create_table :manageable_content_page_contents do |t|
4
4
  t.references :page
5
5
  t.string :key
6
+ t.boolean :short, :default => false
6
7
  t.text :content
7
8
 
8
9
  t.timestamps
@@ -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 = options[:layout] || self.controller_path
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] || []) + keys).uniq
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 + keys).uniq
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
- (layout_content_keys + content_keys).uniq
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
- if page.page_content(content_key).nil?
105
- page_content = page.page_contents.build
106
- page_content.key = content_key
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!
@@ -1,3 +1,3 @@
1
1
  module ManageableContent
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -3,6 +3,9 @@ class ApplicationController < ActionController::Base
3
3
 
4
4
  protect_from_forgery
5
5
 
6
- manageable_layout_content_for :footer_copyright, :footer_contact
7
- manageable_content_for :title, :keywords
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
@@ -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"
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
+  (0.1ms) select sqlite_version(*)
1729
+  (122.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
1730
+  (0.1ms) PRAGMA index_list("schema_migrations")
1731
+  (121.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
1732
+  (0.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
1733
+ Migrating to CreateManageableContentPages (20110814002730)
1734
+  (0.8ms) 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
+  (0.1ms) PRAGMA index_list("manageable_content_pages")
1736
+  (0.5ms) CREATE UNIQUE INDEX "index_manageable_content_pages_on_key_and_locale" ON "manageable_content_pages" ("key", "locale")
1737
+  (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES ('20110814002730')
1738
+ Migrating to CreateManageableContentPageContents (20110814003912)
1739
+  (0.5ms) 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
+  (0.1ms) PRAGMA index_list("manageable_content_page_contents")
1741
+  (0.3ms) CREATE UNIQUE INDEX "index_manageable_content_page_contents_on_page_id_and_key" ON "manageable_content_page_contents" ("page_id", "key")
1742
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20110814003912')
1743
+  (0.4ms) select sqlite_version(*)
1744
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
1745
+  (0.1ms) PRAGMA index_list("manageable_content_page_contents")
1746
+  (0.1ms) PRAGMA index_info('index_manageable_content_page_contents_on_page_id_and_key')
1747
+  (0.0ms) PRAGMA index_list("manageable_content_pages")
1748
+  (0.1ms) PRAGMA index_info('index_manageable_content_pages_on_key_and_locale')
1749
+  (0.1ms) select sqlite_version(*)
1750
+  (207.7ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
1751
+  (0.1ms) PRAGMA index_list("schema_migrations")
1752
+  (104.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
1753
+  (0.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
1754
+ Migrating to CreateManageableContentPages (20110814002730)
1755
+  (0.6ms) 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
+  (0.1ms) PRAGMA index_list("manageable_content_pages")
1757
+  (0.3ms) CREATE UNIQUE INDEX "index_manageable_content_pages_on_key_and_locale" ON "manageable_content_pages" ("key", "locale")
1758
+  (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES ('20110814002730')
1759
+ Migrating to CreateManageableContentPageContents (20110814003912)
1760
+  (0.9ms) 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
+  (0.1ms) PRAGMA index_list("manageable_content_page_contents")
1762
+  (0.4ms) CREATE UNIQUE INDEX "index_manageable_content_page_contents_on_page_id_and_key" ON "manageable_content_page_contents" ("page_id", "key")
1763
+  (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES ('20110814003912')
1764
+  (0.5ms) select sqlite_version(*)
1765
+  (0.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
1766
+  (0.1ms) PRAGMA index_list("manageable_content_page_contents")
1767
+  (0.1ms) PRAGMA index_info('index_manageable_content_page_contents_on_page_id_and_key')
1768
+  (0.1ms) PRAGMA index_list("manageable_content_pages")
1769
+  (0.1ms) PRAGMA index_info('index_manageable_content_pages_on_key_and_locale')