beef-acts_as_content_node 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +7 -0
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/acts_as_content_node.gemspec +71 -0
- data/app/helpers/content_nodes_helper.rb +17 -0
- data/app/views/content_nodes/_publish_select.html.erb +14 -0
- data/generators/content_node_scaffold/USAGE +8 -0
- data/generators/content_node_scaffold/content_node_scaffold_generator.rb +64 -0
- data/generators/content_node_scaffold/lib/insert_commands.rb +93 -0
- data/generators/content_node_scaffold/templates/admin_controller.rb +77 -0
- data/generators/content_node_scaffold/templates/admin_index.html.erb +45 -0
- data/generators/content_node_scaffold/templates/admin_show.html.erb +31 -0
- data/generators/content_node_scaffold/templates/helper.rb +2 -0
- data/generators/content_node_scaffold/templates/helper_test.rb +4 -0
- data/generators/content_node_scaffold/templates/layout.html.erb +17 -0
- data/generators/content_node_scaffold/templates/preview.js.rjs +1 -0
- data/generators/content_node_scaffold/templates/style.css +54 -0
- data/generators/content_node_scaffold/templates/view_controller.rb +31 -0
- data/generators/content_node_scaffold/templates/view_index.html.erb +17 -0
- data/generators/content_node_scaffold/templates/view_show.html.erb +7 -0
- data/init.rb +1 -0
- data/lib/acts_as_content_node/content_node.rb +73 -0
- data/lib/acts_as_content_node/permalinks.rb +18 -0
- data/lib/acts_as_content_node/publishable.rb +39 -0
- data/lib/acts_as_content_node.rb +3 -0
- data/rails/init.rb +12 -0
- data/tasks/acts_as_content_node_tasks.rake +4 -0
- data/test/acts_as_content_node_test.rb +88 -0
- data/test/database.yml +21 -0
- data/test/schema.rb +13 -0
- data/test/test_helper.rb +35 -0
- metadata +89 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2009 Steve England
|
|
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.rdoc
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
require 'jeweler'
|
|
6
|
+
Jeweler::Tasks.new do |gem|
|
|
7
|
+
gem.name = "acts_as_content_node"
|
|
8
|
+
gem.summary = %Q{Common functions for an record used as content of a website. Generator for cms and front end}
|
|
9
|
+
gem.email = "steve@wearebeef.co.uk"
|
|
10
|
+
gem.homepage = "http://github.com/beef/acts_as_content_node"
|
|
11
|
+
gem.authors = ["Steve England"]
|
|
12
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
rescue LoadError
|
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
require 'rake/testtask'
|
|
20
|
+
Rake::TestTask.new(:test) do |test|
|
|
21
|
+
test.libs << 'lib' << 'test'
|
|
22
|
+
test.pattern = 'test/**/*_test.rb'
|
|
23
|
+
test.verbose = true
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
begin
|
|
27
|
+
require 'rcov/rcovtask'
|
|
28
|
+
Rcov::RcovTask.new do |test|
|
|
29
|
+
test.libs << 'test'
|
|
30
|
+
test.pattern = 'test/**/*_test.rb'
|
|
31
|
+
test.verbose = true
|
|
32
|
+
end
|
|
33
|
+
rescue LoadError
|
|
34
|
+
task :rcov do
|
|
35
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
task :default => :test
|
|
41
|
+
|
|
42
|
+
require 'rake/rdoctask'
|
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
|
44
|
+
if File.exist?('VERSION.yml')
|
|
45
|
+
config = YAML.load(File.read('VERSION.yml'))
|
|
46
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
|
47
|
+
else
|
|
48
|
+
version = ""
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
52
|
+
rdoc.title = "acts_as_content_node #{version}"
|
|
53
|
+
rdoc.rdoc_files.include('README*')
|
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
55
|
+
end
|
|
56
|
+
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.1
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |s|
|
|
4
|
+
s.name = %q{acts_as_content_node}
|
|
5
|
+
s.version = "0.1.1"
|
|
6
|
+
|
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
8
|
+
s.authors = ["Steve England"]
|
|
9
|
+
s.date = %q{2009-06-24}
|
|
10
|
+
s.email = %q{steve@wearebeef.co.uk}
|
|
11
|
+
s.extra_rdoc_files = [
|
|
12
|
+
"LICENSE",
|
|
13
|
+
"README.rdoc"
|
|
14
|
+
]
|
|
15
|
+
s.files = [
|
|
16
|
+
".document",
|
|
17
|
+
".gitignore",
|
|
18
|
+
"LICENSE",
|
|
19
|
+
"README.rdoc",
|
|
20
|
+
"Rakefile",
|
|
21
|
+
"VERSION",
|
|
22
|
+
"acts_as_content_node.gemspec",
|
|
23
|
+
"app/helpers/content_nodes_helper.rb",
|
|
24
|
+
"app/views/content_nodes/_publish_select.html.erb",
|
|
25
|
+
"generators/content_node_scaffold/USAGE",
|
|
26
|
+
"generators/content_node_scaffold/content_node_scaffold_generator.rb",
|
|
27
|
+
"generators/content_node_scaffold/lib/insert_commands.rb",
|
|
28
|
+
"generators/content_node_scaffold/templates/admin_controller.rb",
|
|
29
|
+
"generators/content_node_scaffold/templates/admin_index.html.erb",
|
|
30
|
+
"generators/content_node_scaffold/templates/admin_show.html.erb",
|
|
31
|
+
"generators/content_node_scaffold/templates/helper.rb",
|
|
32
|
+
"generators/content_node_scaffold/templates/helper_test.rb",
|
|
33
|
+
"generators/content_node_scaffold/templates/layout.html.erb",
|
|
34
|
+
"generators/content_node_scaffold/templates/preview.js.rjs",
|
|
35
|
+
"generators/content_node_scaffold/templates/style.css",
|
|
36
|
+
"generators/content_node_scaffold/templates/view_controller.rb",
|
|
37
|
+
"generators/content_node_scaffold/templates/view_index.html.erb",
|
|
38
|
+
"generators/content_node_scaffold/templates/view_show.html.erb",
|
|
39
|
+
"init.rb",
|
|
40
|
+
"lib/acts_as_content_node.rb",
|
|
41
|
+
"lib/acts_as_content_node/content_node.rb",
|
|
42
|
+
"lib/acts_as_content_node/permalinks.rb",
|
|
43
|
+
"lib/acts_as_content_node/publishable.rb",
|
|
44
|
+
"rails/init.rb",
|
|
45
|
+
"tasks/acts_as_content_node_tasks.rake",
|
|
46
|
+
"test/acts_as_content_node_test.rb",
|
|
47
|
+
"test/database.yml",
|
|
48
|
+
"test/schema.rb",
|
|
49
|
+
"test/test_helper.rb"
|
|
50
|
+
]
|
|
51
|
+
s.homepage = %q{http://github.com/beef/acts_as_content_node}
|
|
52
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
53
|
+
s.require_paths = ["lib"]
|
|
54
|
+
s.rubygems_version = %q{1.3.3}
|
|
55
|
+
s.summary = %q{Common functions for an record used as content of a website. Generator for cms and front end}
|
|
56
|
+
s.test_files = [
|
|
57
|
+
"test/acts_as_content_node_test.rb",
|
|
58
|
+
"test/schema.rb",
|
|
59
|
+
"test/test_helper.rb"
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
if s.respond_to? :specification_version then
|
|
63
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
64
|
+
s.specification_version = 3
|
|
65
|
+
|
|
66
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
67
|
+
else
|
|
68
|
+
end
|
|
69
|
+
else
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module ContentNodesHelper
|
|
2
|
+
|
|
3
|
+
def content_status(node)
|
|
4
|
+
if node.published_at
|
|
5
|
+
'<span class="status approved">Approved</span>'
|
|
6
|
+
elsif node.published_at.nil?
|
|
7
|
+
'<span class="status draft">Draft</span>'
|
|
8
|
+
else
|
|
9
|
+
'<span class="status hidden">Hidden</span>'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def publish_select(form)
|
|
14
|
+
render :partial => '/content_nodes/publish_select', :locals => { :f => form}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<fieldset>
|
|
2
|
+
<legend>Publishing Options</legend>
|
|
3
|
+
<p>
|
|
4
|
+
<label for="article_published_at">Publish at</label><br/>
|
|
5
|
+
<%= check_box_tag 'live', true, params[:live], :onclick => 'toggle_published_at(this.checked)', :id => 'live' %>
|
|
6
|
+
<span id="published_at"><%= f.datetime_select 'published_at', :disabled => params[:live] ? nil : 'disabled' %></span>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p>
|
|
10
|
+
<label for="article_published_to">Publish till</label><br/>
|
|
11
|
+
<%= check_box_tag 'live', true, params[:live], :onclick => 'toggle_published_to(this.checked)', :id => 'live' %>
|
|
12
|
+
<span id="published_to"><%= f.datetime_select 'published_to', :disabled => params[:live] ? nil : 'disabled' %></span>
|
|
13
|
+
</p>
|
|
14
|
+
</fieldset>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
|
|
2
|
+
|
|
3
|
+
class ContentNodeScaffoldGenerator < ScaffoldGenerator
|
|
4
|
+
|
|
5
|
+
def initialize(runtime_args, runtime_options = {})
|
|
6
|
+
super
|
|
7
|
+
|
|
8
|
+
@args = ['title:string', 'permalink:string', 'published_at:datetime', 'published_to:datetime'] + @args
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def manifest
|
|
12
|
+
record do |m|
|
|
13
|
+
# Check for class naming collisions.
|
|
14
|
+
m.class_collisions("#{controller_class_name}Controller", "Admin::#{controller_class_name}Controller", "#{controller_class_name}Helper")
|
|
15
|
+
m.class_collisions(class_name)
|
|
16
|
+
|
|
17
|
+
# Controller, helper, views, test and stylesheets directories.
|
|
18
|
+
m.directory(File.join('app/models', class_path))
|
|
19
|
+
m.directory(File.join('app/controllers', controller_class_path))
|
|
20
|
+
m.directory(File.join('app/controllers/admin', controller_class_path))
|
|
21
|
+
m.directory(File.join('app/helpers', controller_class_path))
|
|
22
|
+
m.directory(File.join('app/views', controller_class_path, controller_file_name))
|
|
23
|
+
m.directory(File.join('app/views/admin', controller_class_path, controller_file_name))
|
|
24
|
+
m.directory(File.join('app/views/layouts', controller_class_path))
|
|
25
|
+
m.directory(File.join('test/unit', class_path))
|
|
26
|
+
m.directory(File.join('test/unit/helpers', class_path))
|
|
27
|
+
m.directory(File.join('public/stylesheets', class_path))
|
|
28
|
+
|
|
29
|
+
for action in ['index', 'show']
|
|
30
|
+
m.template(
|
|
31
|
+
"view_#{action}.html.erb",
|
|
32
|
+
File.join('app/views', controller_class_path, controller_file_name, "#{action}.html.erb")
|
|
33
|
+
)
|
|
34
|
+
m.template(
|
|
35
|
+
"admin_#{action}.html.erb",
|
|
36
|
+
File.join('app/views/admin', controller_class_path, controller_file_name, "#{action}.html.erb")
|
|
37
|
+
)
|
|
38
|
+
end
|
|
39
|
+
m.template('preview.js.rjs', File.join('app/views/admin', controller_class_path, controller_file_name, 'preview.js.rjs'))
|
|
40
|
+
|
|
41
|
+
# Layout and stylesheet.
|
|
42
|
+
m.template('layout.html.erb', File.join('app/views/layouts', controller_class_path, "application.html.erb"))
|
|
43
|
+
m.template('style.css', 'public/stylesheets/scaffold.css')
|
|
44
|
+
|
|
45
|
+
m.template(
|
|
46
|
+
'view_controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
|
|
47
|
+
)
|
|
48
|
+
m.template(
|
|
49
|
+
'admin_controller.rb', File.join('app/controllers/admin', controller_class_path, "#{controller_file_name}_controller.rb")
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
|
|
53
|
+
m.template('helper_test.rb', File.join('test/unit/helpers', controller_class_path, "#{controller_file_name}_helper_test.rb"))
|
|
54
|
+
|
|
55
|
+
m.route_resources ":#{controller_file_name}, :collection => { :preview => :get }"
|
|
56
|
+
m.route_resources_to_namespace('admin', "#{controller_file_name}, :collection => { :preview => :post }, :member => { :preview => :put }")
|
|
57
|
+
|
|
58
|
+
m.dependency 'model', [name, '--skip-fixture'] + @args, :collision => :skip
|
|
59
|
+
|
|
60
|
+
m.insert_into "app/models/#{singular_name}.rb", 'acts_as_content_node'
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Mostly pinched from http://github.com/ryanb/nifty-generators/tree/master
|
|
2
|
+
Rails::Generator::Commands::Base.class_eval do
|
|
3
|
+
def file_contains?(relative_destination, line)
|
|
4
|
+
File.read(destination_path(relative_destination)).include?(line)
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
Rails::Generator::Commands::Create.class_eval do
|
|
9
|
+
|
|
10
|
+
def insert_into(file, line)
|
|
11
|
+
logger.insert "#{line} into #{file}"
|
|
12
|
+
unless options[:pretend] || file_contains?(file, line)
|
|
13
|
+
gsub_file file, /^(class|module) .+$/ do |match|
|
|
14
|
+
"#{match}\n #{line}"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def route_resources(resource_list)
|
|
20
|
+
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
|
21
|
+
|
|
22
|
+
logger.route "map.resources #{resource_list}"
|
|
23
|
+
unless options[:pretend] || file_contains?('config/routes.rb', resource_list)
|
|
24
|
+
gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
|
|
25
|
+
"#{match}\n map.resources #{resource_list}"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def route_resources_to_namespace(namespace, resource_list)
|
|
31
|
+
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
|
32
|
+
|
|
33
|
+
namespace_map = "map.namespace(:#{namespace}) do |#{namespace}|"
|
|
34
|
+
logger.route namespace_map
|
|
35
|
+
unless options[:pretend] || file_contains?('config/routes.rb', namespace_map)
|
|
36
|
+
gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
|
|
37
|
+
"#{match}\n #{namespace_map}\n end"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
namespace_route = "#{namespace}.resources :#{resource_list}"
|
|
42
|
+
|
|
43
|
+
logger.route namespace_route
|
|
44
|
+
unless options[:pretend] || file_contains?('config/routes.rb', namespace_route)
|
|
45
|
+
gsub_file 'config/routes.rb', /(#{Regexp.escape(namespace_map)})/mi do |match|
|
|
46
|
+
"#{match}\n #{namespace_route}"
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
Rails::Generator::Commands::Destroy.class_eval do
|
|
54
|
+
|
|
55
|
+
def route_resources_to_namespace(namespace, resource_list)
|
|
56
|
+
# do ni
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def route_resources(resource_list)
|
|
60
|
+
look_for = " map.resources #{resource_list}\n".gsub(/[\[\]]/, '\\\\\0')
|
|
61
|
+
logger.route "map.resources #{resource_list} #{look_for}"
|
|
62
|
+
unless options[:pretend]
|
|
63
|
+
gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def insert_into(file, line)
|
|
68
|
+
logger.remove "#{line} from #{file}"
|
|
69
|
+
unless options[:pretend]
|
|
70
|
+
gsub_file file, "\n #{line}", ''
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
Rails::Generator::Commands::List.class_eval do
|
|
77
|
+
|
|
78
|
+
def route_resources_to_namespace(namespace, resource_list)
|
|
79
|
+
namespace_map = "map.namespace(:#{namespace}) do |#{namespace}|"
|
|
80
|
+
logger.route namespace_map
|
|
81
|
+
namespace_route = "#{namespace}.resources :#{resource_list}"
|
|
82
|
+
logger.route namespace_route
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def route_resources(resources_list)
|
|
86
|
+
logger.route "map.resource #{resource_list}"
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def insert_into(file, line)
|
|
90
|
+
logger.insert "#{line} into #{file}"
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
class Admin::<%= controller_class_name %>Controller < Admin::BaseController
|
|
2
|
+
sortable_attributes :<%= attributes.collect{|a| a.name}.join(', :') %>
|
|
3
|
+
|
|
4
|
+
def index
|
|
5
|
+
@<%= table_name %> = <%= class_name %>.paginate :page => params[:page], :order => sort_order
|
|
6
|
+
|
|
7
|
+
respond_to do |format|
|
|
8
|
+
format.html # index.html.erb
|
|
9
|
+
format.xml { render :xml => @<%= table_name %> }
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def show
|
|
14
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
|
15
|
+
|
|
16
|
+
respond_to do |format|
|
|
17
|
+
format.html
|
|
18
|
+
format.xml { render :xml => @<%= file_name %> }
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def new
|
|
23
|
+
@<%= file_name %> = <%= class_name %>.new
|
|
24
|
+
|
|
25
|
+
respond_to do |format|
|
|
26
|
+
format.html { render :action =>'show' }
|
|
27
|
+
format.xml { render :xml => @<%= file_name %> }
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def create
|
|
32
|
+
@<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>])
|
|
33
|
+
@<%= file_name %>.updated_by = @<%= file_name %>.created_by = current_user
|
|
34
|
+
|
|
35
|
+
respond_to do |format|
|
|
36
|
+
if @<%= file_name %>.save
|
|
37
|
+
flash[:notice] = '<%= class_name %> was successfully created.'
|
|
38
|
+
format.html { redirect_to(admin_<%= table_name %>_url) }
|
|
39
|
+
format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
|
|
40
|
+
else
|
|
41
|
+
format.html { render :action => "show" }
|
|
42
|
+
format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def update
|
|
48
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
|
49
|
+
@<%= file_name %>.updated_by = current_user
|
|
50
|
+
|
|
51
|
+
respond_to do |format|
|
|
52
|
+
if @<%= file_name %>.update_attributes(params[:<%= file_name %>])
|
|
53
|
+
flash[:notice] = '<%= class_name %> was successfully updated.'
|
|
54
|
+
format.html { redirect_to(admin_<%= table_name %>_url) }
|
|
55
|
+
format.xml { head :ok }
|
|
56
|
+
else
|
|
57
|
+
format.html { render :action => "show" }
|
|
58
|
+
format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def destroy
|
|
64
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
|
65
|
+
@<%= file_name %>.destroy
|
|
66
|
+
flash[:notice] = '<%= class_name %> was successfully deleted.'
|
|
67
|
+
|
|
68
|
+
respond_to do |format|
|
|
69
|
+
format.html { redirect_to(admin_<%= table_name %>_url) }
|
|
70
|
+
format.xml { head :ok }
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def preview
|
|
75
|
+
session[:<%= file_name %>_preview] = params[:<%= file_name %>]
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<h1>Listing <%= plural_name %></h1>
|
|
2
|
+
|
|
3
|
+
<ul class="choices">
|
|
4
|
+
<li><%%= link_to 'New <%= singular_name %>', new_admin_<%= singular_name %>_path %></li>
|
|
5
|
+
</ul>
|
|
6
|
+
|
|
7
|
+
<table>
|
|
8
|
+
<thead>
|
|
9
|
+
<tr>
|
|
10
|
+
<%%= sortable_table_header :name => "Title", :sort => "title" %>
|
|
11
|
+
<th>Status</th>
|
|
12
|
+
<th>Author</th>
|
|
13
|
+
<%%= sortable_table_header :name => "Updated", :sort => "updated_at" %>
|
|
14
|
+
<%%= sortable_table_header :name => "Published At", :sort => "published_at" %>
|
|
15
|
+
<%%= sortable_table_header :name => "Published To", :sort => "published_to" %>
|
|
16
|
+
<th colspan="3">Actions</th>
|
|
17
|
+
</tr>
|
|
18
|
+
</thead>
|
|
19
|
+
<tbody>
|
|
20
|
+
<%% @<%= plural_name %>.each do |<%= singular_name %>| %>
|
|
21
|
+
<tr id="<%= singular_name %>-<%%= <%= singular_name %>.id %>">
|
|
22
|
+
<td><%%=h <%= singular_name %>.title %></td>
|
|
23
|
+
<td><%%= content_status(<%= singular_name %>) %></td>
|
|
24
|
+
<td><%%= <%= singular_name %>.author %></td>
|
|
25
|
+
<td><%%= <%= singular_name %>.updated_at.strftime('%d %b') %></td>
|
|
26
|
+
<td><%%= <%= singular_name %>.published_at.strftime('%d %b') unless <%= singular_name %>.published_at.nil? %></td>
|
|
27
|
+
<td><%%= <%= singular_name %>.published_to.strftime('%d %b') unless <%= singular_name %>.published_to.nil? %></td>
|
|
28
|
+
<td><%%= link_to 'Show', <%= singular_name %>_path(<%= singular_name %>.permalink), :class => 'show' %></td>
|
|
29
|
+
<td><%%= link_to 'Edit', admin_<%= singular_name %>_path(<%= singular_name %>), :class => 'edit' %></td>
|
|
30
|
+
<td><%%= link_to 'Destroy', admin_<%= singular_name %>_path(<%= singular_name %>), :confirm => 'Are you sure?', :method => :delete, :class => 'delete' %></td>
|
|
31
|
+
</tr>
|
|
32
|
+
<%% end %>
|
|
33
|
+
</tbody>
|
|
34
|
+
<tfoot>
|
|
35
|
+
<tr>
|
|
36
|
+
<%%= sortable_table_header :name => "Title", :sort => "title" %>
|
|
37
|
+
<th>Status</th>
|
|
38
|
+
<th>Author</th>
|
|
39
|
+
<%%= sortable_table_header :name => "Updated", :sort => "updated_at" %>
|
|
40
|
+
<%%= sortable_table_header :name => "Published At", :sort => "published_at" %>
|
|
41
|
+
<%%= sortable_table_header :name => "Published To", :sort => "published_to" %>
|
|
42
|
+
<th colspan="3">Actions</th>
|
|
43
|
+
</tr>
|
|
44
|
+
</tfoot>
|
|
45
|
+
</table>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<%% content_for :header do %>
|
|
2
|
+
<%%= javascript_include_tag 'lightwindow' %>
|
|
3
|
+
<%%= stylesheet_link_tag 'lightwindow' %>
|
|
4
|
+
<%% end -%>
|
|
5
|
+
|
|
6
|
+
<h1><%%= @<%= singular_name %>.new_record? ? 'New' : 'Editing' %> <%= singular_name %></h1>
|
|
7
|
+
|
|
8
|
+
<%% form_for([:admin, @<%= singular_name %>]) do |f| %>
|
|
9
|
+
<%%= f.error_messages %>
|
|
10
|
+
|
|
11
|
+
<p>
|
|
12
|
+
<%%= f.label :title %><br/>
|
|
13
|
+
<%%= f.text_field :title, :class => 'title' %>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
<% for attribute in attributes.reject{ |a| ['title', 'published_at', 'published_to', 'permalink' ].include?(a.name) } -%>
|
|
17
|
+
<p>
|
|
18
|
+
<%%= f.label :<%= attribute.name %> %><br />
|
|
19
|
+
<%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
|
|
20
|
+
</p>
|
|
21
|
+
<% end -%>
|
|
22
|
+
|
|
23
|
+
<%%= publish_select(f) %>
|
|
24
|
+
|
|
25
|
+
<p class="submission">
|
|
26
|
+
<%%= preview_link(@<%= singular_name %>) %>
|
|
27
|
+
<%%= f.submit 'Publish', :name => '<%= singular_name %>[publish]' %>
|
|
28
|
+
<%%= f.submit 'Save as draft', :name => '<%= singular_name %>[hide]' %>
|
|
29
|
+
or <%%= link_to 'Back', admin_<%= plural_name %>_path %>
|
|
30
|
+
</p>
|
|
31
|
+
<%% end %>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
3
|
+
|
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
5
|
+
<head>
|
|
6
|
+
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
|
7
|
+
<title><%= controller_class_name %>: <%%= controller.action_name %></title>
|
|
8
|
+
<%%= stylesheet_link_tag 'scaffold' %>
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
|
|
12
|
+
<p style="color: green"><%%= flash[:notice] %></p>
|
|
13
|
+
|
|
14
|
+
<%%= yield %>
|
|
15
|
+
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
page << "myLightWindow.activateWindow({href: '#{preview_<%= table_name %>_path}', title: 'This is only a preview'});"
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
body { background-color: #fff; color: #333; }
|
|
2
|
+
|
|
3
|
+
body, p, ol, ul, td {
|
|
4
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
|
5
|
+
font-size: 13px;
|
|
6
|
+
line-height: 18px;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
pre {
|
|
10
|
+
background-color: #eee;
|
|
11
|
+
padding: 10px;
|
|
12
|
+
font-size: 11px;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
a { color: #000; }
|
|
16
|
+
a:visited { color: #666; }
|
|
17
|
+
a:hover { color: #fff; background-color:#000; }
|
|
18
|
+
|
|
19
|
+
.fieldWithErrors {
|
|
20
|
+
padding: 2px;
|
|
21
|
+
background-color: red;
|
|
22
|
+
display: table;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
#errorExplanation {
|
|
26
|
+
width: 400px;
|
|
27
|
+
border: 2px solid red;
|
|
28
|
+
padding: 7px;
|
|
29
|
+
padding-bottom: 12px;
|
|
30
|
+
margin-bottom: 20px;
|
|
31
|
+
background-color: #f0f0f0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
#errorExplanation h2 {
|
|
35
|
+
text-align: left;
|
|
36
|
+
font-weight: bold;
|
|
37
|
+
padding: 5px 5px 5px 15px;
|
|
38
|
+
font-size: 12px;
|
|
39
|
+
margin: -7px;
|
|
40
|
+
background-color: #c00;
|
|
41
|
+
color: #fff;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
#errorExplanation p {
|
|
45
|
+
color: #333;
|
|
46
|
+
margin-bottom: 0;
|
|
47
|
+
padding: 5px;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
#errorExplanation ul li {
|
|
51
|
+
font-size: 12px;
|
|
52
|
+
list-style: square;
|
|
53
|
+
}
|
|
54
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
|
2
|
+
# GET /<%= table_name %>
|
|
3
|
+
# GET /<%= table_name %>.xml
|
|
4
|
+
def index
|
|
5
|
+
@<%= table_name %> = <%= class_name %>.all
|
|
6
|
+
|
|
7
|
+
respond_to do |format|
|
|
8
|
+
format.html # index.html.erb
|
|
9
|
+
format.xml { render :xml => @<%= table_name %> }
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# GET /<%= table_name %>/1
|
|
14
|
+
# GET /<%= table_name %>/1.xml
|
|
15
|
+
def show
|
|
16
|
+
@<%= file_name %> = <%= class_name %>.find_by_permalink(params[:id])
|
|
17
|
+
|
|
18
|
+
respond_to do |format|
|
|
19
|
+
format.html # show.html.erb
|
|
20
|
+
format.xml { render :xml => @<%= file_name %> }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def preview
|
|
25
|
+
@page_id = '<%= table_name %>'
|
|
26
|
+
@page_class = 'show'
|
|
27
|
+
@<%= file_name %> = <%= class_name %>.new(session[:<%= file_name %>_preview])
|
|
28
|
+
session[:<%= file_name %>_preview] = nil
|
|
29
|
+
render :action => "show"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<h1>Listing <%= plural_name %></h1>
|
|
2
|
+
|
|
3
|
+
<table>
|
|
4
|
+
<tr>
|
|
5
|
+
<% for attribute in attributes -%>
|
|
6
|
+
<th><%= attribute.column.human_name %></th>
|
|
7
|
+
<% end -%>
|
|
8
|
+
</tr>
|
|
9
|
+
|
|
10
|
+
<%% @<%= plural_name %>.each do |<%= singular_name %>| %>
|
|
11
|
+
<tr>
|
|
12
|
+
<% for attribute in attributes -%>
|
|
13
|
+
<td><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
|
|
14
|
+
<% end -%>
|
|
15
|
+
</tr>
|
|
16
|
+
<%% end %>
|
|
17
|
+
</table>
|
data/init.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + "/rails/init"
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
module Beef
|
|
2
|
+
module Acts
|
|
3
|
+
module ContentNode
|
|
4
|
+
module ClassMethods
|
|
5
|
+
def acts_as_content_node
|
|
6
|
+
|
|
7
|
+
belongs_to :updated_by, :class_name => 'User'
|
|
8
|
+
belongs_to :created_by, :class_name => 'User'
|
|
9
|
+
|
|
10
|
+
named_scope :authored_by, lambda { |user|
|
|
11
|
+
return {} if user.nil?
|
|
12
|
+
user = User.find(user) unless user.is_a? User
|
|
13
|
+
{ :conditions => { :created_by_id => user.id } }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
before_save :set_url
|
|
17
|
+
|
|
18
|
+
validates_presence_of :title
|
|
19
|
+
validates_uniqueness_of :title, :message => 'has been used before'
|
|
20
|
+
validates_uniqueness_of :permalink, :message => 'has been used before', :if => :permalink_written
|
|
21
|
+
|
|
22
|
+
attr_reader :permalink_written
|
|
23
|
+
|
|
24
|
+
def find_by_permalink(permalink)
|
|
25
|
+
content_node = find(:first, :conditions => ['permalink = ?', permalink])
|
|
26
|
+
raise ActiveRecord::RecordNotFound, "Couldn't find #{name} with permalink #{permalink}" if content_node.nil?
|
|
27
|
+
content_node
|
|
28
|
+
end
|
|
29
|
+
acts_as_publishable
|
|
30
|
+
|
|
31
|
+
send :include, InstanceMethods
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
module InstanceMethods
|
|
36
|
+
|
|
37
|
+
def permalink=(permalink)
|
|
38
|
+
unless permalink.blank?
|
|
39
|
+
write_attribute :permalink, permalink.parameterize
|
|
40
|
+
@permalink_written = true
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def editor
|
|
45
|
+
updated_by.nil? ? 'Anon' : updated_by.read_attribute(:name)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def author
|
|
49
|
+
created_by.nil? ? 'Anon' : created_by.read_attribute(:name)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def short_desc
|
|
53
|
+
unless description.nil?
|
|
54
|
+
description.split('.').first
|
|
55
|
+
else
|
|
56
|
+
''
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
private
|
|
61
|
+
|
|
62
|
+
def set_url
|
|
63
|
+
write_attribute :permalink, title.parameterize unless permalink_written or !title_changed?
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def self.included(base)
|
|
69
|
+
base.extend ClassMethods
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Beef
|
|
2
|
+
module Permalinks
|
|
3
|
+
|
|
4
|
+
def permalink(record, options = {})
|
|
5
|
+
record_method_name = record.class.name.underscore
|
|
6
|
+
method_name = "#{record_method_name}_permalink"
|
|
7
|
+
|
|
8
|
+
if respond_to?(method_name)
|
|
9
|
+
send(method_name, record, options)
|
|
10
|
+
elsif record.respond_to?('permalink')
|
|
11
|
+
send("#{record_method_name}_path", record.permalink, options)
|
|
12
|
+
else
|
|
13
|
+
record
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module Beef
|
|
2
|
+
module Acts
|
|
3
|
+
module Publishable
|
|
4
|
+
module ClassMethods
|
|
5
|
+
def acts_as_publishable
|
|
6
|
+
send :include, InstanceMethods
|
|
7
|
+
|
|
8
|
+
named_scope :published, lambda { { :conditions => ['published_at != \'\' AND published_at < ? AND (published_to > ? OR published_to is null)', Time.zone.now, Time.zone.now] } }
|
|
9
|
+
|
|
10
|
+
before_save :set_published
|
|
11
|
+
|
|
12
|
+
attr_accessor :publish, :hide
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
module InstanceMethods
|
|
17
|
+
|
|
18
|
+
def published?
|
|
19
|
+
return false if published_at.nil?
|
|
20
|
+
@published ||= published_at < Time.zone.now
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def set_published
|
|
26
|
+
write_attribute :published_at, Time.zone.now if @publish and published_at.nil?
|
|
27
|
+
if @hide
|
|
28
|
+
write_attribute :published_at, nil
|
|
29
|
+
write_attribute :published_to, nil
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.included(base)
|
|
35
|
+
base.extend ClassMethods
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
data/rails/init.rb
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require "acts_as_content_node/content_node"
|
|
2
|
+
require "acts_as_content_node/publishable"
|
|
3
|
+
require "acts_as_content_node/permalinks"
|
|
4
|
+
|
|
5
|
+
config.to_prepare do
|
|
6
|
+
ApplicationController.helper(ContentNodesHelper)
|
|
7
|
+
ApplicationController.helper(Beef::Permalinks)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
ActiveRecord::Base.send :include, Beef::Acts::ContentNode
|
|
11
|
+
ActiveRecord::Base.send :include, Beef::Acts::Publishable
|
|
12
|
+
ActionController::Base.send :include, Beef::Permalinks
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class ContentNodeTest < Test::Unit::TestCase
|
|
4
|
+
should_validate_presence_of :title
|
|
5
|
+
|
|
6
|
+
should_belong_to :updated_by
|
|
7
|
+
should_belong_to :created_by
|
|
8
|
+
|
|
9
|
+
context "With an exisiting content node" do
|
|
10
|
+
setup do
|
|
11
|
+
@content_node = Factory(:content_node)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
should_validate_uniqueness_of :title, :message => 'has been used before'
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
context 'When permalink is not set it' do
|
|
20
|
+
setup do
|
|
21
|
+
@title = 'My nice article'
|
|
22
|
+
@content_node = Factory(:content_node, :title => @title)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
should "be based on title" do
|
|
26
|
+
assert_equal @content_node.permalink, @title.parameterize
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
should "be based on permalink set when updated" do
|
|
30
|
+
@content_node.update_attributes(:permalink => 'a-perma')
|
|
31
|
+
assert_equal @content_node.permalink, 'a-perma'.parameterize
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
teardown do
|
|
35
|
+
@content_node.destroy
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
context 'When permalink is set' do
|
|
40
|
+
setup do
|
|
41
|
+
@permalink = 'something-else'
|
|
42
|
+
@content_node = Factory(:content_node, :permalink => @permalink)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
should_validate_uniqueness_of :permalink, :message => 'has been used before'
|
|
46
|
+
|
|
47
|
+
should "be the permalink" do
|
|
48
|
+
assert_equal @content_node.permalink, @permalink.parameterize
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
should "be based on title if updated and title changed" do
|
|
52
|
+
@content_node = ContentNode.first
|
|
53
|
+
@content_node.update_attributes(:title => 'New Title')
|
|
54
|
+
assert_equal @content_node.permalink, 'New Title'.parameterize
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
should "be the permalink if updated and title not changed" do
|
|
58
|
+
@content_node = ContentNode.first
|
|
59
|
+
@content_node.save
|
|
60
|
+
assert_equal @content_node.permalink, @permalink.parameterize
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
teardown do
|
|
64
|
+
@content_node.destroy
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
context 'When publish is set' do
|
|
69
|
+
setup do
|
|
70
|
+
@content_node = Factory(:content_node, :publish => true)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
should "be based published" do
|
|
74
|
+
assert @content_node.published?
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
should "not be published if updated and hide set" do
|
|
78
|
+
@content_node.update_attributes(:hide => true)
|
|
79
|
+
assert !@content_node.published?
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
# teardown do
|
|
84
|
+
# @content_node.destroy
|
|
85
|
+
# end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
end
|
data/test/database.yml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
sqlite:
|
|
2
|
+
:adapter: sqlite
|
|
3
|
+
:dbfile: acts_as_content_node_plugin.sqlite.db
|
|
4
|
+
sqlite3:
|
|
5
|
+
:adapter: sqlite3
|
|
6
|
+
:dbfile: acts_as_content_node_plugin.sqlite3.db
|
|
7
|
+
sqlite3mem:
|
|
8
|
+
:adapter: sqlite3
|
|
9
|
+
:dbfile: ":memory:"
|
|
10
|
+
postgresql:
|
|
11
|
+
:adapter: postgresql
|
|
12
|
+
:username: postgres
|
|
13
|
+
:password: postgres
|
|
14
|
+
:database: acts_as_content_node_plugin_test
|
|
15
|
+
:min_messages: ERROR
|
|
16
|
+
mysql:
|
|
17
|
+
:adapter: mysql
|
|
18
|
+
:host: localhost
|
|
19
|
+
:username: rails
|
|
20
|
+
:password:
|
|
21
|
+
:database: acts_as_content_node_plugin_test
|
data/test/schema.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
ActiveRecord::Schema.define(:version => 0) do
|
|
2
|
+
create_table :content_nodes, :force => true do |t|
|
|
3
|
+
t.string :title
|
|
4
|
+
t.string :permalink
|
|
5
|
+
t.string :description
|
|
6
|
+
t.text :body
|
|
7
|
+
t.datetime :published_at
|
|
8
|
+
t.datetime :published_to
|
|
9
|
+
t.datetime :created_at
|
|
10
|
+
t.datetime :updated_at
|
|
11
|
+
t.references :updated_by, :created_by
|
|
12
|
+
end
|
|
13
|
+
end
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require 'active_record'
|
|
4
|
+
require 'shoulda/rails'
|
|
5
|
+
require 'factory_girl'
|
|
6
|
+
require 'faker'
|
|
7
|
+
|
|
8
|
+
# Setting this makes parameterize work
|
|
9
|
+
$KCODE = 'UTF8'
|
|
10
|
+
|
|
11
|
+
# Makes TimeZone work
|
|
12
|
+
Time.zone = 'UTC'
|
|
13
|
+
|
|
14
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
15
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
16
|
+
|
|
17
|
+
RAILS_DEFAULT_LOGGER = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
|
|
18
|
+
|
|
19
|
+
require File.join(File.dirname(__FILE__), '..', 'init')
|
|
20
|
+
|
|
21
|
+
ActiveRecord::Base.configurations = YAML::load(IO.read(File.dirname(__FILE__) + "/database.yml"))
|
|
22
|
+
ActiveRecord::Base.establish_connection(ENV["DB"] || "sqlite3mem")
|
|
23
|
+
ActiveRecord::Migration.verbose = false
|
|
24
|
+
load(File.join(File.dirname(__FILE__), "schema.rb"))
|
|
25
|
+
|
|
26
|
+
class ContentNode < ActiveRecord::Base
|
|
27
|
+
acts_as_content_node
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
Factory.define(:content_node) do |content_node|
|
|
31
|
+
content_node.title {Faker::Lorem.words(5).join(' ')}
|
|
32
|
+
content_node.description {Faker::Lorem.sentence}
|
|
33
|
+
content_node.body {Faker::Lorem.paragraphs.join}
|
|
34
|
+
end
|
|
35
|
+
|
metadata
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: beef-acts_as_content_node
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Steve England
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-06-24 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description:
|
|
17
|
+
email: steve@wearebeef.co.uk
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- LICENSE
|
|
24
|
+
- README.rdoc
|
|
25
|
+
files:
|
|
26
|
+
- .document
|
|
27
|
+
- .gitignore
|
|
28
|
+
- LICENSE
|
|
29
|
+
- README.rdoc
|
|
30
|
+
- Rakefile
|
|
31
|
+
- VERSION
|
|
32
|
+
- acts_as_content_node.gemspec
|
|
33
|
+
- app/helpers/content_nodes_helper.rb
|
|
34
|
+
- app/views/content_nodes/_publish_select.html.erb
|
|
35
|
+
- generators/content_node_scaffold/USAGE
|
|
36
|
+
- generators/content_node_scaffold/content_node_scaffold_generator.rb
|
|
37
|
+
- generators/content_node_scaffold/lib/insert_commands.rb
|
|
38
|
+
- generators/content_node_scaffold/templates/admin_controller.rb
|
|
39
|
+
- generators/content_node_scaffold/templates/admin_index.html.erb
|
|
40
|
+
- generators/content_node_scaffold/templates/admin_show.html.erb
|
|
41
|
+
- generators/content_node_scaffold/templates/helper.rb
|
|
42
|
+
- generators/content_node_scaffold/templates/helper_test.rb
|
|
43
|
+
- generators/content_node_scaffold/templates/layout.html.erb
|
|
44
|
+
- generators/content_node_scaffold/templates/preview.js.rjs
|
|
45
|
+
- generators/content_node_scaffold/templates/style.css
|
|
46
|
+
- generators/content_node_scaffold/templates/view_controller.rb
|
|
47
|
+
- generators/content_node_scaffold/templates/view_index.html.erb
|
|
48
|
+
- generators/content_node_scaffold/templates/view_show.html.erb
|
|
49
|
+
- init.rb
|
|
50
|
+
- lib/acts_as_content_node.rb
|
|
51
|
+
- lib/acts_as_content_node/content_node.rb
|
|
52
|
+
- lib/acts_as_content_node/permalinks.rb
|
|
53
|
+
- lib/acts_as_content_node/publishable.rb
|
|
54
|
+
- rails/init.rb
|
|
55
|
+
- tasks/acts_as_content_node_tasks.rake
|
|
56
|
+
- test/acts_as_content_node_test.rb
|
|
57
|
+
- test/database.yml
|
|
58
|
+
- test/schema.rb
|
|
59
|
+
- test/test_helper.rb
|
|
60
|
+
has_rdoc: false
|
|
61
|
+
homepage: http://github.com/beef/acts_as_content_node
|
|
62
|
+
post_install_message:
|
|
63
|
+
rdoc_options:
|
|
64
|
+
- --charset=UTF-8
|
|
65
|
+
require_paths:
|
|
66
|
+
- lib
|
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
|
+
requirements:
|
|
69
|
+
- - ">="
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: "0"
|
|
72
|
+
version:
|
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
|
+
requirements:
|
|
75
|
+
- - ">="
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: "0"
|
|
78
|
+
version:
|
|
79
|
+
requirements: []
|
|
80
|
+
|
|
81
|
+
rubyforge_project:
|
|
82
|
+
rubygems_version: 1.2.0
|
|
83
|
+
signing_key:
|
|
84
|
+
specification_version: 3
|
|
85
|
+
summary: Common functions for an record used as content of a website. Generator for cms and front end
|
|
86
|
+
test_files:
|
|
87
|
+
- test/acts_as_content_node_test.rb
|
|
88
|
+
- test/schema.rb
|
|
89
|
+
- test/test_helper.rb
|