From b2b069aecf1219e3cdde0a53fa2a64262c64b15d Mon Sep 17 00:00:00 2001 From: Derek Ethier Date: Mon, 23 Jul 2012 13:51:50 -0700 Subject: [PATCH 1/4] Add migration for render_as_partial_for_layout toggle --- ..._render_as_partial_for_layout_for_spree_pages.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 db/migrate/20120723144115_add_render_as_partial_for_layout_for_spree_pages.rb diff --git a/db/migrate/20120723144115_add_render_as_partial_for_layout_for_spree_pages.rb b/db/migrate/20120723144115_add_render_as_partial_for_layout_for_spree_pages.rb new file mode 100644 index 00000000..01e2a4b2 --- /dev/null +++ b/db/migrate/20120723144115_add_render_as_partial_for_layout_for_spree_pages.rb @@ -0,0 +1,13 @@ +class AddRenderAsPartialForLayoutForSpreePages < ActiveRecord::Migration + def up + unless column_exists? :spree_pages, :render_layout_as_partial + add_column :spree_pages, :render_layout_as_partial, :boolean, :default => false + end + end + + def down + if column_exists? :spree_pages, :render_layout_as_partial + remove_column :spree_pages, :render_layout_as_partial + end + end +end From 5caff4a90ba7747c046a4508fec07ca5e8d557fd Mon Sep 17 00:00:00 2001 From: Derek Ethier Date: Mon, 23 Jul 2012 13:52:06 -0700 Subject: [PATCH 2/4] Update documentation --- README.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bc76fc4b..7f111ffc 100644 --- a/README.md +++ b/README.md @@ -10,15 +10,24 @@ Good, clean content management of pages for Spree. You can use this to: ## HowTo -See the wiki for some more documentation on how you can use this extension. +The title, slug, body, and meta fields are fairly self-explanatory. They will replace their respective page +elements on load. -- use spree_editor. -- override dynamic pages. -- ... +A title, slug and body element are all required. + +If you would like to render an entire page without the spree_application layout, specify a relative path to the +layout file (eg. spree/layouts/layout_file_name). If you do not want this layout file to render without the full +spree application layout, check the render layout as partial option. Remember to prefix your layout file with an +underscore. + +Use the show in checkboxes to specify where the page links will be shown. Use the position setting to change the +order in which they appear. + +Finally, you can toggle the visibility using the visible checkbox. ## Basic Installation -**For Spree 1.0.x** +**For Spree 1.0.x**/1.1.x** 1. Add the following to your Gemfile

From 4202c163397dab77ec5f0a3417bc5fdf1a28b255 Mon Sep 17 00:00:00 2001
From: Derek Ethier 
Date: Mon, 23 Jul 2012 13:52:56 -0700
Subject: [PATCH 3/4] Add render_as_partial_for_layout support to the form and
 show views as well update the model and controller for this action.

---
 .../spree/static_content_controller.rb        |  4 +-
 app/models/spree/page.rb                      |  3 +-
 app/views/spree/admin/pages/_form.html.erb    |  6 ++-
 app/views/spree/static_content/show.html.erb  | 42 ++++++++++---------
 4 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/app/controllers/spree/static_content_controller.rb b/app/controllers/spree/static_content_controller.rb
index 01c787bf..8644dea3 100644
--- a/app/controllers/spree/static_content_controller.rb
+++ b/app/controllers/spree/static_content_controller.rb
@@ -2,7 +2,7 @@ class Spree::StaticContentController < Spree::BaseController
   caches_action :show, :cache_path => Proc.new { |controller|
     "spree_static_content/" + controller.params[:path].to_s + "_spree_static_content"
   }
-  
+
   layout :determine_layout
   
   def show
@@ -23,7 +23,7 @@ def show
   private
   
   def determine_layout
-    return @page.layout if @page and @page.layout.present?
+    return @page.layout if @page and @page.layout.present? and not @page.render_layout_as_partial?
     'spree/layouts/spree_application'
   end
 
diff --git a/app/models/spree/page.rb b/app/models/spree/page.rb
index 5d18aa50..ed8aa2cc 100644
--- a/app/models/spree/page.rb
+++ b/app/models/spree/page.rb
@@ -3,6 +3,7 @@ class Spree::Page < ActiveRecord::Base
 
   validates_presence_of :title
   validates_presence_of [:slug, :body], :if => :not_using_foreign_link?
+  validates_presence_of :layout, :if => :render_layout_as_partial?
 
   scope :visible, where(:visible => true)
   scope :header_links, where(:show_in_header => true).visible
@@ -11,7 +12,7 @@ class Spree::Page < ActiveRecord::Base
 
   before_save :update_positions_and_slug
 
-  attr_accessible :title, :slug, :body, :meta_title, :meta_keywords, :meta_description, :layout, :foreign_link, :position, :show_in_sidebar, :show_in_header, :show_in_footer, :visible
+  attr_accessible :title, :slug, :body, :meta_title, :meta_keywords, :meta_description, :layout, :foreign_link, :position, :show_in_sidebar, :show_in_header, :show_in_footer, :visible, :render_layout_as_partial
 
   def self.by_slug(slug)
     slug = StaticPage::remove_spree_mount_point(slug) unless Rails.application.routes.url_helpers.spree_path == "/"
diff --git a/app/views/spree/admin/pages/_form.html.erb b/app/views/spree/admin/pages/_form.html.erb
index ce9ba52d..4f9092ed 100644
--- a/app/views/spree/admin/pages/_form.html.erb
+++ b/app/views/spree/admin/pages/_form.html.erb
@@ -13,7 +13,7 @@
     <% end %>
 
     <%= f.field_container :body do %>
-      <%= f.label :body %>
+ <%= f.label :body %>*
<%= f.text_area :body, {:class => 'fullwidth'} %> <%= f.error_message_on :body %> <% end %> @@ -70,6 +70,10 @@ <%= f.check_box :visible %> <%= f.label :visible %> +
  • + <%= f.check_box :render_layout_as_partial %> + <%= f.label :render_layout_as_partial %> +
  • diff --git a/app/views/spree/static_content/show.html.erb b/app/views/spree/static_content/show.html.erb index a9e9d51e..cddace49 100644 --- a/app/views/spree/static_content/show.html.erb +++ b/app/views/spree/static_content/show.html.erb @@ -1,22 +1,26 @@ -<% content_for :head do -%> - <%- if @page.meta_title.present? -%> - - <%- else -%> - - <%- end -%> - - -<% end -%> +<% if @page.layout.present? and @page.render_layout_as_partial? %> + <%= render :partial => @page.layout %> +<% else %> + <% content_for :head do -%> + <%- if @page.meta_title.present? -%> + + <%- else -%> + + <%- end -%> + + + <% end -%> -<% content_for :sidebar do %> - <% if "products" == @current_controller && @taxon %> - <%= render :partial => "spree/shared/filters" %> - <% else %> - <%= render :partial => "spree/shared/taxonomies" %> + <% content_for :sidebar do %> + <% if "products" == @current_controller && @taxon %> + <%= render :partial => "spree/shared/filters" %> + <% else %> + <%= render :partial => "spree/shared/taxonomies" %> + <% end %> <% end %> -<% end %> -

    <%= @page.title %>

    -
    - <%= raw @page.body %> -
    \ No newline at end of file +

    <%= @page.title %>

    +
    + <%= raw @page.body %> +
    +<% end %> \ No newline at end of file From 19f0f6e3086200a5b54b37e6b4702813323f0d0a Mon Sep 17 00:00:00 2001 From: Derek Ethier Date: Mon, 23 Jul 2012 14:01:45 -0700 Subject: [PATCH 4/4] Update documentation for Spree 1.1.x --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7f111ffc..2a954056 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Finally, you can toggle the visibility using the visible checkbox. ## Basic Installation -**For Spree 1.0.x**/1.1.x** +**For Spree 1.0.x** 1. Add the following to your Gemfile
    @@ -36,6 +36,15 @@ Finally, you can toggle the visibility using the visible checkbox.
     2. Run `bundle install`
     3. To copy and apply migrations run: `rails g spree_static_content:install`
     
    +**For Spree 1.1.x**
    +
    +1. Add the following to your Gemfile
    +
    +  gem 'spree_static_content', :git => 'git@github.com:spree/spree_static_content.git', :branch => 'master'
    +
    +2. Run `bundle install` +3. To copy and apply migrations run: `rails g spree_static_content:install` + ## Development 1. fork the repo here: https://github.com/spree/spree_static_content