spud_cms 0.4.8 → 0.7.0
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/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +40 -0
- data/app/controllers/pages_controller.rb +5 -0
- data/app/controllers/spud/admin/pages_controller.rb +4 -4
- data/app/helpers/spud/cms/application_helper.rb +23 -3
- data/app/models/page_sweeper.rb +18 -1
- data/app/models/spud_page.rb +45 -4
- data/app/views/pages/show.html.erb +3 -1
- data/config/routes.rb +5 -1
- data/db/migrate/20120101192412_create_spud_pages.rb +19 -0
- data/db/migrate/20120101193138_create_spud_menus.rb +10 -0
- data/db/migrate/20120101193255_create_spud_menu_items.rb +17 -0
- data/db/migrate/20120101194124_create_spud_templates.rb +11 -0
- data/db/migrate/20120103034659_create_spud_page_partials.rb +13 -0
- data/db/migrate/20120104194032_add_visibility_to_spud_pages.rb +6 -0
- data/db/migrate/20120107181337_add_menu_name_to_spud_menu_items.rb +5 -0
- data/db/migrate/20120111134754_add_use_custom_url_name_to_spud_pages.rb +5 -0
- data/db/migrate/20120118141852_add_notes_to_spud_pages.rb +5 -0
- data/db/migrate/20120126232428_add_menu_id_to_spud_menu_items.rb +7 -0
- data/db/migrate/20120128163601_add_classes_to_spud_menu_items.rb +6 -0
- data/lib/spud_cms/engine.rb +11 -1
- data/lib/spud_cms/page_route.rb +3 -0
- data/lib/spud_cms/version.rb +5 -0
- data/lib/spud_cms.rb +2 -1
- data/lib/tasks/spud_cms_tasks.rake +4 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/{config → test/dummy/config}/application.rb +18 -7
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +15 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +3 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/migrate/20120307002859_create_spud_admin_permissions.spud_core.rb +12 -0
- data/test/dummy/db/migrate/20120307002860_create_spud_users.spud_core.rb +30 -0
- data/test/dummy/db/migrate/20120307003559_create_spud_permalinks.spud_permalinks.rb +12 -0
- data/test/dummy/db/schema.rb +124 -0
- data/test/dummy/log/development.log +437 -0
- data/test/dummy/log/test.log +2280 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/spud_cms_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +206 -18
- data/README.markdown +0 -71
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 YOURNAME
|
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,40 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'SpudCms'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
Bundler::GemHelper.install_tasks
|
29
|
+
|
30
|
+
require 'rake/testtask'
|
31
|
+
|
32
|
+
# Rake::TestTask.new(:test) do |t|
|
33
|
+
# t.libs << 'lib'
|
34
|
+
# t.libs << 'test'
|
35
|
+
# t.pattern = 'test/**/*_test.rb'
|
36
|
+
# t.verbose = false
|
37
|
+
# end
|
38
|
+
|
39
|
+
|
40
|
+
task :default => [:spec]
|
@@ -11,6 +11,11 @@ class PagesController < ApplicationController
|
|
11
11
|
url_name = !params[:id].blank? ? params[:id] : Spud::Cms.root_page_name
|
12
12
|
@page = SpudPage.published_pages.where(:url_name => url_name).includes([:spud_template,:spud_page_partials]).first
|
13
13
|
if @page.blank?
|
14
|
+
@permalink = SpudPermalink.includes(:attachment).where(:url_name => url_name).first
|
15
|
+
if !@permalink.blank? && @permalink.attachment_type == 'SpudPage'
|
16
|
+
redirect_to @permalink.attachment.url_name == Spud::Cms.root_page_name ? root_url() : page_url(:id => @permalink.attachment.url_name) , :status => :moved_permanently and return
|
17
|
+
end
|
18
|
+
|
14
19
|
flash[:error] = "Page not found"
|
15
20
|
if !params[:id].blank?
|
16
21
|
redirect_to root_url() and return
|
@@ -40,7 +40,7 @@ class Spud::Admin::PagesController < Spud::Admin::ApplicationController
|
|
40
40
|
@templates = SpudTemplate.all
|
41
41
|
@page = SpudPage.new
|
42
42
|
Spud::Cms.default_page_parts.each do |part|
|
43
|
-
@page.spud_page_partials.new(:name => part)
|
43
|
+
@page.spud_page_partials.new(:name => part.strip)
|
44
44
|
end
|
45
45
|
respond_with @page
|
46
46
|
end
|
@@ -58,14 +58,14 @@ class Spud::Admin::PagesController < Spud::Admin::ApplicationController
|
|
58
58
|
@templates = SpudTemplate.all
|
59
59
|
if @page.spud_page_partials.blank?
|
60
60
|
Spud::Cms.default_page_parts.each do |part|
|
61
|
-
@page.spud_page_partials.new(:name => part)
|
61
|
+
@page.spud_page_partials.new(:name => part.strip)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
if !@page.spud_template.blank?
|
65
65
|
@page.spud_template.page_parts.split(",").each do |part|
|
66
|
-
partial = @page.spud_page_partials.select{|p| p.name == part}
|
66
|
+
partial = @page.spud_page_partials.select{|p| p.name == part.strip}
|
67
67
|
if partial.blank?
|
68
|
-
@page.spud_page_partials.new(:name => part)
|
68
|
+
@page.spud_page_partials.new(:name => part.strip)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
@@ -68,7 +68,17 @@ module Spud::Cms::ApplicationHelper
|
|
68
68
|
|
69
69
|
|
70
70
|
grouped_items["SpudMenu"].sort_by{|p| p.menu_order}.each do |item|
|
71
|
-
|
71
|
+
active = false
|
72
|
+
if !item.url_name.blank?
|
73
|
+
if current_page?(page_path(:id => item.url_name))
|
74
|
+
active = true
|
75
|
+
elsif item.url_name == Spud::Cms.root_page_name && current_page?(root_path)
|
76
|
+
active = true
|
77
|
+
end
|
78
|
+
elsif current_page?(item.url)
|
79
|
+
active = true
|
80
|
+
end
|
81
|
+
content += "<li><a class='#{"menu-active" if active} #{item.classes if !item.classes.blank?}' href='#{!item.url_name.blank? ? (item.url_name == Spud::Cms.root_page_name ? root_path() : page_path(:id => item.url_name)) : item.url}'>#{item.name}</a>"
|
72
82
|
if max_depth == 0 || max_depth > 1
|
73
83
|
content += sp_list_menu_item(child_items,item.id,2,max_depth)
|
74
84
|
end
|
@@ -90,7 +100,7 @@ module Spud::Cms::ApplicationHelper
|
|
90
100
|
|
91
101
|
menu_tags = []
|
92
102
|
menu_items.sort_by{|p| p.menu_order}.each do |item|
|
93
|
-
menu_tags += ["<a #{"class='#{item.classes}' " if !item.classes.blank?}href='#{!item.url_name.blank? ? page_path(:id => item.url_name) : item.url}'>#{item.name}</a>"]
|
103
|
+
menu_tags += ["<a #{"class='#{item.classes}' " if !item.classes.blank?}href='#{!item.url_name.blank? ? (item.url_name == Spud::Cms.root_page_name ? root_path() : page_path(:id => item.url_name)) : item.url}'>#{item.name}</a>"]
|
94
104
|
end
|
95
105
|
|
96
106
|
return menu_tags.join(seperator).html_safe
|
@@ -105,7 +115,17 @@ private
|
|
105
115
|
content = "<ul>"
|
106
116
|
|
107
117
|
spud_menu_items.sort_by{|p| p.menu_order}.each do |item|
|
108
|
-
|
118
|
+
active = false
|
119
|
+
if !item.url_name.blank?
|
120
|
+
if current_page?(page_path(:id => item.url_name))
|
121
|
+
active = true
|
122
|
+
elsif item.url_name == Spud::Cms.root_page_name && current_page?(root_path)
|
123
|
+
active = true
|
124
|
+
end
|
125
|
+
elsif current_page?(item.url)
|
126
|
+
active = true
|
127
|
+
end
|
128
|
+
content += "<li><a class='#{"menu-active" if active} #{item.classes if !item.classes.blank?}' href='#{!item.url_name.blank? ? (item.url_name == Spud::Cms.root_page_name ? root_path() : page_path(:id => item.url_name)) : item.url}'>#{item.name}</a>"
|
109
129
|
if max_depth == 0 || max_depth > depth
|
110
130
|
content += sp_list_menu_item(items,item.id,depth+1,max_depth)
|
111
131
|
end
|
data/app/models/page_sweeper.rb
CHANGED
@@ -1,6 +1,23 @@
|
|
1
1
|
class PageSweeper < ActionController::Caching::Sweeper
|
2
2
|
observe SpudPage,SpudTemplate,SpudMenuItem
|
3
3
|
|
4
|
+
def before_save(record)
|
5
|
+
if record.is_a?(SpudPage) && record.changed_attributes.has_key?("url_name")
|
6
|
+
if Spud::Cms.enable_full_page_caching
|
7
|
+
if record.changed_attributes["url_name"] == Spud::Cms.root_page_name
|
8
|
+
expire_page root_path
|
9
|
+
else
|
10
|
+
expire_page page_path(:id => record.changed_attributes["url_name"])
|
11
|
+
end
|
12
|
+
elsif Spud::Cms.enable_action_caching
|
13
|
+
if record.changed_attributes["url_name"] == Spud::Cms.root_page_name
|
14
|
+
expire_action root_path
|
15
|
+
else
|
16
|
+
expire_action page_path(:id => record.changed_attributes["url_name"])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
4
21
|
def after_save(record)
|
5
22
|
expire_cache_for(record)
|
6
23
|
expire_page spud_cms_sitemap_path
|
@@ -23,7 +40,7 @@ private
|
|
23
40
|
expire_page root_path
|
24
41
|
else
|
25
42
|
expire_page page_path(:id => record.url_name)
|
26
|
-
|
43
|
+
end
|
27
44
|
elsif Spud::Cms.enable_action_caching
|
28
45
|
if record.url_name == Spud::Cms.root_page_name
|
29
46
|
expire_action root_path
|
data/app/models/spud_page.rb
CHANGED
@@ -4,6 +4,7 @@ class SpudPage < ActiveRecord::Base
|
|
4
4
|
belongs_to :spud_template,:foreign_key => :template_id
|
5
5
|
has_many :spud_pages, :dependent => :nullify
|
6
6
|
has_many :spud_page_partials,:dependent => :destroy
|
7
|
+
has_many :spud_permalinks,:as => :attachment, :dependent => :destroy
|
7
8
|
belongs_to :created_by_user,:class_name => "SpudUser",:foreign_key => :created_by
|
8
9
|
belongs_to :updated_by_user,:class_name => "SpudUser",:foreign_key => :updated_by
|
9
10
|
|
@@ -46,22 +47,62 @@ class SpudPage < ActiveRecord::Base
|
|
46
47
|
def generate_url_name
|
47
48
|
return true if self.name.blank?
|
48
49
|
if !self.use_custom_url_name || self.url_name.blank?
|
49
|
-
|
50
|
-
|
50
|
+
url_name = ""
|
51
|
+
if !self.spud_page.blank?
|
52
|
+
url_name += self.spud_page.url_name + "/"
|
53
|
+
end
|
54
|
+
url_name += self.name.parameterize.downcase
|
51
55
|
if !self.use_custom_url_name
|
52
56
|
pages = SpudPage
|
57
|
+
|
53
58
|
if !self.id.blank?
|
54
59
|
pages = pages.where("id != #{self.id}")
|
55
60
|
end
|
56
61
|
url_names = pages.all.collect{|p| p.url_name}
|
62
|
+
|
57
63
|
counter = 1
|
58
|
-
|
59
|
-
|
64
|
+
url_name_new = url_name
|
65
|
+
while url_names.include?(url_name_new) do
|
66
|
+
url_name_new = url_name + "-#{counter}"
|
60
67
|
counter += 1
|
61
68
|
end
|
69
|
+
# url_name = url_name_new
|
70
|
+
# Check Permalinks List
|
71
|
+
|
72
|
+
permalink = SpudPermalink.where(:url_name => url_name_new).first
|
73
|
+
counter = 1
|
74
|
+
while permalink.blank? == false
|
75
|
+
|
76
|
+
if permalink.attachment == self
|
77
|
+
permalink.destroy
|
78
|
+
permalink = nil
|
79
|
+
else
|
80
|
+
url_name_new = url_name + "-#{counter}"
|
81
|
+
counter += 1
|
82
|
+
permalink = SpudPermalink.where(:url_name => url_name_new).first
|
83
|
+
end
|
84
|
+
end
|
85
|
+
url_name = url_name_new
|
62
86
|
end
|
87
|
+
if self.url_name.blank? == false && url_name != self.url_name
|
88
|
+
self.spud_permalinks.create(:url_name => self.url_name)
|
89
|
+
end
|
63
90
|
self.url_name = url_name
|
64
91
|
self.use_custom_url_name = false
|
92
|
+
elsif self.id.to_i > 0
|
93
|
+
page = SpudPage.where(:id => self.id).first
|
94
|
+
if page.url_name.blank? == false && page.url_name != self.url_name
|
95
|
+
permalink = SpudPermalink.where(:url_name => self.url_name).first
|
96
|
+
if permalink.blank? == false
|
97
|
+
if permalink.attachment == self
|
98
|
+
permalink.destroy
|
99
|
+
else
|
100
|
+
self.errors.add :url_name, "This permalink has already been used by another page."
|
101
|
+
return false
|
102
|
+
end
|
103
|
+
end
|
104
|
+
self.spud_permalinks.create(:url_name => page.url_name)
|
105
|
+
end
|
65
106
|
end
|
66
107
|
return true
|
67
108
|
end
|
data/config/routes.rb
CHANGED
@@ -16,7 +16,11 @@ Rails.application.routes.draw do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
root :to => 'pages#show'
|
19
|
-
|
19
|
+
|
20
|
+
# This is located in lib/spud_cms/page_route.rb to make sure it is loaded last
|
21
|
+
# match "*id", :controller => "pages",:action => "show", :as => "page"
|
20
22
|
|
21
23
|
end
|
24
|
+
Spud::Cms::Engine.routes.draw do
|
25
|
+
end
|
22
26
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreateSpudPages < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :spud_pages do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :url_name
|
6
|
+
t.datetime :publish_at
|
7
|
+
t.integer :created_by
|
8
|
+
t.integer :updated_by
|
9
|
+
t.string :format,:default => "html"
|
10
|
+
t.integer :spud_page_id
|
11
|
+
t.text :meta_description
|
12
|
+
t.string :meta_keywords
|
13
|
+
t.integer :page_order
|
14
|
+
t.integer :template_id
|
15
|
+
|
16
|
+
t.timestamps
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateSpudMenuItems < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :spud_menu_items do |t|
|
4
|
+
t.string :parent_type
|
5
|
+
t.integer :parent_id
|
6
|
+
t.integer :item_type
|
7
|
+
t.integer :spud_page_id
|
8
|
+
t.integer :menu_order,:default => 0
|
9
|
+
t.string :url
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
|
14
|
+
add_index :spud_menu_items,[:parent_type,:parent_id]
|
15
|
+
add_index :spud_menu_items,[:menu_order]
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateSpudPagePartials < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :spud_page_partials do |t|
|
4
|
+
t.integer :spud_page_id
|
5
|
+
t.string :name
|
6
|
+
t.text :content
|
7
|
+
t.string :format
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
add_index :spud_page_partials,:spud_page_id
|
12
|
+
end
|
13
|
+
end
|
data/lib/spud_cms/engine.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
require 'spud_core'
|
2
|
+
require 'spud_permalinks'
|
2
3
|
require 'codemirror-rails'
|
3
4
|
module Spud
|
4
5
|
module Cms
|
5
6
|
class Engine < Rails::Engine
|
6
7
|
engine_name :spud_cms
|
7
8
|
# config.autoload_paths << File.expand_path("../app/sweepers", __FILE__)
|
8
|
-
|
9
|
+
config.generators do |g|
|
10
|
+
g.test_framework :rspec, :view_specs => false
|
11
|
+
end
|
9
12
|
|
10
13
|
initializer :admin do
|
11
14
|
Spud::Core.configure do |config|
|
@@ -22,6 +25,13 @@ module Spud
|
|
22
25
|
|
23
26
|
end
|
24
27
|
end
|
28
|
+
initializer :spud_cms_routes do |config|
|
29
|
+
config.routes_reloader.paths << File.expand_path('../page_route.rb', __FILE__)
|
30
|
+
end
|
31
|
+
initializer :load_priority, :after => :load_environment_config do |config|
|
32
|
+
puts "Loading Railties Order"
|
33
|
+
# Rails.application.config.railties_order = [:main_app, :all,Spud::Core::Engine,Spud::Cms::Engine]
|
34
|
+
end
|
25
35
|
initializer :assets do |config|
|
26
36
|
Rails.application.config.assets.precompile += ["spud/admin/cms*"]
|
27
37
|
end
|
data/lib/spud_cms.rb
CHANGED