contentable 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.textile +40 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/contentable.gemspec +133 -0
- data/lib/contentable.rb +117 -0
- data/lib/version.rb +4 -0
- data/spec/rails3/Gemfile +37 -0
- data/spec/rails3/Gemfile.lock +104 -0
- data/spec/rails3/Rakefile +10 -0
- data/spec/rails3/app_root/.gitignore +4 -0
- data/spec/rails3/app_root/README +256 -0
- data/spec/rails3/app_root/app/controllers/application_controller.rb +3 -0
- data/spec/rails3/app_root/app/controllers/content_items_controller.rb +83 -0
- data/spec/rails3/app_root/app/helpers/application_helper.rb +2 -0
- data/spec/rails3/app_root/app/helpers/content_items_helper.rb +2 -0
- data/spec/rails3/app_root/app/models/content_item.rb +3 -0
- data/spec/rails3/app_root/app/views/content_items/_form.html.erb +17 -0
- data/spec/rails3/app_root/app/views/content_items/edit.html.erb +6 -0
- data/spec/rails3/app_root/app/views/content_items/index.html.erb +21 -0
- data/spec/rails3/app_root/app/views/content_items/new.html.erb +5 -0
- data/spec/rails3/app_root/app/views/content_items/show.html.erb +5 -0
- data/spec/rails3/app_root/app/views/layouts/application.html.erb +14 -0
- data/spec/rails3/app_root/config.ru +4 -0
- data/spec/rails3/app_root/config/application.rb +46 -0
- data/spec/rails3/app_root/config/boot.rb +13 -0
- data/spec/rails3/app_root/config/database.yml +28 -0
- data/spec/rails3/app_root/config/environment.rb +5 -0
- data/spec/rails3/app_root/config/environments/development.rb +26 -0
- data/spec/rails3/app_root/config/environments/in_memory.rb +35 -0
- data/spec/rails3/app_root/config/environments/production.rb +49 -0
- data/spec/rails3/app_root/config/environments/test.rb +35 -0
- data/spec/rails3/app_root/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails3/app_root/config/initializers/inflections.rb +10 -0
- data/spec/rails3/app_root/config/initializers/mime_types.rb +5 -0
- data/spec/rails3/app_root/config/initializers/secret_token.rb +7 -0
- data/spec/rails3/app_root/config/initializers/session_store.rb +8 -0
- data/spec/rails3/app_root/config/locales/en.yml +5 -0
- data/spec/rails3/app_root/config/routes.rb +60 -0
- data/spec/rails3/app_root/db/migrate/20110102070953_create_content_items.rb +9 -0
- data/spec/rails3/app_root/db/schema.rb +24 -0
- data/spec/rails3/app_root/db/seeds.rb +7 -0
- data/spec/rails3/app_root/doc/README_FOR_APP +2 -0
- data/spec/rails3/app_root/lib/tasks/.gitkeep +0 -0
- data/spec/rails3/app_root/public/404.html +26 -0
- data/spec/rails3/app_root/public/422.html +26 -0
- data/spec/rails3/app_root/public/500.html +26 -0
- data/spec/rails3/app_root/public/favicon.ico +0 -0
- data/spec/rails3/app_root/public/images/rails.png +0 -0
- data/spec/rails3/app_root/public/index.html +239 -0
- data/spec/rails3/app_root/public/javascripts/application.js +2 -0
- data/spec/rails3/app_root/public/javascripts/controls.js +965 -0
- data/spec/rails3/app_root/public/javascripts/dragdrop.js +974 -0
- data/spec/rails3/app_root/public/javascripts/effects.js +1123 -0
- data/spec/rails3/app_root/public/javascripts/prototype.js +6001 -0
- data/spec/rails3/app_root/public/javascripts/rails.js +175 -0
- data/spec/rails3/app_root/public/robots.txt +5 -0
- data/spec/rails3/app_root/public/stylesheets/.gitkeep +0 -0
- data/spec/rails3/app_root/public/stylesheets/scaffold.css +56 -0
- data/spec/rails3/app_root/script/rails +6 -0
- data/spec/rails3/contentable_spec.rb +31 -0
- data/spec/rails3/spec.opts +1 -0
- data/spec/rails3/spec_helper.rb +21 -0
- metadata +183 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 metasoarous
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
h1. Contentable
|
2
|
+
|
3
|
+
Contentable is a gem for easing the integration of chunks of dynamic content. For situations in which content which needs to be inserted here in there in some web application, but which should be updatable on the fly, you could go with a content management system, but if you also need other models and the rest of the power of rails, that isn't the best solution. This gem addresses this issue by allowing you to create content_items which house content (using textile) and give you easy display (etc) access to this content, either as full page content or as a simple block of content to be embedded within some other dynamic page.
|
4
|
+
|
5
|
+
h2. How to use
|
6
|
+
|
7
|
+
The basics of use of this gem are as follows.
|
8
|
+
|
9
|
+
# First, include the gem in your Gemfile
|
10
|
+
# Next scaffold out a content_item model with fields @name:string title:string description:string text:text@. Alternatively (preferably really) there is a migration helper which goes along the lines of @create_content_items@ that does this for you; just include that method call within @def self.up@.
|
11
|
+
# Put the line @acts_as_contentable@ in your @ContentItem@ model
|
12
|
+
# Use @display_content(content_item)@ in your views (or @display_textile(some_textile_text)@)
|
13
|
+
# Include @Contentable::Controller@ in your @ContentItemController@ to gain access to the @find_content_item@ controller method which first looks to see if @params[:id]@ is defined and then looks to see if @params[name]@ is defined. The the first isn't but the latter is, the action will grab the content item based on the name passed through. Now you can set up routes that easily take advantage of this so that your content item @name@ attributes can behave like parts of a path.
|
14
|
+
# You can also call @ContentItem#safe_find_by_name(name)@ directly (the method able is just a wrapper of this). If that name queried for is not found, the method returns a (either new or old, depending on whether the situation has ever happened before) content item named @content_missing@. This content item will be given a @missing@ attribute (in local memory, not in db) which stores the name of the missing content item. This name can then be used for easier creation of content that should exist but does not yet.
|
15
|
+
|
16
|
+
h2. TODO
|
17
|
+
|
18
|
+
* Make it so that the class you include contentable in can be named whatever your want (BIG ONE)
|
19
|
+
* Make helpers for using javascript to automatically render the textile as you type it.
|
20
|
+
* Put in validations on @name@ of content items so that they can always be used as paths?
|
21
|
+
* Create validations/protections on changing the content_item @name@
|
22
|
+
* Create generators for view code, (migrations, etc?)
|
23
|
+
* ContentItem manager (a sort of default content item index which allows an admin to manage content items)
|
24
|
+
* Support other markup languages
|
25
|
+
* Integrate the textile helper
|
26
|
+
* Routing helpers
|
27
|
+
|
28
|
+
h2. Note on Patches/Pull Requests
|
29
|
+
|
30
|
+
* Fork the project.
|
31
|
+
* Make your feature addition or bug fix.
|
32
|
+
* Add specs for it. This is important so I don't break it in a
|
33
|
+
future version unintentionally.
|
34
|
+
* Commit, do not mess with rakefile, version, or history.
|
35
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
36
|
+
* Send me a pull request. Bonus points for topic branches.
|
37
|
+
|
38
|
+
h2. Copyright
|
39
|
+
|
40
|
+
Copyright (c) 2010 metasoarous (Christopher Small). See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "contentable"
|
8
|
+
gem.summary = %Q{Rails 3 gem for streamlining the management of chunks of html (textile) content within an application}
|
9
|
+
gem.description = %Q{Contentable allows rails developers to place chunks of content in "content_items" whcih store content text, titles and descriptions in order to make content more easily updateable manageable.}
|
10
|
+
gem.email = "metasoarous@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/metasoarous/contentable"
|
12
|
+
gem.authors = ["metasoarous"]
|
13
|
+
gem.add_dependency "RedCloth"
|
14
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
# Complaining about not being able to find Spec
|
23
|
+
#
|
24
|
+
# Spec::Rake::SpecTask.new(:rcov) do |spec|
|
25
|
+
# spec.libs << 'lib' << 'spec'
|
26
|
+
# spec.pattern = 'spec/**/*_spec.rb'
|
27
|
+
# spec.rcov = true
|
28
|
+
# end
|
29
|
+
|
30
|
+
task :spec => :check_dependencies
|
31
|
+
|
32
|
+
# task :default => :spec
|
33
|
+
desc 'Default: Run all specs.'
|
34
|
+
task :default => :all_specs
|
35
|
+
|
36
|
+
desc "Run all specs"
|
37
|
+
task :all_specs do
|
38
|
+
Dir['spec/**/Rakefile'].each do |rakefile|
|
39
|
+
directory_name = File.dirname(rakefile)
|
40
|
+
sh <<-CMD
|
41
|
+
cd #{directory_name}
|
42
|
+
bundle exec rake
|
43
|
+
CMD
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
require 'rake/rdoctask'
|
50
|
+
Rake::RDocTask.new do |rdoc|
|
51
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
52
|
+
|
53
|
+
rdoc.rdoc_dir = 'rdoc'
|
54
|
+
rdoc.title = "contentable #{version}"
|
55
|
+
rdoc.rdoc_files.include('README*')
|
56
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.0
|
data/contentable.gemspec
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{contentable}
|
8
|
+
s.version = "0.3.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["metasoarous"]
|
12
|
+
s.date = %q{2011-01-17}
|
13
|
+
s.description = %q{Contentable allows rails developers to place chunks of content in "content_items" whcih store content text, titles and descriptions in order to make content more easily updateable manageable.}
|
14
|
+
s.email = %q{metasoarous@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.textile"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.textile",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"contentable.gemspec",
|
27
|
+
"lib/contentable.rb",
|
28
|
+
"lib/version.rb",
|
29
|
+
"spec/rails3/Gemfile",
|
30
|
+
"spec/rails3/Gemfile.lock",
|
31
|
+
"spec/rails3/Rakefile",
|
32
|
+
"spec/rails3/app_root/.gitignore",
|
33
|
+
"spec/rails3/app_root/README",
|
34
|
+
"spec/rails3/app_root/app/controllers/application_controller.rb",
|
35
|
+
"spec/rails3/app_root/app/controllers/content_items_controller.rb",
|
36
|
+
"spec/rails3/app_root/app/helpers/application_helper.rb",
|
37
|
+
"spec/rails3/app_root/app/helpers/content_items_helper.rb",
|
38
|
+
"spec/rails3/app_root/app/models/content_item.rb",
|
39
|
+
"spec/rails3/app_root/app/views/content_items/_form.html.erb",
|
40
|
+
"spec/rails3/app_root/app/views/content_items/edit.html.erb",
|
41
|
+
"spec/rails3/app_root/app/views/content_items/index.html.erb",
|
42
|
+
"spec/rails3/app_root/app/views/content_items/new.html.erb",
|
43
|
+
"spec/rails3/app_root/app/views/content_items/show.html.erb",
|
44
|
+
"spec/rails3/app_root/app/views/layouts/application.html.erb",
|
45
|
+
"spec/rails3/app_root/config.ru",
|
46
|
+
"spec/rails3/app_root/config/application.rb",
|
47
|
+
"spec/rails3/app_root/config/boot.rb",
|
48
|
+
"spec/rails3/app_root/config/database.yml",
|
49
|
+
"spec/rails3/app_root/config/environment.rb",
|
50
|
+
"spec/rails3/app_root/config/environments/development.rb",
|
51
|
+
"spec/rails3/app_root/config/environments/in_memory.rb",
|
52
|
+
"spec/rails3/app_root/config/environments/production.rb",
|
53
|
+
"spec/rails3/app_root/config/environments/test.rb",
|
54
|
+
"spec/rails3/app_root/config/initializers/backtrace_silencers.rb",
|
55
|
+
"spec/rails3/app_root/config/initializers/inflections.rb",
|
56
|
+
"spec/rails3/app_root/config/initializers/mime_types.rb",
|
57
|
+
"spec/rails3/app_root/config/initializers/secret_token.rb",
|
58
|
+
"spec/rails3/app_root/config/initializers/session_store.rb",
|
59
|
+
"spec/rails3/app_root/config/locales/en.yml",
|
60
|
+
"spec/rails3/app_root/config/routes.rb",
|
61
|
+
"spec/rails3/app_root/db/migrate/20110102070953_create_content_items.rb",
|
62
|
+
"spec/rails3/app_root/db/schema.rb",
|
63
|
+
"spec/rails3/app_root/db/seeds.rb",
|
64
|
+
"spec/rails3/app_root/doc/README_FOR_APP",
|
65
|
+
"spec/rails3/app_root/lib/tasks/.gitkeep",
|
66
|
+
"spec/rails3/app_root/public/404.html",
|
67
|
+
"spec/rails3/app_root/public/422.html",
|
68
|
+
"spec/rails3/app_root/public/500.html",
|
69
|
+
"spec/rails3/app_root/public/favicon.ico",
|
70
|
+
"spec/rails3/app_root/public/images/rails.png",
|
71
|
+
"spec/rails3/app_root/public/index.html",
|
72
|
+
"spec/rails3/app_root/public/javascripts/application.js",
|
73
|
+
"spec/rails3/app_root/public/javascripts/controls.js",
|
74
|
+
"spec/rails3/app_root/public/javascripts/dragdrop.js",
|
75
|
+
"spec/rails3/app_root/public/javascripts/effects.js",
|
76
|
+
"spec/rails3/app_root/public/javascripts/prototype.js",
|
77
|
+
"spec/rails3/app_root/public/javascripts/rails.js",
|
78
|
+
"spec/rails3/app_root/public/robots.txt",
|
79
|
+
"spec/rails3/app_root/public/stylesheets/.gitkeep",
|
80
|
+
"spec/rails3/app_root/public/stylesheets/scaffold.css",
|
81
|
+
"spec/rails3/app_root/script/rails",
|
82
|
+
"spec/rails3/contentable_spec.rb",
|
83
|
+
"spec/rails3/spec.opts",
|
84
|
+
"spec/rails3/spec_helper.rb"
|
85
|
+
]
|
86
|
+
s.homepage = %q{http://github.com/metasoarous/contentable}
|
87
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
88
|
+
s.require_paths = ["lib"]
|
89
|
+
s.rubygems_version = %q{1.3.7}
|
90
|
+
s.summary = %q{Rails 3 gem for streamlining the management of chunks of html (textile) content within an application}
|
91
|
+
s.test_files = [
|
92
|
+
"spec/rails3/app_root/app/controllers/application_controller.rb",
|
93
|
+
"spec/rails3/app_root/app/controllers/content_items_controller.rb",
|
94
|
+
"spec/rails3/app_root/app/helpers/application_helper.rb",
|
95
|
+
"spec/rails3/app_root/app/helpers/content_items_helper.rb",
|
96
|
+
"spec/rails3/app_root/app/models/content_item.rb",
|
97
|
+
"spec/rails3/app_root/config/application.rb",
|
98
|
+
"spec/rails3/app_root/config/boot.rb",
|
99
|
+
"spec/rails3/app_root/config/environment.rb",
|
100
|
+
"spec/rails3/app_root/config/environments/development.rb",
|
101
|
+
"spec/rails3/app_root/config/environments/in_memory.rb",
|
102
|
+
"spec/rails3/app_root/config/environments/production.rb",
|
103
|
+
"spec/rails3/app_root/config/environments/test.rb",
|
104
|
+
"spec/rails3/app_root/config/initializers/backtrace_silencers.rb",
|
105
|
+
"spec/rails3/app_root/config/initializers/inflections.rb",
|
106
|
+
"spec/rails3/app_root/config/initializers/mime_types.rb",
|
107
|
+
"spec/rails3/app_root/config/initializers/secret_token.rb",
|
108
|
+
"spec/rails3/app_root/config/initializers/session_store.rb",
|
109
|
+
"spec/rails3/app_root/config/routes.rb",
|
110
|
+
"spec/rails3/app_root/db/migrate/20110102070953_create_content_items.rb",
|
111
|
+
"spec/rails3/app_root/db/schema.rb",
|
112
|
+
"spec/rails3/app_root/db/seeds.rb",
|
113
|
+
"spec/rails3/contentable_spec.rb",
|
114
|
+
"spec/rails3/spec_helper.rb"
|
115
|
+
]
|
116
|
+
|
117
|
+
if s.respond_to? :specification_version then
|
118
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
119
|
+
s.specification_version = 3
|
120
|
+
|
121
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
122
|
+
s.add_runtime_dependency(%q<RedCloth>, [">= 0"])
|
123
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
124
|
+
else
|
125
|
+
s.add_dependency(%q<RedCloth>, [">= 0"])
|
126
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
127
|
+
end
|
128
|
+
else
|
129
|
+
s.add_dependency(%q<RedCloth>, [">= 0"])
|
130
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
data/lib/contentable.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
require "redcloth"
|
2
|
+
|
3
|
+
module Contentable
|
4
|
+
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
config.to_prepare do
|
7
|
+
ActiveRecord::Base.send :extend, Contentable::Hook
|
8
|
+
end
|
9
|
+
initializer "contentable.initialize" do |app|
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Extends ActiveRecord::Base in order to grant it's decendents
|
15
|
+
# the acts_as_hook
|
16
|
+
module Hook
|
17
|
+
def acts_as_contentable
|
18
|
+
self.send :include, Model
|
19
|
+
ActiveRecord::Migration.extend MigrationHelper
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Gets auto included in your ApplicationHelper when you include the
|
24
|
+
# Model module in the model class
|
25
|
+
module Helpers
|
26
|
+
def display_textile(text)
|
27
|
+
RedCloth.new(text).to_html
|
28
|
+
end
|
29
|
+
def display_content(content_item, edit = false)
|
30
|
+
html = display_textile(content_item.text)
|
31
|
+
if edit
|
32
|
+
edit_path = content_item.missing ? new_content_item_path(:title => content_item.missing) : edit_content_item_path(content_item)
|
33
|
+
html += "<p>#{link_to("Edit Content", edit_path)}</p> "
|
34
|
+
end
|
35
|
+
return html
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Once included in your model (which at least as of now should be named
|
40
|
+
# ContentItem) you get class method safe_find_by_title which lets you
|
41
|
+
# search for a ContentItem using a specific title and if it can't find
|
42
|
+
# it it presents a default content content_item.
|
43
|
+
module Model
|
44
|
+
def self.included(model)
|
45
|
+
model.extend ClassMethods
|
46
|
+
model.send :attr_accessor, :missing
|
47
|
+
model.validates_uniqueness_of :title
|
48
|
+
ActionView::Base.send :include, Helpers
|
49
|
+
end
|
50
|
+
module ClassMethods
|
51
|
+
def safe_find_by_name(name)
|
52
|
+
found_by_name = find_by_title(name)
|
53
|
+
if found_by_name
|
54
|
+
return found_by_name
|
55
|
+
else
|
56
|
+
content_missing = find_or_create_by_name(:name => "content_missing", :title => "Content Missing", :description => "This is the display page returned when there is no content found that matches a particular name.", :text => "This content has yet to be created.")
|
57
|
+
# This lets the content_missing content item know what
|
58
|
+
# name was requested so that one can ask it for the
|
59
|
+
# name and create a new content item with that name.
|
60
|
+
content_missing.missing = name
|
61
|
+
return content_missing
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# After includng this module in the ContentItem, take the
|
68
|
+
# @content_item assignments as these will be set up for you
|
69
|
+
# with the before filter. Or, alternatively, make a call to
|
70
|
+
# find_content_item yourself.
|
71
|
+
module Controller
|
72
|
+
# Sets up before filter for us.
|
73
|
+
def self.included(controller)
|
74
|
+
controller.before_filter :find_content_item
|
75
|
+
end
|
76
|
+
private
|
77
|
+
# This method can be used as a controller helper mehtod to be
|
78
|
+
# used in a before filter
|
79
|
+
def find_content_item
|
80
|
+
if params[:id]
|
81
|
+
@content_item = ContentItem.find(params[:id])
|
82
|
+
elsif params[:name]
|
83
|
+
@content_item = ContentItem.safe_find_by_name(params[:name])
|
84
|
+
@missing = @content_item.missing
|
85
|
+
else
|
86
|
+
@content_item = ContentItem.safe_find_by_name("content_missing")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# This module gives us some migration helpers that let us easily
|
92
|
+
# create the fields necessary for content items. We are switching
|
93
|
+
# this so that title can contain title information to show up in
|
94
|
+
# the resulting document title, while path is where you go to get
|
95
|
+
# there.
|
96
|
+
#
|
97
|
+
# This doesn't work yet - might want to consider scrapping it for
|
98
|
+
# now, but it would be good to have later. When we do that, we should
|
99
|
+
# make it model name agnostic...
|
100
|
+
module MigrationHelper
|
101
|
+
def create_content_items
|
102
|
+
create_table :content_items do |t|
|
103
|
+
t.string :name
|
104
|
+
t.string :title
|
105
|
+
t.string :description
|
106
|
+
t.text :text
|
107
|
+
|
108
|
+
t.timestamps
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def drop_content_items
|
113
|
+
drop_table :content_items
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
data/lib/version.rb
ADDED
data/spec/rails3/Gemfile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '3.0.2'
|
4
|
+
|
5
|
+
gem 'rspec'
|
6
|
+
gem 'rspec-rails'
|
7
|
+
gem 'ruby-debug'
|
8
|
+
|
9
|
+
gem "contentable", :path => "../.."
|
10
|
+
|
11
|
+
# Bundle edge Rails instead:
|
12
|
+
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
13
|
+
|
14
|
+
gem 'sqlite3-ruby', :require => 'sqlite3'
|
15
|
+
|
16
|
+
# Use unicorn as the web server
|
17
|
+
# gem 'unicorn'
|
18
|
+
|
19
|
+
# Deploy with Capistrano
|
20
|
+
# gem 'capistrano'
|
21
|
+
|
22
|
+
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
|
23
|
+
# gem 'ruby-debug'
|
24
|
+
# gem 'ruby-debug19'
|
25
|
+
|
26
|
+
# Bundle the extra gems:
|
27
|
+
# gem 'bj'
|
28
|
+
# gem 'nokogiri'
|
29
|
+
# gem 'sqlite3-ruby', :require => 'sqlite3'
|
30
|
+
# gem 'aws-s3', :require => 'aws/s3'
|
31
|
+
|
32
|
+
# Bundle gems for the local environment. Make sure to
|
33
|
+
# put test-only gems in this group so their generators
|
34
|
+
# and rake tasks are available in development mode:
|
35
|
+
# group :development, :test do
|
36
|
+
# gem 'webrat'
|
37
|
+
# end
|