Skip to content

Commit 84bca93

Browse files
committed
Ported spree static content to Solidus.
1 parent 01f620c commit 84bca93

File tree

72 files changed

+1597
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1597
-2
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
nbproject
3+
**.gem
4+
Gemfile.lock
5+
spec/dummy/
6+
.rvmrc
7+
tmp
8+
coverage

.rbenv-gemsets

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spree_static_content

.rspec

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--colour
2+
--format
3+
progress

.ruby-gemset

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spree_static_content

.ruby-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.1.5

.travis.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
language: ruby
2+
rvm:
3+
- 1.9.3
4+
- 2.0.0
5+
- 2.1.0
6+
before_script:
7+
- "bundle exec rake test_app"
8+
script: "DISPLAY=:99.0 bundle exec rspec spec"
9+
notifications:
10+
email:
11+
12+
irc:
13+
channels:
14+
- "irc.freenode.org#spree"
15+
use_notice: true
16+
branches:
17+
only:
18+
- master
19+
- 1-3-stable
20+
- 2-0-stable
21+
- 2-1-stable
22+
- 2-2-stable
23+
- 2-3-stable

Gemfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'https://rubygems.org/'
2+
gem "solidus", github: 'solidusio/solidus', branch: 'master'
3+
gemspec

Guardfile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
guard "rspec", cmd: "bundle exec rspec" do
2+
watch("spec/spec_helper.rb") { "spec" }
3+
watch("config/routes.rb") { "spec/controllers" }
4+
watch("app/controllers/application_controller.rb") { "spec/controllers" }
5+
watch(%r{^spec/(.+)_spec\.rb$}) { |m| "spec/#{m[1]}_spec.rb"}
6+
watch(%r{^app/(.+)_decorator\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7+
watch(%r{^(app|lib)/(.+)(\.rb|\.erb)$}) { |m| "spec/#{m[2]}_spec.rb" }
8+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb" }
9+
end

LICENSE.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright (c) 2014 Peter Berkenbosch and contributors.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification,
5+
are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice,
8+
this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation
11+
and/or other materials provided with the distribution.
12+
* Neither the name Spree nor the names of its contributors may be used to
13+
endorse or promote products derived from this software without specific
14+
prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

100644100755
+94-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,94 @@
1-
# solidus_static_content
2-
Completely based on spree_static_content
1+
# Spree Static Content
2+
3+
[![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)
4+
[![Code Climate](https://codeclimate.com/github/spree-contrib/spree_static_content/badges/gpa.svg)](https://codeclimate.com/github/spree-contrib/spree_static_content)
5+
6+
Good, clean content management of pages for Spree. You can use this to:
7+
8+
- Add and manage static pages such as an 'About' page.
9+
- Show a static page instead of existing dynamic pages such as the home page,
10+
products pages, and taxon pages.
11+
12+
## HowTo
13+
14+
Using the 'Pages' option in the admin tab, you can add static pages to your Spree install. The page content can
15+
be pulled directly from the database, be a separate layout file or rendered as a partial.
16+
17+
In the admin tab, use the 'New page' option to create a new static page.
18+
19+
The title, slug, body, and meta fields will replace their respective page elements on load. The title, slug and
20+
body element are all required fields.
21+
22+
Body text provided without a layout / partial being specified will be loaded in the spree_application layout after
23+
it is pulled from the database.
24+
25+
**Layout and Partial Rendering**
26+
27+
To render an entire page without the spree_application layout, specify a relative path to the layout file (eg.
28+
`spree/layouts/layout_file_name`). This file will not be prefixed with an underscore as it is a layout, not a partial.
29+
30+
To render a partial, specify the path in the layout file name and check the 'Render layout as partial' option. The
31+
path specified in the layout area will not have an underscore, but it will be required in the filename.
32+
33+
Also note the availability of the render_snippet helper which finds a page by its slug and renders the raw page
34+
body anywhere in your view.
35+
36+
**Options**
37+
38+
Use the 'Show in' checkboxes to specify whether to display the page links in the header, footer or sidebar. The
39+
position setting alters the order in which they appear.
40+
41+
Finally, toggle the visibility using the 'Visible' checkbox. If it is unchecked, the page will not be available.
42+
43+
## Basic Installation
44+
45+
Add to your `Gemfile`:
46+
47+
```ruby
48+
gem 'spree_static_content', github: 'spree-contrib/spree_static_content', branch: '2-4-stable'
49+
```
50+
51+
Run:
52+
53+
bundle install
54+
rails g spree_static_content:install
55+
56+
That's all!
57+
58+
**NOTE: Check [Versionfile][1] for corresponding gem `branch` for your Spree version.**
59+
60+
## Contributing
61+
62+
In the spirit of [free software][2], **everyone** is encouraged to help improve this project.
63+
64+
Here are some ways *you* can contribute:
65+
66+
* by using prerelease versions
67+
* by reporting [bugs][3]
68+
* by suggesting new features
69+
* by writing translations
70+
* by writing or editing documentation
71+
* by writing specifications
72+
* by writing code (*no patch is too small*: fix typos, add comments, clean up inconsistent whitespace)
73+
* by refactoring code
74+
* by resolving [issues][3]
75+
* by reviewing patches
76+
77+
Starting point:
78+
79+
* Fork the repo
80+
* Clone your repo
81+
* Run `bundle install`
82+
* Run `bundle exec rake test_app` to create the test application in `spec/test_app`
83+
* Make your changes
84+
* Ensure specs pass by running `bundle exec rspec spec`
85+
* Submit your pull request
86+
87+
Copyright (c) 2014 [Peter Berkenbosch][4] and [contributors][5], released under the [New BSD License][6]
88+
89+
[1]: https://github.com/spree-contrib/spree_static_content/blob/master/Versionfile
90+
[2]: http://www.fsf.org/licensing/essays/free-sw.html
91+
[3]: https://github.com/spree-contrib/spree_static_content/issues
92+
[4]: https://github.com/peterberkenbosch
93+
[5]: https://github.com/spree-contrib/spree_static_content/graphs/contributors
94+
[6]: https://github.com/spree-contrib/spree_static_content/blob/master/LICENSE.md

Rakefile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'bundler'
2+
Bundler::GemHelper.install_tasks
3+
4+
require 'rspec/core/rake_task'
5+
require 'spree/testing_support/common_rake'
6+
7+
RSpec::Core::RakeTask.new
8+
9+
task :default => [:spec]
10+
11+
desc "Generates a dummy app for testing"
12+
task :test_app do
13+
ENV['LIB_NAME'] = 'spree_static_content'
14+
Rake::Task['common:test_app'].invoke
15+
end

VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.3.0

Versionfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"2.3.x" => { :branch => '2-3-stable' }
2+
"2.2.x" => { :branch => '2-2-stable' }
3+
"2.1.x" => { :branch => '2-1-stable' }
4+
"2.0.x" => { :branch => '2-0-stable' }
5+
"1.3.x" => { :branch => '1-3-stable' }
6+
"1.2.x" => { :branch => '1-2-stable' }
7+
"1.1.x" => { :branch => '1-1-stable', :version => '1.1' }
8+
"1.0.x" => { :branch => '1-0-stable', :version => '1.0.1' }
9+
"0.70.x" => { :version => '0.70.3', :ref => '1861f4cd08c0ffa9940f0c81e69ea29b4541dbbd' }
10+
"0.60.x" => { :tag => "v0.60.2", :version => '0.60.2'}
11+
"0.50.x" => { :version => '0.40.2', :ref => '45b0050b96809c8fb0f21940f9407e9012a6d420' }
12+
"0.40.x" => { :version => '0.40.2', :ref => '45b0050b96809c8fb0f21940f9407e9012a6d420' }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//= require spree/backend
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//= require spree/frontend
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/*
2+
*= require spree/backend
3+
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* Sidebar */
2+
nav#pages .pages-root {
3+
text-transform: uppercase;
4+
border-bottom: 1px solid rgb(217, 217, 219);
5+
margin-bottom: 5px;
6+
font-size: 14px;
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Spree::Admin::PagesController < Spree::Admin::ResourceController
2+
3+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Spree::StaticContentController < Spree::StoreController
2+
rescue_from ActiveRecord::RecordNotFound, :with => :render_404
3+
4+
helper 'spree/products'
5+
layout :determine_layout
6+
7+
def show
8+
@page = Spree::Page.by_store(current_store).visible.find_by_slug!(request.path)
9+
end
10+
11+
private
12+
def determine_layout
13+
return @page.layout if @page and @page.layout.present? and not @page.render_layout_as_partial?
14+
Spree::Config.layout
15+
end
16+
17+
def accurate_title
18+
@page ? (@page.meta_title.present? ? @page.meta_title : @page.title) : nil
19+
end
20+
end

app/helpers/spree/pages_helper.rb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Spree::PagesHelper
2+
def render_snippet(slug)
3+
page = Spree::Page.find_by_slug(slug)
4+
raw page.body if page
5+
end
6+
end

app/models/spree/page.rb

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
class Spree::Page < ActiveRecord::Base
2+
default_scope -> { order("position ASC") }
3+
4+
has_and_belongs_to_many :stores, :join_table => 'spree_pages_stores'
5+
6+
validates_presence_of :title
7+
validates_presence_of [:slug, :body], :if => :not_using_foreign_link?
8+
validates_presence_of :layout, :if => :render_layout_as_partial?
9+
10+
validates :slug, :uniqueness => true, :if => :not_using_foreign_link?
11+
validates :foreign_link, :uniqueness => true, :allow_blank => true
12+
13+
scope :visible, -> { where(:visible => true) }
14+
scope :header_links, -> { where(:show_in_header => true).visible }
15+
scope :footer_links, -> { where(:show_in_footer => true).visible }
16+
scope :sidebar_links, -> { where(:show_in_sidebar => true).visible }
17+
18+
scope :by_store, lambda { |store| joins(:stores).where("spree_pages_stores.store_id = ?", store) }
19+
20+
before_save :update_positions_and_slug
21+
22+
def initialize(*args)
23+
super(*args)
24+
25+
last_page = Spree::Page.last
26+
self.position = last_page ? last_page.position + 1 : 0
27+
end
28+
29+
def link
30+
foreign_link.blank? ? slug : foreign_link
31+
end
32+
33+
private
34+
35+
def update_positions_and_slug
36+
# ensure that all slugs start with a slash
37+
slug.prepend('/') if not_using_foreign_link? and not slug.start_with? '/'
38+
39+
unless new_record?
40+
return unless prev_position = Spree::Page.find(self.id).position
41+
if prev_position > self.position
42+
Spree::Page.where("? <= position AND position < ?", self.position, prev_position).update_all("position = position + 1")
43+
elsif prev_position < self.position
44+
Spree::Page.where("? < position AND position <= ?", prev_position, self.position).update_all("position = position - 1")
45+
end
46+
end
47+
48+
true
49+
end
50+
51+
def not_using_foreign_link?
52+
foreign_link.blank?
53+
end
54+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Deface::Override.new(virtual_path: "spree/admin/shared/_configuration_menu",
2+
name: "pages_admin_configurations_menu",
3+
insert_bottom: "[data-hook='admin_configurations_sidebar_menu'], #admin_configurations_sidebar_menu[data-hook]",
4+
text: "<%= configurations_sidebar_menu_item Spree.t(:pages), admin_pages_path %>",
5+
disabled: false)

app/overrides/pages_in_footer.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Deface::Override.new(:virtual_path => "spree/shared/_footer",
2+
:name => "pages_in_footer",
3+
:insert_bottom => "#footer-right",
4+
:partial => "spree/static_content/static_content_footer",
5+
:disabled => false)

app/overrides/pages_in_header.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Deface::Override.new(:virtual_path => "spree/shared/_main_nav_bar",
2+
:name => "pages_in_header",
3+
:insert_bottom => "#main-nav-bar",
4+
:partial => "spree/static_content/static_content_header",
5+
:disabled => false)

app/overrides/pages_in_sidebar.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Deface::Override.new(:virtual_path => "spree/shared/_sidebar",
2+
:name => "pages_in_sidebar",
3+
:insert_bottom => "#sidebar",
4+
:partial => "spree/static_content/static_content_sidebar",
5+
:disabled => false)

0 commit comments

Comments
 (0)