spud_cms 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
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 'spud_admin', :git => "git://github.com/davydotcom/spud_core_admin.git"
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
@@ -17,6 +17,7 @@ class Spud::Admin::MenuItemsController < Spud::Admin::ApplicationController
17
17
  @page_name = "New Menu Item"
18
18
 
19
19
  @menu_item = @menu.spud_menu_items.new
20
+
20
21
  end
21
22
 
22
23
  def create
@@ -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(:spud_custom_fields,:spud_page_partials).first
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 => "application",:page_parts => "Body")
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,6 +1,8 @@
1
1
  class Spud::Cms::SitemapsController < Spud::ApplicationController
2
+ respond_to :xml
2
3
  caches_page :show,:expires_in => 1.day
3
4
  def show
4
5
  @pages = SpudPage.published_pages.public.order(:spud_page_id)
6
+ respond_with @pages
5
7
  end
6
8
  end
@@ -1,23 +1,31 @@
1
1
  module Spud::Cms::ApplicationHelper
2
2
  def sp_list_pages(options = {})
3
- pages = SpudPage.parent_pages
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.id}'>"
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.order(:page_order).each do |page|
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.spud_pages.count == 0
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.spud_pages.order(:page_order).each do |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
- def self.options_tree_for_item(item,menu)
26
- items = menu.spud_menu_items
27
- items = items.where(["id != ?",item.id]) if !item.blank? && !item.id.blank?
28
-
29
-
30
- options = []
31
- items.each do |item|
32
- options << ["#{item.name}",item.id]
33
- options = item.options_tree(options,1,item)
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
- return options
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
@@ -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.options_tree_for_page(page)
34
- pages = SpudPage.parent_pages
35
- pages = pages.where(["id != ?",page.id]) if !page.blank? && !page.id.blank?
36
-
19
+ def self.grouped
20
+ return all.group_by(&:spud_page_id)
21
+ end
37
22
 
38
- options = []
39
- pages.each do |sub_page|
40
- options << ["#{sub_page.name}",sub_page.id]
41
- options = sub_page.options_tree(options,1,page)
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 options
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
- self.url_name = self.name.gsub(/[^a-zA-Z0-9\ ]/," ").gsub(/\ \ +/," ").gsub(/\ /,"-").downcase
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
@@ -1,5 +1,5 @@
1
1
  class SpudTemplate < ActiveRecord::Base
2
- has_many :spud_pages,:dependent => :nullify
2
+ has_many :spud_pages,:dependent => :nullify,:foreign_key => :template_id
3
3
 
4
4
  validates :base_layout, :presence => true
5
5
  validates :page_parts, :presence => true
@@ -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(nil),@menu_item.spud_page_id),{:include_blank => 'Use URL instead'},{:title => "",:onchange => "if($(this).val() != '') {$('#spud_menu_item_url').val('');}"}%>
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,@menu),@menu_item.parent_id),{:include_blank => "#{@menu.name}"},{:title => ""}%>
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
@@ -2,6 +2,6 @@ module Spud
2
2
  module Cms
3
3
  require 'spud_cms/configuration'
4
4
  require 'spud_cms/engine' if defined?(Rails)
5
-
5
+ require 'spud_cms/test_files' if ENV["RAILS_ENV"] == 'test'
6
6
  end
7
7
  end
@@ -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.0
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-30 00:00:00.000000000 Z
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: &70222010796980 !ruby/object:Gem::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: *70222010796980
24
+ version_requirements: *70366827584580
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: codemirror-rails
27
- requirement: &70222010782760 !ruby/object:Gem::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: *70222010782760
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: []
@@ -1,7 +0,0 @@
1
- class SpudCustomField < ActiveRecord::Base
2
- belongs_to :parent,:polymorphic => true
3
- validates :name,:presence => true
4
- validates :value,:presence => true
5
- validates :parent_type,:presence => true
6
- validates :parent_id,:presence => true
7
- end