Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Commit

Permalink
Merge pull request #65 from ethier/master
Browse files Browse the repository at this point in the history
Issue #63 - Add partial support
  • Loading branch information
peterberkenbosch committed Jul 24, 2012
2 parents 991478b + 19f0f6e commit abe3552
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 27 deletions.
26 changes: 22 additions & 4 deletions README.md
Expand Up @@ -10,11 +10,20 @@ 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

Expand All @@ -27,6 +36,15 @@ See the wiki for some more documentation on how you can use this extension.
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
<pre>
gem 'spree_static_content', :git => 'git@github.com:spree/spree_static_content.git', :branch => 'master'
</pre>
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
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/spree/static_content_controller.rb
Expand Up @@ -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
Expand All @@ -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

Expand Down
3 changes: 2 additions & 1 deletion app/models/spree/page.rb
Expand Up @@ -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
Expand All @@ -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 == "/"
Expand Down
6 changes: 5 additions & 1 deletion app/views/spree/admin/pages/_form.html.erb
Expand Up @@ -13,7 +13,7 @@
<% end %>
<%= f.field_container :body do %>
<%= f.label :body %><br />
<%= f.label :body %><span class="required">*</span><br />
<%= f.text_area :body, {:class => 'fullwidth'} %>
<%= f.error_message_on :body %>
<% end %>
Expand Down Expand Up @@ -70,6 +70,10 @@
<%= f.check_box :visible %>
<%= f.label :visible %>
</li>
<li>
<%= f.check_box :render_layout_as_partial %>
<%= f.label :render_layout_as_partial %>
</li>
</ul>

</div>
Expand Down
42 changes: 23 additions & 19 deletions app/views/spree/static_content/show.html.erb
@@ -1,22 +1,26 @@
<% content_for :head do -%>
<%- if @page.meta_title.present? -%>
<meta name="title" content="<%=@page.meta_title%>">
<%- else -%>
<meta name="title" content="<%=@page.title%>">
<%- end -%>
<meta name="keywords" content="<%=@page.meta_keywords%>">
<meta name="description" content="<%=@page.meta_description%>">
<% 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? -%>
<meta name="title" content="<%=@page.meta_title%>">
<%- else -%>
<meta name="title" content="<%=@page.title%>">
<%- end -%>
<meta name="keywords" content="<%=@page.meta_keywords%>">
<meta name="description" content="<%=@page.meta_description%>">
<% 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 %>

<h1><%= @page.title %></h1>
<div id="page_content">
<%= raw @page.body %>
</div>
<h1><%= @page.title %></h1>
<div id="page_content">
<%= raw @page.body %>
</div>
<% end %>
@@ -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

0 comments on commit abe3552

Please sign in to comment.