spud_cms 0.9.21 → 1.0.0.RC1

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 (41) hide show
  1. checksums.yaml +6 -14
  2. data/app/assets/javascripts/spud/admin/cms/menu_items.js +31 -3
  3. data/app/assets/stylesheets/spud/admin/cms/application.css +4 -0
  4. data/app/controllers/pages_controller.rb +5 -8
  5. data/app/controllers/spud/admin/menu_items_controller.rb +28 -6
  6. data/app/controllers/spud/admin/menus_controller.rb +6 -2
  7. data/app/controllers/spud/admin/pages_controller.rb +13 -6
  8. data/app/controllers/spud/admin/snippets_controller.rb +7 -3
  9. data/app/controllers/spud/cms/sitemaps_controller.rb +0 -2
  10. data/app/helpers/spud/cms/application_helper.rb +6 -4
  11. data/app/models/concerns/spud/liquid_taggable.rb +8 -0
  12. data/app/models/spud_menu.rb +4 -4
  13. data/app/models/spud_menu_item.rb +2 -5
  14. data/app/models/spud_page.rb +9 -12
  15. data/app/models/spud_page_liquid_tag.rb +1 -2
  16. data/app/models/spud_page_partial.rb +14 -6
  17. data/app/models/spud_page_partial_revision.rb +1 -4
  18. data/app/models/spud_snippet.rb +22 -4
  19. data/app/observers/page_sweeper.rb +2 -0
  20. data/app/views/pages/show.html.erb +7 -2
  21. data/app/views/spud/admin/menu_items/_form.html.erb +3 -10
  22. data/app/views/spud/admin/menu_items/_menu_item_row.html.erb +2 -2
  23. data/app/views/spud/admin/menu_items/index.html.erb +3 -1
  24. data/app/views/spud/admin/pages/_form.html.erb +8 -1
  25. data/app/views/spud/admin/pages/show.html.erb +13 -11
  26. data/app/views/spud/admin/snippets/_form.html.erb +8 -1
  27. data/config/routes.rb +7 -2
  28. data/lib/spud_cms/engine.rb +11 -8
  29. data/lib/spud_cms/liquid_taggable.rb +28 -0
  30. data/lib/spud_cms/page_route.rb +2 -2
  31. data/lib/spud_cms/version.rb +1 -1
  32. data/spec/controllers/pages_controller_spec.rb +5 -2
  33. data/spec/controllers/spud/cms/sitemaps_controller_spec.rb +3 -2
  34. data/spec/dummy/config/environments/development.rb +2 -4
  35. data/spec/dummy/config/environments/production.rb +1 -1
  36. data/spec/dummy/config/environments/test.rb +2 -4
  37. data/spec/dummy/log/test.log +19992 -4353
  38. data/spec/models/spud_page_partial_spec.rb +3 -3
  39. data/spec/models/spud_page_spec.rb +3 -3
  40. metadata +36 -36
  41. data/spec/dummy/log/development.log +0 -182
@@ -1,4 +1,3 @@
1
1
  class SpudPageLiquidTag < ActiveRecord::Base
2
- attr_accessible :attachment_type,:attachment_id, :tag_name, :value
3
- belongs_to :attachment, :polymorphic => true
2
+ belongs_to :attachment, :polymorphic => true, :touch => true
4
3
  end
@@ -1,8 +1,7 @@
1
1
  class SpudPagePartial < ActiveRecord::Base
2
- belongs_to :spud_page
2
+ belongs_to :spud_page, :touch => true
3
3
  has_many :spud_page_liquid_tags, :as => :attachment, :dependent => :destroy
4
4
  validates :name,:presence => true
5
- attr_accessible :name, :spud_page_id, :content, :format, :content_processed
6
5
  before_save :maintain_revisions
7
6
  before_save :update_symbol_name
8
7
  before_save :postprocess_content
@@ -18,15 +17,22 @@ class SpudPagePartial < ActiveRecord::Base
18
17
  end
19
18
 
20
19
  def postprocess_content
21
- template = Liquid::Template.parse(self.content) # Parses and compiles the template
20
+ rendererClass = Spud::Core.renderer(self.format)
21
+ if rendererClass
22
+ renderer = rendererClass.new()
23
+ self.content_processed = renderer.render self.content
24
+ else
25
+ self.content_processed = content
26
+ end
27
+ # template = Liquid::Template.parse(self.content) # Parses and compiles the template
22
28
 
23
- self.content_processed = template.render('page' => self.spud_page)
29
+ # self.content_processed = template.render('page' => self.spud_page)
24
30
  end
25
31
 
26
32
  def update_taglist
27
33
  template = Liquid::Template.parse(self.content) # Parses and compiles the template
28
34
 
29
- self.spud_page_liquid_tags.all.each do |tag|
35
+ self.spud_page_liquid_tags.each do |tag|
30
36
  tag.destroy
31
37
  end
32
38
  template.root.nodelist.each do |node|
@@ -44,7 +50,9 @@ class SpudPagePartial < ActiveRecord::Base
44
50
  if read_attribute(:content_processed).blank?
45
51
  self.update_column(:content_processed, postprocess_content)
46
52
  end
47
- return read_attribute(:content_processed)
53
+ template = Liquid::Template.parse(read_attribute(:content_processed)) # Parses and compiles the template
54
+
55
+ return template.render('page' => self.spud_page)
48
56
  end
49
57
 
50
58
  def maintain_revisions
@@ -1,8 +1,5 @@
1
1
  class SpudPagePartialRevision < ActiveRecord::Base
2
2
  belongs_to :spud_page
3
-
4
- attr_accessible :name,:content,:format,:spud_page_id
5
-
3
+ # attr_accessible :name,:content,:format,:spud_page_id
6
4
  scope :for_partial, lambda {|partial| where(:spud_page_id => partial.spud_page_id, :name => partial.name)}
7
-
8
5
  end
@@ -1,5 +1,4 @@
1
1
  class SpudSnippet < ActiveRecord::Base
2
- attr_accessible :content, :content_processed, :format, :name
3
2
  has_many :spud_page_liquid_tags, :as => :attachment, :dependent => :destroy
4
3
 
5
4
  validates :name, :presence => true
@@ -9,11 +8,19 @@ class SpudSnippet < ActiveRecord::Base
9
8
 
10
9
  before_save :postprocess_content
11
10
  after_save :update_taglist
11
+ after_destroy :expire_cache
12
+
12
13
  def postprocess_content
13
- template = Liquid::Template.parse(self.content) # Parses and compiles the template
14
- self.content_processed = template.render()
14
+ rendererClass = Spud::Core.renderer(self.format)
15
+ if rendererClass
16
+ renderer = rendererClass.new()
17
+ self.content_processed = renderer.render self.content
18
+ else
19
+ self.content_processed = content
20
+ end
15
21
  end
16
22
 
23
+
17
24
  def content_processed=(content)
18
25
  write_attribute(:content_processed,content)
19
26
  end
@@ -22,7 +29,8 @@ class SpudSnippet < ActiveRecord::Base
22
29
  if read_attribute(:content_processed).blank?
23
30
  self.update_column(:content_processed, postprocess_content)
24
31
  end
25
- return read_attribute(:content_processed)
32
+ template = Liquid::Template.parse(read_attribute(:content_processed)) # Parses and compiles the template
33
+ return template.render()
26
34
  end
27
35
 
28
36
 
@@ -37,6 +45,16 @@ class SpudSnippet < ActiveRecord::Base
37
45
  self.spud_page_liquid_tags.create(:tag_name => node.tag_name,:value => node.tag_value)
38
46
  end
39
47
  end
48
+
40
49
  end
41
50
 
51
+ def expire_cache
52
+ # Now Time to Update Parent Entries
53
+ old_name = self.name_was
54
+ values = [self.name]
55
+ values << old_name if !old_name.blank?
56
+ SpudPageLiquidTag.where(:tag_name => "snippet",:value => values).includes(:attachment).each do |tag|
57
+ partial = tag.touch
58
+ end
59
+ end
42
60
  end
@@ -1,3 +1,5 @@
1
+ require 'actionpack/action_caching'
2
+ require 'actionpack/page_caching'
1
3
  class PageSweeper < ActionController::Caching::Sweeper
2
4
  observe :spud_page,:spud_menu_item
3
5
 
@@ -14,11 +14,16 @@
14
14
  <%=render :inline => @inline%>
15
15
  <%end%>
16
16
  <%@page.spud_page_partials.each do |page_partial|%>
17
+
17
18
  <%if(page_partial.name.match(/^body$/i) && Spud::Cms.yield_body_as_content_block == false)%>
18
- <%=page_partial.content_processed.html_safe%>
19
+ <%cache page_partial do%>
20
+ <%=page_partial.content_processed.html_safe%>
21
+ <%end%>
19
22
  <%else%>
20
23
  <%=content_for page_partial.symbol_name.to_sym do%>
21
- <%=page_partial.content_processed.html_safe%>
24
+ <%cache page_partial do%>
25
+ <%=page_partial.content_processed.html_safe%>
26
+ <%end%>
22
27
  <%end%>
23
28
  <%end%>
24
29
  <%end%>
@@ -5,22 +5,15 @@
5
5
  <div class="controls">
6
6
  <%=f.text_field :name,:title => "",:size=>40%>
7
7
  </div>
8
-
9
- </div>
10
- <div class="control-group">
11
8
 
12
- <%=f.label :menu_order, :required=>true,:class => "control-label"%>
13
- <div class="controls">
14
- <%=f.text_field :menu_order,:title => "",:size=>5%>
15
- </div>
16
-
17
9
  </div>
10
+
18
11
  <div class="control-group">
19
12
  <%=f.label :spud_page_id, "Page",:class => "control-label"%>
20
13
  <div class="controls">
21
14
  <%=f.select :spud_page_id,options_for_select(SpudPage.options_tree_for_page(:site_id => session[:admin_site]),@menu_item.spud_page_id),{:include_blank => 'Use URL instead'},{:title => "",:onchange => "if($(this).val() != '') {$('#spud_menu_item_url').val('');}"}%>
22
15
  </div>
23
-
16
+
24
17
  </div>
25
18
 
26
19
 
@@ -42,7 +35,7 @@
42
35
  <div class="controls">
43
36
  <%=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 => ""}%>
44
37
  </div>
45
-
38
+
46
39
  </div>
47
40
 
48
41
  </fieldset>
@@ -1,8 +1,8 @@
1
- <div class="page_row" menu_item_id="<%=menu_item.id%>">
1
+ <div class="page_row menu-item-row" data-menu-item-id="<%=menu_item.id%>">
2
2
 
3
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
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 => 'btn'%>&nbsp;&nbsp;<%=link_to "Remove",spud_admin_menu_menu_item_path(:id => menu_item.id),:method => :delete,:class => 'btn btn-danger',:confirm => "Are you sure you want to remove this menu item?"%></span>
5
+ <span class="edit_controls"><%=link_to "Edit",edit_spud_admin_menu_menu_item_path(:id => menu_item.id), :title => "Edit Menu Item",:class => 'btn btn-small'%>&nbsp;&nbsp;<%=link_to "Remove",spud_admin_menu_menu_item_path(:id => menu_item.id),:method => :delete,:class => 'btn btn-small btn-danger', :data => {:confirm => "Are you sure you want to remove this menu item?"}%></span>
6
6
  <br style="clear:both;"/>
7
7
  </div>
8
8
  <ul class="menu_list subitem sortable connectedSortable">
@@ -2,6 +2,7 @@
2
2
  <%=link_to "New Menu Item",new_spud_admin_menu_menu_item_path(),:class => "btn btn-primary",:title => "New Menu Item"%>
3
3
  <%end%>
4
4
  <%=content_for :detail do%>
5
+ <p class="lead">Drag and drop to rearrange your menus.</p>
5
6
  <ul id="root_menu_list" class="menu_list page_list sortable connectedSortable">
6
7
  <%@menu_items.each do |menu_item|%>
7
8
  <li>
@@ -11,7 +12,8 @@
11
12
 
12
13
  </ul>
13
14
 
15
+
14
16
  <script type="text/javascript">
15
- $(document).ready(function() { spud.admin.cms.menu_items.init();})
17
+ $(document).ready(function() { spud.admin.cms.menu_items.init(<%=@menu.id%>);})
16
18
  </script>
17
19
  <%end%>
@@ -14,7 +14,14 @@
14
14
  <%=f.fields_for :spud_page_partials do |b|%>
15
15
  <div class="formtab tab-pane">
16
16
  <%=b.hidden_field :name,:class => "tab_name"%>
17
- <%=b.text_area :content,:class => "tinymce"%>
17
+ <div class="control-group">
18
+ <div class="controls">
19
+ <%=b.select :format,Spud::Core.renderers.collect { |k,v| [v[:description] || k, k]}, {:include_blank => false}, :class => "pull-right", "data-formatter" => "spud_partial_#{b.object.name.parameterize}"%>
20
+ </div>
21
+ </div>
22
+ <div style="clear:both;">
23
+ <%=b.text_area :content,:class => "spud-formatted-editor", :rows => 10, :id => "spud_partial_#{b.object.name.parameterize}","data-format" => b.object.format%>
24
+ </div>
18
25
  </div>
19
26
  <%end%>
20
27
  </div>
@@ -4,17 +4,19 @@
4
4
 
5
5
  <meta name="keywords" content="<%=@page.meta_keywords%>" />
6
6
  <%end%>
7
-
8
- <%if !@inline.blank?%>
9
- <%=render :inline => @inline%>
10
- <%end%>
11
- <%@page.spud_page_partials.each do |page_partial|%>
12
-
13
- <%if(page_partial.name.downcase == 'body' && Spud::Cms.yield_body_as_content_block == false)%>
14
- <%=page_partial.postprocess_content.html_safe%>
15
- <%else%>
16
- <%=content_for page_partial.name.parameterize.underscore.to_sym do%>
17
- <%=page_partial.postprocess_content.html_safe%>
7
+ <%cache @page do%>
8
+ <%if !@inline.blank?%>
9
+ <%=render :inline => @inline%>
10
+ <%end%>
11
+ <%@page.spud_page_partials.each do |page_partial|%>
12
+ <%cache page_partial do%>
13
+ <%if(page_partial.name.downcase == 'body' && Spud::Cms.yield_body_as_content_block == false)%>
14
+ <%=page_partial.postprocess_content.html_safe%>
15
+ <%else%>
16
+ <%=content_for page_partial.name.parameterize.underscore.to_sym do%>
17
+ <%=page_partial.postprocess_content.html_safe%>
18
+ <%end%>
19
+ <%end%>
18
20
  <%end%>
19
21
  <%end%>
20
22
  <%end%>
@@ -4,5 +4,12 @@
4
4
  </fieldset>
5
5
  <br/>
6
6
  <div>
7
- <%= f.text_area :content,:style => "width:100%;", :class => 'tinymce full-width' %>
7
+ <div class="control-group">
8
+ <div class="controls">
9
+ <%=f.select :format,Spud::Core.renderers.collect { |k,v| [v[:description] || k, k]}, {:include_blank => false}, :class => "pull-right", "data-formatter" => "spud_snippet_content_area"%>
10
+ </div>
11
+ </div>
12
+ <div style="clear:both;">
13
+ <%= f.text_area :content,:style => "width:100%;", :id => "spud_snippet_content_area", :class => 'spud-formatted-editor full-width',"data-format" => f.object.format %>
14
+ </div>
8
15
  </div>
data/config/routes.rb CHANGED
@@ -12,7 +12,9 @@ Rails.application.routes.draw do
12
12
  resources :snippets
13
13
 
14
14
  resources :menus do
15
- resources :menu_items
15
+ resources :menu_items do
16
+ put :sort, :on => :collection
17
+ end
16
18
  end
17
19
  resources :contacts
18
20
  end
@@ -20,7 +22,10 @@ Rails.application.routes.draw do
20
22
  resource :sitemap,:only => "show"
21
23
  end
22
24
  end
23
- root :to => 'pages#show'
25
+
26
+ if Spud::Cms.config.root_page_name
27
+ root :to => 'pages#show'
28
+ end
24
29
 
25
30
  # This is located in lib/spud_cms/page_route.rb to make sure it is loaded last
26
31
  # match "*id", :controller => "pages",:action => "show", :as => "page"
@@ -2,7 +2,8 @@ require 'spud_core'
2
2
  require 'spud_permalinks'
3
3
  require 'codemirror-rails'
4
4
  require 'liquid'
5
-
5
+ require 'rails/observers/activerecord/active_record'
6
+ require 'rails/observers/action_controller/caching/sweeping'
6
7
  module Spud
7
8
  module Cms
8
9
  class Engine < Rails::Engine
@@ -34,13 +35,15 @@ module Spud
34
35
  include Spud::Searchable
35
36
  end
36
37
  end
37
- initializer :cms_sweepers do |config|
38
- if ActiveRecord::Base.connection.tables.include?('spud_pages')
39
- Spud::Admin::ApplicationController.instance_eval do
40
- cache_sweeper :page_sweeper, :except => [:show,:index]
41
- end
42
- end
43
- end
38
+ # initializer :cms_sweepers do |config|
39
+
40
+ # ActionController::Base.extend ActionController::Caching::Sweeping::ClassMethods
41
+ # if ActiveRecord::Base.connection.tables.include?('spud_pages')
42
+ # Spud::Admin::ApplicationController.instance_eval do
43
+ # cache_sweeper :page_sweeper, :except => [:show,:index]
44
+ # end
45
+ # end
46
+ # end
44
47
 
45
48
  initializer :spud_cms_routes do |config|
46
49
  config.routes_reloader.paths << File.expand_path('../page_route.rb', __FILE__)
@@ -0,0 +1,28 @@
1
+ module Spud::LiquidTaggable
2
+ extend ActiveSupport::Concern
3
+ included do
4
+ extend ClassMethods
5
+ end
6
+ module ClassMethods
7
+ def liquid_taggable(options)
8
+ @liquid_tag_name = options[:tag_name]
9
+ @liquid_tag_id_field = options[:tag_id_field] || :name
10
+ after_save :expire_cache
11
+ after_destroy :expire_cache
12
+ end
13
+ end
14
+
15
+ def expire_cache
16
+ # Now Time to Update Parent Entries
17
+ old_name = self.name_was
18
+ values = [self.name]
19
+ values << old_name if !old_name.blank?
20
+ SpudPageLiquidTag.where(:tag_name => "snippet",:value => values).includes(:attachment).each do |tag|
21
+ partial = tag.touch
22
+ end
23
+ end
24
+
25
+ def tag_name
26
+ self.superclass.instance_variable_get('@liquid_tag_name')
27
+ end
28
+ end
@@ -1,5 +1,5 @@
1
- Rails.application.routes.append do
1
+ Rails.application.routes.draw do
2
2
  # constraints :path => /(?!assets)/ do
3
- match "*id", :controller => "pages",:action => "show", :as => "page"
3
+ get "*id", :controller => "pages",:action => "show", :as => "page"
4
4
  # end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Spud
2
2
  module Cms
3
- VERSION = "0.9.21"
3
+ VERSION = "1.0.0.RC1"
4
4
  end
5
5
  end
@@ -84,8 +84,11 @@ describe PagesController do
84
84
 
85
85
  it "should not show a page on a different site" do
86
86
  page = FactoryGirl.create(:spud_page,:name => "about",:site_id => 0)
87
- get :show,:id=>"about"
88
- response.response_code.should == 404
87
+ expect {
88
+ get :show,:id=>"about"
89
+ }.to raise_exception(ActionController::RoutingError)
90
+
91
+ # response.response_code.should == 404
89
92
  end
90
93
 
91
94
  it "should show the right page" do
@@ -18,8 +18,9 @@ describe Spud::Cms::SitemapsController do
18
18
  end
19
19
 
20
20
  it "should only respond to an XML format" do
21
- get :show
22
- response.response_code.should == 406
21
+ expect {
22
+ get :show
23
+ }.to raise_exception(ActionController::UnknownFormat)
23
24
  end
24
25
 
25
26
  describe :multisite do
@@ -6,8 +6,6 @@ Dummy::Application.configure do
6
6
  # since you don't have to restart the web server when you make code changes.
7
7
  config.cache_classes = false
8
8
 
9
- # Log error messages when you accidentally call methods on nil.
10
- config.whiny_nils = true
11
9
 
12
10
  # Show full error reports and disable caching
13
11
  config.consider_all_requests_local = true
@@ -22,8 +20,7 @@ Dummy::Application.configure do
22
20
  # Only use best-standards-support built into browsers
23
21
  config.action_dispatch.best_standards_support = :builtin
24
22
 
25
- # Raise exception on mass assignment protection for Active Record models
26
- config.active_record.mass_assignment_sanitizer = :strict
23
+
27
24
 
28
25
  # Log the query plan for queries taking more than this (works
29
26
  # with SQLite, MySQL, and PostgreSQL)
@@ -32,6 +29,7 @@ Dummy::Application.configure do
32
29
  # Do not compress assets
33
30
  config.assets.compress = false
34
31
 
32
+ config.eager_load = false
35
33
  # Expands the lines which load the assets
36
34
  config.assets.debug = true
37
35
  end
@@ -60,7 +60,7 @@ Dummy::Application.configure do
60
60
 
61
61
  # Send deprecation notices to registered listeners
62
62
  config.active_support.deprecation = :notify
63
-
63
+ config.eager_load = true
64
64
  # Log the query plan for queries taking more than this (works
65
65
  # with SQLite, MySQL, and PostgreSQL)
66
66
  # config.active_record.auto_explain_threshold_in_seconds = 0.5