spud_cms 0.3.0 → 0.3.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/README.markdown +1 -1
- data/app/controllers/spud/admin/menu_items_controller.rb +1 -0
- data/app/controllers/spud/admin/pages_controller.rb +1 -1
- data/app/controllers/spud/admin/templates_controller.rb +1 -1
- data/app/controllers/spud/cms/sitemaps_controller.rb +2 -0
- data/app/helpers/spud/cms/application_helper.rb +17 -9
- data/app/models/spud_menu_item.rb +45 -10
- data/app/models/spud_page.rb +33 -25
- data/app/models/spud_template.rb +1 -1
- data/app/views/spud/admin/menu_items/_form.html.erb +2 -2
- data/app/views/spud/admin/pages/_form.html.erb +1 -1
- data/lib/spud_cms.rb +1 -1
- data/lib/spud_cms/test_files.rb +25 -0
- metadata +7 -7
- data/app/models/spud_custom_field.rb +0 -7
data/README.markdown
CHANGED
@@ -9,7 +9,7 @@ Installation/Usage
|
|
9
9
|
|
10
10
|
1. In your Gemfile add the following
|
11
11
|
|
12
|
-
gem '
|
12
|
+
gem 'spud_core', :git => "git://github.com/davydotcom/spud_core_admin.git"
|
13
13
|
gem 'spud_cms', :git => "git://github.com/davydotcom/spud_cms.git"
|
14
14
|
|
15
15
|
2. Run bundle install
|
@@ -139,7 +139,7 @@ class Spud::Admin::PagesController < Spud::Admin::ApplicationController
|
|
139
139
|
|
140
140
|
private
|
141
141
|
def load_page
|
142
|
-
@page = SpudPage.where(:id => params[:id]).includes(:
|
142
|
+
@page = SpudPage.where(:id => params[:id]).includes(:spud_page_partials).first
|
143
143
|
if @page.blank?
|
144
144
|
flash[:error] = "Page not found!"
|
145
145
|
redirect_to spud_admin_pages_url() and return false
|
@@ -13,7 +13,7 @@ class Spud::Admin::TemplatesController < Spud::Admin::ApplicationController
|
|
13
13
|
|
14
14
|
def new
|
15
15
|
add_breadcrumb "New", :new_spud_admin_template_path
|
16
|
-
@template = SpudTemplate.new(:base_layout =>
|
16
|
+
@template = SpudTemplate.new(:base_layout => Spud::Cms.default_page_layout,:page_parts => Spud::Cms.default_page_parts.join(","))
|
17
17
|
respond_with @template
|
18
18
|
end
|
19
19
|
|
@@ -1,23 +1,31 @@
|
|
1
1
|
module Spud::Cms::ApplicationHelper
|
2
2
|
def sp_list_pages(options = {})
|
3
|
-
pages = SpudPage.
|
3
|
+
pages = SpudPage.public.published_pages
|
4
|
+
start_page = nil
|
4
5
|
if !options.blank?
|
5
6
|
if options.has_key?(:exclude)
|
6
7
|
|
7
8
|
pages = pages.where(["name NOT IN (?)",options[:exclude]])
|
8
9
|
end
|
10
|
+
if options.has_key?(:start_page_id)
|
11
|
+
start_page = options[:start_page_id]
|
12
|
+
end
|
9
13
|
if options.has_key?(:id)
|
10
|
-
content = "<ul id='#{options
|
14
|
+
content = "<ul id='#{options[:id]}'>"
|
11
15
|
else
|
12
16
|
content = "<ul>"
|
13
17
|
end
|
14
18
|
else
|
15
19
|
content = "<ul>"
|
16
20
|
end
|
17
|
-
|
18
|
-
pages.
|
21
|
+
|
22
|
+
pages = pages.all.group_by(&:spud_page_id)
|
23
|
+
if pages[start_page].blank?
|
24
|
+
return ""
|
25
|
+
end
|
26
|
+
pages[start_page].sort_by{|p| p.page_order}.each do |page|
|
19
27
|
content += "<li><a href='#{page_path(:id => page.url_name)}'>#{page.name}</a>"
|
20
|
-
content += sp_list_page(page)
|
28
|
+
content += sp_list_page(page,pages)
|
21
29
|
content += "</li>"
|
22
30
|
end
|
23
31
|
content += "</ul>"
|
@@ -86,14 +94,14 @@ private
|
|
86
94
|
content += "</ul>"
|
87
95
|
return content.html_safe
|
88
96
|
end
|
89
|
-
def sp_list_page(page)
|
90
|
-
if page.
|
97
|
+
def sp_list_page(page,collection)
|
98
|
+
if collection[page.id].blank?
|
91
99
|
return ""
|
92
100
|
end
|
93
101
|
content = "<ul>"
|
94
|
-
page.
|
102
|
+
collection[page.id].sort_by{|p| p.page_order}.each do |page|
|
95
103
|
content += "<li><a href='#{page_path(:id => page.url_name)}'>#{page.name}</a>"
|
96
|
-
content += sp_list_page(page)
|
104
|
+
content += sp_list_page(page,collection)
|
97
105
|
content += "</li>"
|
98
106
|
end
|
99
107
|
content += "</ul>"
|
@@ -21,17 +21,52 @@ class SpudMenuItem < ActiveRecord::Base
|
|
21
21
|
end
|
22
22
|
return options
|
23
23
|
end
|
24
|
+
def self.grouped(menu)
|
25
|
+
return menu.spud_menu_items_combined.group_by(&:parent_type)
|
26
|
+
end
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
# Returns an array of pages in order of heirarchy
|
29
|
+
# :fitler Filters out a page by ID, and all of its children
|
30
|
+
# :value Pick an attribute to be used in the value field, defaults to ID
|
31
|
+
def self.options_tree_for_item(menu,config={})
|
32
|
+
collection = config[:collection] || self.grouped(menu)
|
33
|
+
level = config[:level] || 0
|
34
|
+
parent_id = config[:parent_id] || nil
|
35
|
+
parent_type = config[:parent_type] || 'SpudMenu'
|
36
|
+
filter = config[:filter] || nil
|
37
|
+
value = config[:value] || :id
|
38
|
+
list = []
|
39
|
+
if parent_type == 'SpudMenu' && collection[parent_type]
|
40
|
+
item_collection = collection['SpudMenuItem'].group_by(&:parent_id) if collection['SpudMenuItem']
|
41
|
+
collection[parent_type].each do |c|
|
42
|
+
if filter.blank? || c.id != filter.id
|
43
|
+
list << [level.times.collect{ '- ' }.join('') + c.name, c[value]]
|
44
|
+
list += self.options_tree_for_item(menu,{:collection => item_collection, :parent_id => c.id, :level => level+1, :filter => filter,:parent_type => "SpudMenuItem"})
|
45
|
+
end
|
46
|
+
end
|
47
|
+
else
|
48
|
+
if collection[parent_id]
|
49
|
+
collection[parent_id].each do |c|
|
50
|
+
if filter.blank? || c.id != filter.id
|
51
|
+
list << [level.times.collect{ '- ' }.join('') + c.name, c[value]]
|
52
|
+
list += self.options_tree_for_item(menu,{:collection => collection, :parent_id => c.id, :level => level+1, :filter => filter,:parent_type => "SpudMenuItem"})
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
34
56
|
end
|
35
|
-
|
57
|
+
|
58
|
+
return list
|
36
59
|
end
|
60
|
+
# def self.options_tree_for_item(item,menu)
|
61
|
+
# items = menu.spud_menu_items
|
62
|
+
# items = items.where(["id != ?",item.id]) if !item.blank? && !item.id.blank?
|
63
|
+
|
64
|
+
|
65
|
+
# options = []
|
66
|
+
# items.each do |item|
|
67
|
+
# options << ["#{item.name}",item.id]
|
68
|
+
# options = item.options_tree(options,1,item)
|
69
|
+
# end
|
70
|
+
# return options
|
71
|
+
# end
|
37
72
|
end
|
data/app/models/spud_page.rb
CHANGED
@@ -3,7 +3,6 @@ class SpudPage < ActiveRecord::Base
|
|
3
3
|
belongs_to :spud_template,:foreign_key => :template_id
|
4
4
|
has_many :spud_pages, :dependent => :nullify
|
5
5
|
has_many :spud_page_partials,:dependent => :destroy
|
6
|
-
has_many :spud_custom_fields,:as => :parent,:dependent => :destroy
|
7
6
|
belongs_to :created_by_user,:class_name => "SpudUser",:foreign_key => :created_by
|
8
7
|
belongs_to :updated_by_user,:class_name => "SpudUser",:foreign_key => :updated_by
|
9
8
|
|
@@ -11,43 +10,52 @@ class SpudPage < ActiveRecord::Base
|
|
11
10
|
validates :name,:presence => true
|
12
11
|
validates :url_name,:presence => true, :uniqueness => true
|
13
12
|
|
14
|
-
accepts_nested_attributes_for :spud_custom_fields
|
15
13
|
accepts_nested_attributes_for :spud_page_partials, :allow_destroy => true
|
16
14
|
scope :parent_pages, where(:spud_page_id => nil)
|
17
15
|
scope :published_pages, where(:published => true)
|
18
16
|
scope :public, where(:visibility => 0)
|
19
17
|
|
20
|
-
def options_tree(options,depth,current_page = nil)
|
21
|
-
sub_pages = self.spud_pages
|
22
|
-
sub_pages = sub_pages.where(["id != ?",current_page.id]) if !current_page.blank? && !current_page.id.blank?
|
23
|
-
if(sub_pages.blank?)
|
24
|
-
return options
|
25
|
-
end
|
26
|
-
sub_pages.each do |page|
|
27
|
-
options << ["#{'-'*depth} #{page.name}",page.id]
|
28
|
-
options = page.options_tree(options,depth+1,current_page)
|
29
|
-
end
|
30
|
-
return options
|
31
|
-
end
|
32
18
|
|
33
|
-
def self.
|
34
|
-
|
35
|
-
|
36
|
-
|
19
|
+
def self.grouped
|
20
|
+
return all.group_by(&:spud_page_id)
|
21
|
+
end
|
37
22
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
23
|
+
# Returns an array of pages in order of heirarchy
|
24
|
+
# :fitler Filters out a page by ID, and all of its children
|
25
|
+
# :value Pick an attribute to be used in the value field, defaults to ID
|
26
|
+
def self.options_tree_for_page(config={})
|
27
|
+
collection = config[:collection] || self.grouped
|
28
|
+
level = config[:level] || 0
|
29
|
+
parent_id = config[:parent_id] || nil
|
30
|
+
filter = config[:filter] || nil
|
31
|
+
value = config[:value] || :id
|
32
|
+
list = []
|
33
|
+
if collection[parent_id]
|
34
|
+
collection[parent_id].each do |c|
|
35
|
+
if filter.blank? || c.id != filter.id
|
36
|
+
list << [level.times.collect{ '- ' }.join('') + c.name, c[value]]
|
37
|
+
list += self.options_tree_for_page({:collection => collection, :parent_id => c.id, :level => level+1, :filter => filter})
|
38
|
+
end
|
39
|
+
end
|
42
40
|
end
|
43
|
-
return
|
41
|
+
return list
|
44
42
|
end
|
45
43
|
|
46
44
|
|
47
|
-
|
48
45
|
def generate_url_name
|
46
|
+
return false if self.name.blank?
|
49
47
|
if !self.use_custom_url_name || self.url_name.blank?
|
50
|
-
|
48
|
+
|
49
|
+
url_name = self.name.parameterize.downcase
|
50
|
+
if !self.use_custom_url_name
|
51
|
+
url_names = SpudPage.where("id != #{self.id}").all.collect{|p| p.url_name}
|
52
|
+
counter = 1
|
53
|
+
while url_names.include?(url_name) do
|
54
|
+
url_name = self.name.parameterize.downcase + "-#{counter}"
|
55
|
+
counter += 1
|
56
|
+
end
|
57
|
+
end
|
58
|
+
self.url_name = url_name
|
51
59
|
self.use_custom_url_name = false
|
52
60
|
end
|
53
61
|
return true
|
data/app/models/spud_template.rb
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
<%=error_message_on "menu_item","menu_order"%>
|
10
10
|
</li>
|
11
11
|
<li><%=f.label :spud_page_id, "Page"%>
|
12
|
-
<%=f.select :spud_page_id,options_for_select(SpudPage.options_tree_for_page(
|
12
|
+
<%=f.select :spud_page_id,options_for_select(SpudPage.options_tree_for_page(),@menu_item.spud_page_id),{:include_blank => 'Use URL instead'},{:title => "",:onchange => "if($(this).val() != '') {$('#spud_menu_item_url').val('');}"}%>
|
13
13
|
<%=error_message_on "menu_item","spud_page_id"%>
|
14
14
|
</li>
|
15
15
|
|
@@ -24,7 +24,7 @@
|
|
24
24
|
<%=error_message_on "menu_item","classes"%>
|
25
25
|
</li>
|
26
26
|
<li><%=f.label :parent, "Parent Menu"%>
|
27
|
-
<%=f.select :parent_id,options_for_select(SpudMenuItem.options_tree_for_item(@menu_item
|
27
|
+
<%=f.select :parent_id,options_for_select(SpudMenuItem.options_tree_for_item(@menu,:filter => @menu_item),@menu_item.parent_type == 'SpudMenuItem' ? @menu_item.parent_id : nil),{:include_blank => "#{@menu.name}"},{:title => ""}%>
|
28
28
|
<%=error_message_on "menu_item","parent"%>
|
29
29
|
</li>
|
30
30
|
</ol>
|
@@ -30,7 +30,7 @@
|
|
30
30
|
<li>
|
31
31
|
<%=error_message_on "page","spud_page_id"%>
|
32
32
|
<%=f.label :spud_page_id, "Parent Page"%>
|
33
|
-
<%=f.select :spud_page_id,options_for_select(SpudPage.options_tree_for_page(@page),@page.spud_page_id),{:include_blank => 'None'},{:title => ""}%>
|
33
|
+
<%=f.select :spud_page_id,options_for_select(SpudPage.options_tree_for_page(:filter => @page),@page.spud_page_id),{:include_blank => 'None'},{:title => ""}%>
|
34
34
|
</li>
|
35
35
|
<li>
|
36
36
|
<%=error_message_on "page","url_name"%>
|
data/lib/spud_cms.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Spud
|
2
|
+
module Cms
|
3
|
+
module TestFiles
|
4
|
+
class << self
|
5
|
+
def load_all
|
6
|
+
load_specs
|
7
|
+
load_factories
|
8
|
+
load_support
|
9
|
+
end
|
10
|
+
|
11
|
+
def load_specs
|
12
|
+
Dir[File.join(File.expand_path('../../../', __FILE__), "spec/**/*_spec.rb")].each {|f| require f}
|
13
|
+
end
|
14
|
+
|
15
|
+
def load_factories
|
16
|
+
Dir[File.join(File.expand_path('../../../', __FILE__), "factories/*")].each {|f| require f}
|
17
|
+
end
|
18
|
+
|
19
|
+
def load_support
|
20
|
+
Dir[File.join(File.expand_path('../../../', __FILE__), "spec/support/**/*.rb")].each {|f| require f}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spud_cms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01
|
12
|
+
date: 2012-02-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: spud_core
|
16
|
-
requirement: &
|
16
|
+
requirement: &70366827584580 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.3.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70366827584580
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: codemirror-rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &70366831691500 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70366831691500
|
36
36
|
description:
|
37
37
|
email: destes@redwindsw.com
|
38
38
|
executables: []
|
@@ -69,7 +69,6 @@ files:
|
|
69
69
|
- app/helpers/spud/cms/application_helper.rb
|
70
70
|
- app/helpers/spud/cms/sitemaps_helper.rb
|
71
71
|
- app/helpers/spud/user_sessions_helper.rb
|
72
|
-
- app/models/spud_custom_field.rb
|
73
72
|
- app/models/spud_menu.rb
|
74
73
|
- app/models/spud_menu_item.rb
|
75
74
|
- app/models/spud_page.rb
|
@@ -105,6 +104,7 @@ files:
|
|
105
104
|
- lib/spud_cms.rb
|
106
105
|
- lib/spud_cms/configuration.rb
|
107
106
|
- lib/spud_cms/engine.rb
|
107
|
+
- lib/spud_cms/test_files.rb
|
108
108
|
- README.markdown
|
109
109
|
homepage:
|
110
110
|
licenses: []
|