Skip to content

Commit

Permalink
Ported spree static content to Solidus.
Browse files Browse the repository at this point in the history
  • Loading branch information
njakic committed Aug 25, 2015
1 parent 01f620c commit 84bca93
Show file tree
Hide file tree
Showing 72 changed files with 1,597 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
nbproject
**.gem
Gemfile.lock
spec/dummy/
.rvmrc
tmp
coverage
1 change: 1 addition & 0 deletions .rbenv-gemsets
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spree_static_content
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--colour
--format
progress
1 change: 1 addition & 0 deletions .ruby-gemset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spree_static_content
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.1.5
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
language: ruby
rvm:
- 1.9.3
- 2.0.0
- 2.1.0
before_script:
- "bundle exec rake test_app"
script: "DISPLAY=:99.0 bundle exec rspec spec"
notifications:
email:
- [email protected]
irc:
channels:
- "irc.freenode.org#spree"
use_notice: true
branches:
only:
- master
- 1-3-stable
- 2-0-stable
- 2-1-stable
- 2-2-stable
- 2-3-stable
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org/'
gem "solidus", github: 'solidusio/solidus', branch: 'master'
gemspec
9 changes: 9 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
guard "rspec", cmd: "bundle exec rspec" do
watch("spec/spec_helper.rb") { "spec" }
watch("config/routes.rb") { "spec/controllers" }
watch("app/controllers/application_controller.rb") { "spec/controllers" }
watch(%r{^spec/(.+)_spec\.rb$}) { |m| "spec/#{m[1]}_spec.rb"}
watch(%r{^app/(.+)_decorator\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^(app|lib)/(.+)(\.rb|\.erb)$}) { |m| "spec/#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb" }
end
26 changes: 26 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright (c) 2014 Peter Berkenbosch and contributors.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name Spree nor the names of its contributors may be used to
endorse or promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
96 changes: 94 additions & 2 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,94 @@
# solidus_static_content
Completely based on spree_static_content
# Spree Static Content

[![Build Status](https://travis-ci.org/spree-contrib/spree_static_content.svg?branch=2-4-stable)](https://travis-ci.org/spree-contrib/spree_static_content)
[![Code Climate](https://codeclimate.com/github/spree-contrib/spree_static_content/badges/gpa.svg)](https://codeclimate.com/github/spree-contrib/spree_static_content)

Good, clean content management of pages for Spree. You can use this to:

- Add and manage static pages such as an 'About' page.
- Show a static page instead of existing dynamic pages such as the home page,
products pages, and taxon pages.

## HowTo

Using the 'Pages' option in the admin tab, you can add static pages to your Spree install. The page content can
be pulled directly from the database, be a separate layout file or rendered as a partial.

In the admin tab, use the 'New page' option to create a new static page.

The title, slug, body, and meta fields will replace their respective page elements on load. The title, slug and
body element are all required fields.

Body text provided without a layout / partial being specified will be loaded in the spree_application layout after
it is pulled from the database.

**Layout and Partial Rendering**

To render an entire page without the spree_application layout, specify a relative path to the layout file (eg.
`spree/layouts/layout_file_name`). This file will not be prefixed with an underscore as it is a layout, not a partial.

To render a partial, specify the path in the layout file name and check the 'Render layout as partial' option. The
path specified in the layout area will not have an underscore, but it will be required in the filename.

Also note the availability of the render_snippet helper which finds a page by its slug and renders the raw page
body anywhere in your view.

**Options**

Use the 'Show in' checkboxes to specify whether to display the page links in the header, footer or sidebar. The
position setting alters the order in which they appear.

Finally, toggle the visibility using the 'Visible' checkbox. If it is unchecked, the page will not be available.

## Basic Installation

Add to your `Gemfile`:

```ruby
gem 'spree_static_content', github: 'spree-contrib/spree_static_content', branch: '2-4-stable'
```

Run:

bundle install
rails g spree_static_content:install

That's all!

**NOTE: Check [Versionfile][1] for corresponding gem `branch` for your Spree version.**

## Contributing

In the spirit of [free software][2], **everyone** is encouraged to help improve this project.

Here are some ways *you* can contribute:

* by using prerelease versions
* by reporting [bugs][3]
* by suggesting new features
* by writing translations
* by writing or editing documentation
* by writing specifications
* by writing code (*no patch is too small*: fix typos, add comments, clean up inconsistent whitespace)
* by refactoring code
* by resolving [issues][3]
* by reviewing patches

Starting point:

* Fork the repo
* Clone your repo
* Run `bundle install`
* Run `bundle exec rake test_app` to create the test application in `spec/test_app`
* Make your changes
* Ensure specs pass by running `bundle exec rspec spec`
* Submit your pull request

Copyright (c) 2014 [Peter Berkenbosch][4] and [contributors][5], released under the [New BSD License][6]

[1]: https://github.com/spree-contrib/spree_static_content/blob/master/Versionfile
[2]: http://www.fsf.org/licensing/essays/free-sw.html
[3]: https://github.com/spree-contrib/spree_static_content/issues
[4]: https://github.com/peterberkenbosch
[5]: https://github.com/spree-contrib/spree_static_content/graphs/contributors
[6]: https://github.com/spree-contrib/spree_static_content/blob/master/LICENSE.md
15 changes: 15 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'bundler'
Bundler::GemHelper.install_tasks

require 'rspec/core/rake_task'
require 'spree/testing_support/common_rake'

RSpec::Core::RakeTask.new

task :default => [:spec]

desc "Generates a dummy app for testing"
task :test_app do
ENV['LIB_NAME'] = 'spree_static_content'
Rake::Task['common:test_app'].invoke
end
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.3.0
12 changes: 12 additions & 0 deletions Versionfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"2.3.x" => { :branch => '2-3-stable' }
"2.2.x" => { :branch => '2-2-stable' }
"2.1.x" => { :branch => '2-1-stable' }
"2.0.x" => { :branch => '2-0-stable' }
"1.3.x" => { :branch => '1-3-stable' }
"1.2.x" => { :branch => '1-2-stable' }
"1.1.x" => { :branch => '1-1-stable', :version => '1.1' }
"1.0.x" => { :branch => '1-0-stable', :version => '1.0.1' }
"0.70.x" => { :version => '0.70.3', :ref => '1861f4cd08c0ffa9940f0c81e69ea29b4541dbbd' }
"0.60.x" => { :tag => "v0.60.2", :version => '0.60.2'}
"0.50.x" => { :version => '0.40.2', :ref => '45b0050b96809c8fb0f21940f9407e9012a6d420' }
"0.40.x" => { :version => '0.40.2', :ref => '45b0050b96809c8fb0f21940f9407e9012a6d420' }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//= require spree/backend
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//= require spree/frontend
3 changes: 3 additions & 0 deletions app/assets/stylesheets/spree/backend/spree_static_content.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*
*= require spree/backend
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* Sidebar */
nav#pages .pages-root {
text-transform: uppercase;
border-bottom: 1px solid rgb(217, 217, 219);
margin-bottom: 5px;
font-size: 14px;
}
3 changes: 3 additions & 0 deletions app/controllers/spree/admin/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Spree::Admin::PagesController < Spree::Admin::ResourceController

end
20 changes: 20 additions & 0 deletions app/controllers/spree/static_content_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Spree::StaticContentController < Spree::StoreController
rescue_from ActiveRecord::RecordNotFound, :with => :render_404

helper 'spree/products'
layout :determine_layout

def show
@page = Spree::Page.by_store(current_store).visible.find_by_slug!(request.path)
end

private
def determine_layout
return @page.layout if @page and @page.layout.present? and not @page.render_layout_as_partial?
Spree::Config.layout
end

def accurate_title
@page ? (@page.meta_title.present? ? @page.meta_title : @page.title) : nil
end
end
6 changes: 6 additions & 0 deletions app/helpers/spree/pages_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Spree::PagesHelper
def render_snippet(slug)
page = Spree::Page.find_by_slug(slug)
raw page.body if page
end
end
54 changes: 54 additions & 0 deletions app/models/spree/page.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
class Spree::Page < ActiveRecord::Base
default_scope -> { order("position ASC") }

has_and_belongs_to_many :stores, :join_table => 'spree_pages_stores'

validates_presence_of :title
validates_presence_of [:slug, :body], :if => :not_using_foreign_link?
validates_presence_of :layout, :if => :render_layout_as_partial?

validates :slug, :uniqueness => true, :if => :not_using_foreign_link?
validates :foreign_link, :uniqueness => true, :allow_blank => true

scope :visible, -> { where(:visible => true) }
scope :header_links, -> { where(:show_in_header => true).visible }
scope :footer_links, -> { where(:show_in_footer => true).visible }
scope :sidebar_links, -> { where(:show_in_sidebar => true).visible }

scope :by_store, lambda { |store| joins(:stores).where("spree_pages_stores.store_id = ?", store) }

before_save :update_positions_and_slug

def initialize(*args)
super(*args)

last_page = Spree::Page.last
self.position = last_page ? last_page.position + 1 : 0
end

def link
foreign_link.blank? ? slug : foreign_link
end

private

def update_positions_and_slug
# ensure that all slugs start with a slash
slug.prepend('/') if not_using_foreign_link? and not slug.start_with? '/'

unless new_record?
return unless prev_position = Spree::Page.find(self.id).position
if prev_position > self.position
Spree::Page.where("? <= position AND position < ?", self.position, prev_position).update_all("position = position + 1")
elsif prev_position < self.position
Spree::Page.where("? < position AND position <= ?", prev_position, self.position).update_all("position = position - 1")
end
end

true
end

def not_using_foreign_link?
foreign_link.blank?
end
end
5 changes: 5 additions & 0 deletions app/overrides/add_pages_to_admin_configuration_sidebar.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Deface::Override.new(virtual_path: "spree/admin/shared/_configuration_menu",
name: "pages_admin_configurations_menu",
insert_bottom: "[data-hook='admin_configurations_sidebar_menu'], #admin_configurations_sidebar_menu[data-hook]",
text: "<%= configurations_sidebar_menu_item Spree.t(:pages), admin_pages_path %>",
disabled: false)
5 changes: 5 additions & 0 deletions app/overrides/pages_in_footer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Deface::Override.new(:virtual_path => "spree/shared/_footer",
:name => "pages_in_footer",
:insert_bottom => "#footer-right",
:partial => "spree/static_content/static_content_footer",
:disabled => false)
5 changes: 5 additions & 0 deletions app/overrides/pages_in_header.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Deface::Override.new(:virtual_path => "spree/shared/_main_nav_bar",
:name => "pages_in_header",
:insert_bottom => "#main-nav-bar",
:partial => "spree/static_content/static_content_header",
:disabled => false)
5 changes: 5 additions & 0 deletions app/overrides/pages_in_sidebar.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Deface::Override.new(:virtual_path => "spree/shared/_sidebar",
:name => "pages_in_sidebar",
:insert_bottom => "#sidebar",
:partial => "spree/static_content/static_content_sidebar",
:disabled => false)
Loading

0 comments on commit 84bca93

Please sign in to comment.