solidus_static_content 1.0.0

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 (69) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +21 -0
  5. data/Gemfile +13 -0
  6. data/Guardfile +9 -0
  7. data/LICENSE.md +26 -0
  8. data/README.md +105 -0
  9. data/Rakefile +15 -0
  10. data/app/assets/javascripts/spree/backend/spree_static_content.js +1 -0
  11. data/app/assets/javascripts/spree/frontend/spree_static_content.js +1 -0
  12. data/app/assets/stylesheets/spree/backend/spree_static_content.css +3 -0
  13. data/app/assets/stylesheets/spree/frontend/spree_static_content.css +7 -0
  14. data/app/controllers/spree/admin/pages_controller.rb +3 -0
  15. data/app/controllers/spree/static_content_controller.rb +20 -0
  16. data/app/helpers/spree/pages_helper.rb +6 -0
  17. data/app/models/spree/page.rb +54 -0
  18. data/app/overrides/pages_in_footer.rb +5 -0
  19. data/app/overrides/pages_in_header.rb +5 -0
  20. data/app/overrides/pages_in_menu.rb +5 -0
  21. data/app/overrides/pages_in_sidebar.rb +5 -0
  22. data/app/views/spree/admin/pages/_form.html.erb +98 -0
  23. data/app/views/spree/admin/pages/edit.html.erb +18 -0
  24. data/app/views/spree/admin/pages/index.html.erb +51 -0
  25. data/app/views/spree/admin/pages/new.html.erb +18 -0
  26. data/app/views/spree/static_content/_static_content_footer.html.erb +3 -0
  27. data/app/views/spree/static_content/_static_content_header.html.erb +1 -0
  28. data/app/views/spree/static_content/_static_content_list.html.erb +6 -0
  29. data/app/views/spree/static_content/_static_content_sidebar.html.erb +6 -0
  30. data/app/views/spree/static_content/show.html.erb +26 -0
  31. data/bin/rails +7 -0
  32. data/config/locales/de.yml +37 -0
  33. data/config/locales/en.yml +37 -0
  34. data/config/locales/es.yml +37 -0
  35. data/config/locales/et.yml +37 -0
  36. data/config/locales/fr.yml +37 -0
  37. data/config/locales/it.yml +37 -0
  38. data/config/locales/nl.yml +37 -0
  39. data/config/locales/pl.yml +39 -0
  40. data/config/locales/pt-BR.yml +37 -0
  41. data/config/locales/pt.yml +37 -0
  42. data/config/locales/ro.yml +39 -0
  43. data/config/locales/ru.yml +39 -0
  44. data/config/locales/sv.yml +37 -0
  45. data/config/routes.rb +8 -0
  46. data/db/migrate/20081216193152_create_pages.rb +15 -0
  47. data/db/migrate/20090625125735_extend_pages.rb +28 -0
  48. data/db/migrate/20090814113100_add_visible_to_pages.rb +17 -0
  49. data/db/migrate/20090814142845_add_default_true_to_visible_for_page.rb +8 -0
  50. data/db/migrate/20090829000527_add_index_for_page.rb +10 -0
  51. data/db/migrate/20091219021134_add_meta_fields_to_pages.rb +9 -0
  52. data/db/migrate/20100204105222_add_layout_to_pages.rb +9 -0
  53. data/db/migrate/20100323085528_add_show_in_sidebar_option_to_pages.rb +9 -0
  54. data/db/migrate/20110717103112_add_meta_title_to_page.rb +9 -0
  55. data/db/migrate/20120723144115_add_render_as_partial_for_layout_for_spree_pages.rb +13 -0
  56. data/db/migrate/20140926121757_add_pages_stores.rb +14 -0
  57. data/lib/generators/solidus_static_content/install/install_generator.rb +24 -0
  58. data/lib/solidus_static_content.rb +21 -0
  59. data/lib/spree_static_content/engine.rb +17 -0
  60. data/solidus_static_content.gemspec +32 -0
  61. data/spec/controllers/static_content_controller_spec.rb +37 -0
  62. data/spec/factories/page_factory.rb +18 -0
  63. data/spec/features/admin/pages_spec.rb +67 -0
  64. data/spec/features/static_content_spec.rb +53 -0
  65. data/spec/helpers/page_helper_spec.rb +14 -0
  66. data/spec/lib/spree_static.content_spec.rb +34 -0
  67. data/spec/models/page_spec.rb +46 -0
  68. data/spec/spec_helper.rb +50 -0
  69. metadata +294 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4fb012c97e50d28d83c4efce564265f2fdb538f7
4
+ data.tar.gz: d159565b4f4ea4a7a883ce4378fa1a4b35f6d21f
5
+ SHA512:
6
+ metadata.gz: a814032d5eab0fab3c699c1169864a59c8d48a8438d21eaa1115d6064444adc59ca8c103990f81002cb638ddeb8b7f37b37652a7ba814e9b68cbd2b8f5f70af8
7
+ data.tar.gz: 3624ace3e06d964c27007cce8e50527c29e50e1ae7069fef94b10151538adb6e76614a3881a0c05d5b44a1e46b730637b402466797a4f27374787b42a244c2ba
@@ -0,0 +1,9 @@
1
+ .DS_Store
2
+ nbproject
3
+ **.gem
4
+ Gemfile.lock
5
+ spec/dummy/
6
+ .rvmrc
7
+ tmp
8
+ coverage
9
+ .bundle
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --format
3
+ progress
@@ -0,0 +1,21 @@
1
+ before_script:
2
+ - "bundle exec rake test_app"
3
+ script: "bundle exec rspec spec"
4
+ sudo: false
5
+ language: ruby
6
+ rvm:
7
+ - 2.3.1
8
+ env:
9
+ matrix:
10
+ - SOLIDUS_BRANCH=v1.1 DB=postgres
11
+ - SOLIDUS_BRANCH=v1.2 DB=postgres
12
+ - SOLIDUS_BRANCH=v1.3 DB=postgres
13
+ - SOLIDUS_BRANCH=v1.4 DB=postgres
14
+ - SOLIDUS_BRANCH=v2.0 DB=postgres
15
+ - SOLIDUS_BRANCH=master DB=postgres
16
+ - SOLIDUS_BRANCH=v1.1 DB=mysql
17
+ - SOLIDUS_BRANCH=v1.2 DB=mysql
18
+ - SOLIDUS_BRANCH=v1.3 DB=mysql
19
+ - SOLIDUS_BRANCH=v1.4 DB=mysql
20
+ - SOLIDUS_BRANCH=v2.0 DB=mysql
21
+ - SOLIDUS_BRANCH=master DB=mysql
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org/'
2
+
3
+ branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
4
+ gem 'solidus', github: 'solidusio/solidus', branch: branch
5
+
6
+ if branch == 'master' || branch >= "v2.0"
7
+ gem "rails-controller-testing", group: :test
8
+ end
9
+
10
+ gem 'pg'
11
+ gem 'mysql2'
12
+
13
+ gemspec
@@ -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
@@ -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.
@@ -0,0 +1,105 @@
1
+ # Solidus Static Content
2
+
3
+ [![Build Status](https://travis-ci.org/solidusio-contrib/solidus_static_content.svg)](https://travis-ci.org/solidusio-contrib/solidus_static_content)
4
+
5
+ A fork of the [Spree extension][1] for compatibility with [Solidus][7].
6
+
7
+ Good, clean content management of pages for Spree. You can use this to:
8
+
9
+ - Add and manage static pages such as an 'About' page.
10
+ - Show a static page instead of existing dynamic pages such as the home page,
11
+ products pages, and taxon pages.
12
+
13
+ ## Basic Installation
14
+
15
+ Add to your `Gemfile`:
16
+
17
+ ```ruby
18
+ gem 'solidus_static_content', github: 'solidusio-contrib/solidus_static_content'
19
+ ```
20
+
21
+ Run:
22
+
23
+ ```
24
+ $ bundle install
25
+ $ bundle exec rails g solidus_static_content:install
26
+ ```
27
+
28
+ That's all!
29
+
30
+
31
+ ## HowTo
32
+
33
+ Using the 'Pages' option in the admin tab, you can add static pages to your
34
+ Spree install. The page content can be pulled directly from the database, be a
35
+ separate layout file or rendered as a partial.
36
+
37
+ In the admin tab, use the 'New page' option to create a new static page.
38
+
39
+ The title, slug, body, and meta fields will replace their respective page
40
+ elements on load. The title, slug and body element are all required fields.
41
+
42
+ Body text provided without a layout / partial being specified will be loaded in
43
+ the spree_application layout after it is pulled from the database.
44
+
45
+
46
+ ### Layout and Partial Rendering
47
+
48
+ To render an entire page without the spree_application layout, specify a
49
+ relative path to the layout file (eg. `spree/layouts/layout_file_name`). This
50
+ file will not be prefixed with an underscore as it is a layout, not a partial.
51
+
52
+ To render a partial, specify the path in the layout file name and check the
53
+ 'Render layout as partial' option. The path specified in the layout area will
54
+ not have an underscore, but it will be required in the filename.
55
+
56
+ Also note the availability of the render_snippet helper which finds a page by
57
+ its slug and renders the raw page body anywhere in your view.
58
+
59
+ ### Options
60
+
61
+ Use the 'Show in' checkboxes to specify whether to display the page links in the
62
+ header, footer or sidebar. The position setting alters the order in which they
63
+ appear.
64
+
65
+ Finally, toggle the visibility using the 'Visible' checkbox. If it is unchecked,
66
+ the page will not be available.
67
+
68
+
69
+ ## Contributing
70
+
71
+ In the spirit of [free software][2], **everyone** is encouraged to help improve
72
+ this project.
73
+
74
+ Here are some ways *you* can contribute:
75
+
76
+ * by using prerelease versions
77
+ * by reporting [bugs][3]
78
+ * by suggesting new features
79
+ * by writing translations
80
+ * by writing or editing documentation
81
+ * by writing specifications
82
+ * by writing code (*no patch is too small*: fix typos, add comments, clean up inconsistent whitespace)
83
+ * by refactoring code
84
+ * by resolving [issues][3]
85
+ * by reviewing patches
86
+
87
+ Starting point:
88
+
89
+ * Fork the repo
90
+ * Clone your repo
91
+ * Run `bundle install`
92
+ * Run `bundle exec rake test_app` to create the test application in `spec/test_app`
93
+ * Make your changes
94
+ * Ensure specs pass by running `bundle exec rspec spec`
95
+ * Submit your pull request
96
+
97
+ Copyright (c) 2014 [Peter Berkenbosch][4] and [contributors][5], released under the [New BSD License][6]
98
+
99
+ [1]: https://github.com/spree-contrib/spree_static_content/
100
+ [2]: http://www.fsf.org/licensing/essays/free-sw.html
101
+ [3]: https://github.com/solidusio-contrib/solidus_static_content/issues
102
+ [4]: https://github.com/peterberkenbosch
103
+ [5]: https://github.com/solidusio-contrib/solidus_static_content/graphs/contributors
104
+ [6]: ./LICENSE.md
105
+ [7]: https://solidus.io/
@@ -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'] = 'solidus_static_content'
14
+ Rake::Task['common:test_app'].invoke
15
+ end
@@ -0,0 +1 @@
1
+ //= require spree/backend
@@ -0,0 +1 @@
1
+ //= require spree/frontend
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require spree/backend
3
+ */
@@ -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
+ }
@@ -0,0 +1,3 @@
1
+ class Spree::Admin::PagesController < Spree::Admin::ResourceController
2
+
3
+ end
@@ -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
@@ -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
@@ -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
@@ -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)
@@ -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)
@@ -0,0 +1,5 @@
1
+ Deface::Override.new(:virtual_path => "spree/admin/shared/_menu",
2
+ :name => "static_content_pages_admin_tab",
3
+ :insert_bottom => "[data-hook='admin_tabs']",
4
+ :text => "<%= tab(:pages, label: 'Pages', icon: 'file-text') %>",
5
+ :disabled => false)
@@ -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,0 +1,98 @@
1
+ <div data-hook="admin_page_form_fields">
2
+ <div class="left eight columns alpha" data-hook="admin_page_form_left">
3
+
4
+ <%= f.field_container :title do %>
5
+ <%= f.label :title %> <span class="required">*</span><br />
6
+ <%= f.text_field :title, :class => 'fullwidth title' %>
7
+ <%= f.error_message_on :title %>
8
+ <% end %>
9
+
10
+ <%= f.field_container :slug do %>
11
+ <%= f.label :slug %> <span class="required">*</span><br />
12
+ <%= f.text_field :slug, :class => 'fullwidth title' %>
13
+ <%= f.error_message_on :slug %>
14
+ <% end %>
15
+
16
+ <%= f.field_container :body do %>
17
+ <%= f.label :body %> <span class="required">*</span><br />
18
+ <%= f.text_area :body, {rows: 12, :class => 'fullwidth'} %>
19
+ <%= f.error_message_on :body %>
20
+ <% end %>
21
+
22
+ </div>
23
+ <div class="right four columns omega" data-hook="admin_page_form_right">
24
+
25
+ <%= f.field_container :layout do %>
26
+ <%= f.label :layout %><br />
27
+ <%= f.text_field :layout, :class => 'fullwidth title' %>
28
+ <% end %>
29
+
30
+ <%= f.field_container :foreign_link do %>
31
+ <%= f.label :foreign_link %><br />
32
+ <%= f.text_field :foreign_link, :class => 'fullwidth title' %>
33
+ <% end %>
34
+
35
+ <%= f.field_container :position do %>
36
+ <%= f.label :position %><br />
37
+ <%= f.number_field :position, :min => 0, :class => 'fullwidth title' %>
38
+ <% end %>
39
+
40
+ <%= f.field_container :show_in_sidebar do %>
41
+ <%= f.check_box :show_in_sidebar %>
42
+ <%= f.label :show_in_sidebar %>
43
+ <% end %>
44
+
45
+ <%= f.field_container :show_in_heade do %>
46
+ <%= f.check_box :show_in_header %>
47
+ <%= f.label :show_in_header %>
48
+ <% end %>
49
+
50
+ <%= f.field_container :show_in_footer do %>
51
+ <%= f.check_box :show_in_footer %>
52
+ <%= f.label :show_in_footer %>
53
+ <% end %>
54
+
55
+ <%= f.field_container :visible do %>
56
+ <%= f.check_box :visible %>
57
+ <%= f.label :visible %>
58
+ <% end %>
59
+
60
+ <%= f.field_container :render_layout_as_partial do %>
61
+ <%= f.check_box :render_layout_as_partial %>
62
+ <%= f.label :render_layout_as_partial %>
63
+ <% end %>
64
+
65
+ <%= f.field_container :stores do %>
66
+ <%= f.label :stores, Spree.t(:stores)%><br />
67
+ <% Spree::Store.all.each do |store| %>
68
+ <%= check_box_tag "page[store_ids][]", store.id, @page.stores.include?(store) %> <%= store.name %>
69
+ <% end %>
70
+ <% end %>
71
+
72
+ </div>
73
+
74
+ <div data-hook="admin_page_form_meta" class="alpha omega twelve columns">
75
+
76
+ <%= f.field_container :meta_title do %>
77
+ <%= f.label :meta_title %><br />
78
+ <%= f.text_field :meta_title, :class => 'fullwidth title' %>
79
+ <%= f.error_message_on :meta_title %>
80
+ <% end %>
81
+
82
+ <%= f.field_container :meta_keywords do %>
83
+ <%= f.label :meta_keywords %><br />
84
+ <%= f.text_field :meta_keywords, :class => 'fullwidth title' %>
85
+ <%= f.error_message_on :meta_keywords %>
86
+ <% end %>
87
+
88
+ <%= f.field_container :meta_description do %>
89
+ <%= f.label :meta_description %><br />
90
+ <%= f.text_field :meta_description, :class => 'fullwidth title' %>
91
+ <%= f.error_message_on :meta_description %>
92
+ <% end %>
93
+
94
+ </div>
95
+ <div class="clear"></div>
96
+ <div data-hook="admin_page_form_additional_fields"></div>
97
+ <div class="clear"></div>
98
+ </div>