spud_cms 0.3.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.
Files changed (67) hide show
  1. data/README.markdown +71 -0
  2. data/app/assets/images/spud/admin/menus_thumb.png +0 -0
  3. data/app/assets/images/spud/admin/pages_thumb.png +0 -0
  4. data/app/assets/images/spud/admin/posts_thumb.png +0 -0
  5. data/app/assets/images/spud/admin/templates_thumb.png +0 -0
  6. data/app/assets/javascripts/pages.js +2 -0
  7. data/app/assets/javascripts/spud/admin/cms/application.js +24 -0
  8. data/app/assets/javascripts/spud/admin/templates.js +2 -0
  9. data/app/assets/javascripts/spud/cms/sitemaps.js +2 -0
  10. data/app/assets/stylesheets/pages.css +4 -0
  11. data/app/assets/stylesheets/spud/admin/cms/application.css +4 -0
  12. data/app/assets/stylesheets/spud/cms/sitemaps.css +4 -0
  13. data/app/controllers/pages_controller.rb +29 -0
  14. data/app/controllers/spud/admin/menu_items_controller.rb +118 -0
  15. data/app/controllers/spud/admin/menus_controller.rb +50 -0
  16. data/app/controllers/spud/admin/pages_controller.rb +149 -0
  17. data/app/controllers/spud/admin/templates_controller.rb +55 -0
  18. data/app/controllers/spud/cms/sitemaps_controller.rb +6 -0
  19. data/app/helpers/pages_helper.rb +2 -0
  20. data/app/helpers/spud/admin/contacts_helper.rb +2 -0
  21. data/app/helpers/spud/admin/media_helper.rb +2 -0
  22. data/app/helpers/spud/admin/menu_items_helper.rb +2 -0
  23. data/app/helpers/spud/admin/menus_helper.rb +2 -0
  24. data/app/helpers/spud/admin/pages_helper.rb +2 -0
  25. data/app/helpers/spud/admin/posts_helper.rb +2 -0
  26. data/app/helpers/spud/admin/templates_helper.rb +2 -0
  27. data/app/helpers/spud/admin/users_helper.rb +2 -0
  28. data/app/helpers/spud/cms/application_helper.rb +102 -0
  29. data/app/helpers/spud/cms/sitemaps_helper.rb +2 -0
  30. data/app/helpers/spud/user_sessions_helper.rb +2 -0
  31. data/app/models/spud_custom_field.rb +7 -0
  32. data/app/models/spud_menu.rb +6 -0
  33. data/app/models/spud_menu_item.rb +37 -0
  34. data/app/models/spud_page.rb +59 -0
  35. data/app/models/spud_page_partial.rb +3 -0
  36. data/app/models/spud_template.rb +7 -0
  37. data/app/views/layouts/spud/admin/cms/detail.html.erb +6 -0
  38. data/app/views/pages/show.html.erb +25 -0
  39. data/app/views/spud/admin/contacts/index.html.erb +0 -0
  40. data/app/views/spud/admin/menu_items/_form.html.erb +34 -0
  41. data/app/views/spud/admin/menu_items/_menu_item_row.html.erb +18 -0
  42. data/app/views/spud/admin/menu_items/edit.html.erb +13 -0
  43. data/app/views/spud/admin/menu_items/index.html.erb +12 -0
  44. data/app/views/spud/admin/menu_items/new.html.erb +13 -0
  45. data/app/views/spud/admin/menus/_form.html.erb +9 -0
  46. data/app/views/spud/admin/menus/edit.html.erb +13 -0
  47. data/app/views/spud/admin/menus/index.html.erb +24 -0
  48. data/app/views/spud/admin/menus/new.html.erb +13 -0
  49. data/app/views/spud/admin/pages/_form.html.erb +71 -0
  50. data/app/views/spud/admin/pages/_page_partials_form.html.erb +18 -0
  51. data/app/views/spud/admin/pages/_page_row.html.erb +18 -0
  52. data/app/views/spud/admin/pages/edit.html.erb +13 -0
  53. data/app/views/spud/admin/pages/index.html.erb +12 -0
  54. data/app/views/spud/admin/pages/new.html.erb +12 -0
  55. data/app/views/spud/admin/pages/show.html.erb +25 -0
  56. data/app/views/spud/admin/templates/_form.html.erb +31 -0
  57. data/app/views/spud/admin/templates/edit.html.erb +11 -0
  58. data/app/views/spud/admin/templates/index.html.erb +17 -0
  59. data/app/views/spud/admin/templates/new.html.erb +13 -0
  60. data/app/views/spud/cms/sitemaps/show.xml.builder +16 -0
  61. data/config/application.rb +48 -0
  62. data/config/boot.rb +6 -0
  63. data/config/routes.rb +22 -0
  64. data/lib/spud_cms.rb +7 -0
  65. data/lib/spud_cms/configuration.rb +15 -0
  66. data/lib/spud_cms/engine.rb +29 -0
  67. metadata +133 -0
@@ -0,0 +1,55 @@
1
+ class Spud::Admin::TemplatesController < Spud::Admin::ApplicationController
2
+ layout 'spud/admin/cms/detail'
3
+ add_breadcrumb "Templates", :spud_admin_templates_path
4
+ belongs_to_spud_app :templates
5
+ before_filter :load_template,:only => [:edit,:update,:show,:destroy]
6
+
7
+
8
+ def index
9
+ flash.now[:warning] = "Templates are an advanced way to create modified pages and require some experience in HTML and Ruby."
10
+ @templates = SpudTemplate.order(:name).paginate :page => params[:page]
11
+ respond_with @templates
12
+ end
13
+
14
+ def new
15
+ add_breadcrumb "New", :new_spud_admin_template_path
16
+ @template = SpudTemplate.new(:base_layout => "application",:page_parts => "Body")
17
+ respond_with @template
18
+ end
19
+
20
+ def create
21
+ add_breadcrumb "New", :new_spud_admin_template_path
22
+
23
+ @template = SpudTemplate.new(params[:spud_template])
24
+
25
+ flash[:notice] = "Template created successfully!" if @template.save
26
+
27
+ respond_with @template, :location => spud_admin_templates_url
28
+ end
29
+
30
+ def edit
31
+ add_breadcrumb "Edit #{@template.name}", :edit_spud_admin_template_path
32
+ respond_with @template
33
+ end
34
+
35
+ def update
36
+ add_breadcrumb "Edit #{@template.name}", :edit_spud_admin_template_path
37
+ flash[:notice] = "Template updated successfully" if @template.update_attributes(params[:spud_template])
38
+ respond_with @template, :location => spud_admin_templates_url
39
+ end
40
+
41
+
42
+ def destroy
43
+ flash[:notice] = "Template removed" if @template.destroy
44
+ respond_with @template, :location => spud_admin_templates_url
45
+ end
46
+
47
+ private
48
+ def load_template
49
+ @template = SpudTemplate.where(:id => params[:id]).first
50
+ if @template.blank?
51
+ flash[:error] = "Template not found!"
52
+ redirect_to spud_admin_templates_url and return false
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,6 @@
1
+ class Spud::Cms::SitemapsController < Spud::ApplicationController
2
+ caches_page :show,:expires_in => 1.day
3
+ def show
4
+ @pages = SpudPage.published_pages.public.order(:spud_page_id)
5
+ end
6
+ end
@@ -0,0 +1,2 @@
1
+ module PagesHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module Spud::Admin::ContactsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module Spud::Admin::MediaHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module Spud::Admin::MenuItemsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module Spud::Admin::MenusHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module Spud::Admin::PagesHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module Spud::Admin::PostsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module Spud::Admin::TemplatesHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module Spud::Admin::UsersHelper
2
+ end
@@ -0,0 +1,102 @@
1
+ module Spud::Cms::ApplicationHelper
2
+ def sp_list_pages(options = {})
3
+ pages = SpudPage.parent_pages
4
+ if !options.blank?
5
+ if options.has_key?(:exclude)
6
+
7
+ pages = pages.where(["name NOT IN (?)",options[:exclude]])
8
+ end
9
+ if options.has_key?(:id)
10
+ content = "<ul id='#{options.id}'>"
11
+ else
12
+ content = "<ul>"
13
+ end
14
+ else
15
+ content = "<ul>"
16
+ end
17
+
18
+ pages.order(:page_order).each do |page|
19
+ content += "<li><a href='#{page_path(:id => page.url_name)}'>#{page.name}</a>"
20
+ content += sp_list_page(page)
21
+ content += "</li>"
22
+ end
23
+ content += "</ul>"
24
+ return content.html_safe
25
+ end
26
+
27
+
28
+ def sp_list_menu(options = {})
29
+
30
+ menu = SpudMenu
31
+ if !options.blank?
32
+ if options.has_key?(:menu_id)
33
+ menu = menu.where(:id => options[:menu_id])
34
+ end
35
+ if options.has_key?(:name)
36
+ menu = menu.where(:name => options[:name])
37
+ end
38
+ if options.has_key?(:id)
39
+ content = "<ul id='#{options[:id]}'>"
40
+ else
41
+ content = "<ul>"
42
+ end
43
+ else
44
+ content = "<ul>"
45
+ end
46
+ menu = menu.first
47
+ if menu.blank?
48
+ return ""
49
+ end
50
+ menu_items = menu.spud_menu_items_combined.select("spud_menu_items.id as id,spud_menu_items.url as url,spud_menu_items.classes as classes,spud_menu_items.parent_type as parent_type,spud_menu_items.menu_order as menu_order,spud_menu_items.parent_id as parent_id,spud_menu_items.name as name,spud_pages.url_name as url_name").order(:parent_type,:parent_id).joins("LEFT JOIN spud_pages ON (spud_pages.id = spud_menu_items.spud_page_id)").all
51
+
52
+ grouped_items = menu_items.group_by(&:parent_type)
53
+ if grouped_items["SpudMenu"].blank?
54
+ return ""
55
+ end
56
+ child_items = grouped_items["SpudMenuItem"].blank? ? [] : grouped_items["SpudMenuItem"].group_by(&:parent_id)
57
+
58
+
59
+ grouped_items["SpudMenu"].sort_by{|p| p.menu_order}.each do |item|
60
+ content += "<li><a #{"class='#{item.classes}' " if !item.classes.blank?}href='#{!item.url_name.blank? ? page_path(:id => item.url_name) : item.url}'>#{item.name}</a>"
61
+ content += sp_list_menu_item(child_items,item.id)
62
+ content += "</li>"
63
+ end
64
+ # menu.spud_menu_items.order(:menu_order).each do |item|
65
+ # content += "<li><a href='#{item.spud_page_id ? page_path(:id => item.spud_page.url_name) : item.url}'>#{item.name}</a>"
66
+ # content += sp_list_menu_item(item)
67
+ # content += "</li>"
68
+ # end
69
+ content += "</ul>"
70
+ return content.html_safe
71
+ end
72
+ private
73
+ def sp_list_menu_item(items,item_id)
74
+
75
+ spud_menu_items = items[item_id]
76
+ if spud_menu_items == nil
77
+ return ""
78
+ end
79
+ content = "<ul>"
80
+
81
+ spud_menu_items.sort_by{|p| p.menu_order}.each do |item|
82
+ content += "<li><a #{"class='#{item.classes}' " if !item.classes.blank?}href='#{!item.url_name.blank? ? page_path(:id => item.url_name) : item.url}'>#{item.name}</a>"
83
+ content += sp_list_menu_item(items,item.id)
84
+ content += "</li>"
85
+ end
86
+ content += "</ul>"
87
+ return content.html_safe
88
+ end
89
+ def sp_list_page(page)
90
+ if page.spud_pages.count == 0
91
+ return ""
92
+ end
93
+ content = "<ul>"
94
+ page.spud_pages.order(:page_order).each do |page|
95
+ content += "<li><a href='#{page_path(:id => page.url_name)}'>#{page.name}</a>"
96
+ content += sp_list_page(page)
97
+ content += "</li>"
98
+ end
99
+ content += "</ul>"
100
+ return content.html_safe
101
+ end
102
+ end
@@ -0,0 +1,2 @@
1
+ module Spud::Cms::SitemapsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module Spud::UserSessionsHelper
2
+ end
@@ -0,0 +1,7 @@
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
@@ -0,0 +1,6 @@
1
+ class SpudMenu < ActiveRecord::Base
2
+ validates :name,:presence => true
3
+ has_many :spud_menu_items,:as => :parent,:dependent => :destroy
4
+ has_many :spud_menu_items_combined,:class_name => "SpudMenuItem",:foreign_key => :spud_menu_id,:dependent => :destroy
5
+
6
+ end
@@ -0,0 +1,37 @@
1
+ class SpudMenuItem < ActiveRecord::Base
2
+ belongs_to :parent, :polymorphic=>true
3
+ belongs_to :spud_menu
4
+ belongs_to :spud_page
5
+ has_many :spud_menu_items,:as => :parent,:dependent => :destroy
6
+
7
+ validates :name,:presence => true
8
+ validates :parent_type,:presence => true
9
+ validates :parent_id,:presence => true
10
+
11
+
12
+ def options_tree(options,depth,current = nil)
13
+ sub_items = self.spud_menu_items
14
+ sub_items = sub_items.where(["id != ?",current.id]) if !current.blank? && !current.id.blank?
15
+ if(sub_items.blank?)
16
+ return options
17
+ end
18
+ sub_items.each do |item|
19
+ options << ["#{'-'*depth} #{item.name}",item.id]
20
+ options = item.options_tree(options,depth+1,current)
21
+ end
22
+ return options
23
+ end
24
+
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)
34
+ end
35
+ return options
36
+ end
37
+ end
@@ -0,0 +1,59 @@
1
+ class SpudPage < ActiveRecord::Base
2
+ belongs_to :spud_page
3
+ belongs_to :spud_template,:foreign_key => :template_id
4
+ has_many :spud_pages, :dependent => :nullify
5
+ has_many :spud_page_partials,:dependent => :destroy
6
+ has_many :spud_custom_fields,:as => :parent,:dependent => :destroy
7
+ belongs_to :created_by_user,:class_name => "SpudUser",:foreign_key => :created_by
8
+ belongs_to :updated_by_user,:class_name => "SpudUser",:foreign_key => :updated_by
9
+
10
+ before_validation :generate_url_name
11
+ validates :name,:presence => true
12
+ validates :url_name,:presence => true, :uniqueness => true
13
+
14
+ accepts_nested_attributes_for :spud_custom_fields
15
+ accepts_nested_attributes_for :spud_page_partials, :allow_destroy => true
16
+ scope :parent_pages, where(:spud_page_id => nil)
17
+ scope :published_pages, where(:published => true)
18
+ scope :public, where(:visibility => 0)
19
+
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
+
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
+
37
+
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)
42
+ end
43
+ return options
44
+ end
45
+
46
+
47
+
48
+ def generate_url_name
49
+ if !self.use_custom_url_name || self.url_name.blank?
50
+ self.url_name = self.name.gsub(/[^a-zA-Z0-9\ ]/," ").gsub(/\ \ +/," ").gsub(/\ /,"-").downcase
51
+ self.use_custom_url_name = false
52
+ end
53
+ return true
54
+ end
55
+
56
+ def is_private?
57
+ return self.visibility == 1
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ class SpudPagePartial < ActiveRecord::Base
2
+ belongs_to :spud_page
3
+ end
@@ -0,0 +1,7 @@
1
+ class SpudTemplate < ActiveRecord::Base
2
+ has_many :spud_pages,:dependent => :nullify
3
+
4
+ validates :base_layout, :presence => true
5
+ validates :page_parts, :presence => true
6
+ validates :name, :presence => true,:uniqueness => true
7
+ end
@@ -0,0 +1,6 @@
1
+ <%=content_for :head do%>
2
+ <%= javascript_include_tag "wymeditor/jquery.wymeditor.min" %>
3
+ <%= stylesheet_link_tag "spud/admin/cms/application" %>
4
+ <%= javascript_include_tag "spud/admin/cms/application" %>
5
+ <%end%>
6
+ <%= render :template => 'layouts/spud/admin/detail' %>
@@ -0,0 +1,25 @@
1
+
2
+ <%=content_for :head do%>
3
+ <%if !@page.meta_description.blank?%>
4
+ <meta name="description" content="<%=@page.meta_description%>" />
5
+ <%end%>
6
+ <%if !@page.meta_keywords.blank?%>
7
+ <meta name="keywords" content="<%=@page.meta_keywords%>" />
8
+ <%end%>
9
+ <%end%>
10
+
11
+ <%if !@inline.blank?%>
12
+ <%=render :inline => @inline%>
13
+ <%else%>
14
+ <h2><%=@page.name%></h2>
15
+ <%end%>
16
+ <%@page.spud_page_partials.each do |page_partial|%>
17
+
18
+ <%if(page_partial.name.downcase == 'body' && Spud::Cms.yield_body_as_content_block == false)%>
19
+ <%=page_partial.content.html_safe%>
20
+ <%else%>
21
+ <%=content_for page_partial.name.parameterize.underscore.to_sym do%>
22
+ <%=page_partial.content.html_safe%>
23
+ <%end%>
24
+ <%end%>
25
+ <%end%>
File without changes
@@ -0,0 +1,34 @@
1
+ <fieldset>
2
+ <ol>
3
+ <li><%=f.label :name, :required=>true%>
4
+ <%=f.text_field :name,:title => "",:size=>40%>
5
+ <%=error_message_on "menu_item","name"%>
6
+ </li>
7
+ <li><%=f.label :menu_order, :required=>true%>
8
+ <%=f.text_field :menu_order,:title => "",:size=>5%>
9
+ <%=error_message_on "menu_item","menu_order"%>
10
+ </li>
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('');}"}%>
13
+ <%=error_message_on "menu_item","spud_page_id"%>
14
+ </li>
15
+
16
+
17
+
18
+ <li><%=f.label :url%>
19
+ <%=f.text_field :url,:title => "",:size=>40%>
20
+ <%=error_message_on "menu_item","url"%>
21
+ </li>
22
+ <li><%=f.label :classes%>
23
+ <%=f.text_field :classes,:title => "",:size=>40%>
24
+ <%=error_message_on "menu_item","classes"%>
25
+ </li>
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 => ""}%>
28
+ <%=error_message_on "menu_item","parent"%>
29
+ </li>
30
+ </ol>
31
+ </fieldset>
32
+
33
+
34
+
@@ -0,0 +1,18 @@
1
+ <div class="page_row">
2
+
3
+ <span class="row_meta"><%=prefix if defined? prefix%><%=link_to menu_item.name,edit_spud_admin_menu_menu_item_path(:id => menu_item.id)%></span>
4
+
5
+ <span class="edit_controls"><%=link_to "Edit",edit_spud_admin_menu_menu_item_path(:id => menu_item.id), :title => "Edit Menu Item",:class => 'button'%>&nbsp;&nbsp;<%=link_to "Remove",spud_admin_menu_menu_item_path(:id => menu_item.id),:method => :delete,:class => 'button',:confirm => "Are you sure you want to remove this menu item?"%></span>
6
+ <br style="clear:both;"/>
7
+ </div>
8
+ <%if !menu_item.spud_menu_items.all.blank?%>
9
+
10
+ <div class="left_guide">
11
+
12
+ <%menu_item.spud_menu_items.order(:menu_order).each do |menu_item|%>
13
+ <%=render :partial => 'menu_item_row',:locals => {:menu_item => menu_item}%>
14
+ <%end%>
15
+
16
+ </div>
17
+
18
+ <%end%>
@@ -0,0 +1,13 @@
1
+
2
+
3
+
4
+ <%=form_for @menu_item,:url => spud_admin_menu_menu_item_path(:id => @menu_item.id),:html=>{:class=>"right_aligned_form"} do |f|%>
5
+ <%=render :partial => "form",:locals => {:f => f}%>
6
+ <fieldset class="submit"><%=f.submit%> or <%=link_to "cancel",request.referer%></fieldset>
7
+ <%end%>
8
+
9
+ <script type="text/javascript">
10
+ $('input[type=submit],.close_dialog').button();
11
+
12
+ </script>
13
+