solidus_static_content 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +35 -0
  3. data/.gem_release.yml +5 -0
  4. data/.gitignore +17 -6
  5. data/.rspec +2 -3
  6. data/.rubocop.yml +2 -0
  7. data/CHANGELOG.md +80 -0
  8. data/Gemfile +26 -6
  9. data/{LICENSE.md → LICENSE} +0 -0
  10. data/README.md +81 -68
  11. data/Rakefile +4 -13
  12. data/app/assets/stylesheets/spree/frontend/solidus_static_content.css +7 -0
  13. data/app/assets/stylesheets/spree/frontend/spree_static_content.css +2 -7
  14. data/app/models/solidus_static_content/permission_sets/page_display.rb +11 -0
  15. data/app/models/solidus_static_content/permission_sets/page_management.rb +11 -0
  16. data/app/models/spree/page.rb +16 -21
  17. data/bin/console +17 -0
  18. data/bin/r +8 -0
  19. data/bin/rails +6 -6
  20. data/bin/rails-engine +13 -0
  21. data/bin/rails-sandbox +16 -0
  22. data/bin/rake +7 -0
  23. data/bin/sandbox +84 -0
  24. data/bin/sandbox_rails +8 -0
  25. data/bin/setup +8 -0
  26. data/config/locales/de.yml +7 -5
  27. data/config/locales/en.yml +9 -7
  28. data/config/locales/es-MX.yml +38 -0
  29. data/config/locales/es.yml +6 -5
  30. data/config/locales/et.yml +6 -5
  31. data/config/locales/fr.yml +7 -5
  32. data/config/locales/it.yml +6 -5
  33. data/config/locales/nl.yml +7 -5
  34. data/config/locales/pl.yml +6 -5
  35. data/config/locales/pt-BR.yml +6 -5
  36. data/config/locales/pt.yml +7 -5
  37. data/config/locales/ro.yml +11 -9
  38. data/config/locales/ru.yml +7 -5
  39. data/config/locales/sv.yml +7 -5
  40. data/config/routes.rb +9 -2
  41. data/db/migrate/20081216193152_create_pages.rb +1 -1
  42. data/db/migrate/20090625125735_extend_pages.rb +1 -1
  43. data/db/migrate/20090814113100_add_visible_to_pages.rb +1 -1
  44. data/db/migrate/20090814142845_add_default_true_to_visible_for_page.rb +1 -1
  45. data/db/migrate/20090829000527_add_index_for_page.rb +1 -1
  46. data/db/migrate/20091219021134_add_meta_fields_to_pages.rb +1 -1
  47. data/db/migrate/20100204105222_add_layout_to_pages.rb +1 -1
  48. data/db/migrate/20100323085528_add_show_in_sidebar_option_to_pages.rb +1 -1
  49. data/db/migrate/20110717103112_add_meta_title_to_page.rb +1 -1
  50. data/db/migrate/20120723144115_add_render_as_partial_for_layout_for_spree_pages.rb +1 -1
  51. data/db/migrate/20140926121757_add_pages_stores.rb +1 -1
  52. data/db/migrate/20180305193240_update_spree_page_position.rb +13 -0
  53. data/lib/controllers/backend/spree/admin/pages_controller.rb +16 -0
  54. data/{app/controllers → lib/controllers/frontend}/spree/static_content_controller.rb +7 -3
  55. data/lib/generators/solidus_static_content/install/install_generator.rb +7 -5
  56. data/lib/solidus_static_content.rb +6 -18
  57. data/lib/solidus_static_content/engine.rb +35 -0
  58. data/lib/solidus_static_content/factories.rb +18 -0
  59. data/lib/solidus_static_content/route_matcher.rb +11 -0
  60. data/lib/solidus_static_content/version.rb +5 -0
  61. data/lib/views/backend/spree/admin/pages/_form.html.erb +119 -0
  62. data/lib/views/backend/spree/admin/pages/edit.html.erb +32 -0
  63. data/lib/views/backend/spree/admin/pages/index.html.erb +68 -0
  64. data/lib/views/backend/spree/admin/pages/new.html.erb +31 -0
  65. data/lib/views/backend/spree/admin/shared/_pages_tabs.html.erb +9 -0
  66. data/{app/views → lib/views/frontend}/spree/static_content/_static_content_footer.html.erb +0 -0
  67. data/{app/views → lib/views/frontend}/spree/static_content/_static_content_header.html.erb +0 -0
  68. data/{app/views → lib/views/frontend}/spree/static_content/_static_content_list.html.erb +0 -0
  69. data/{app/views → lib/views/frontend}/spree/static_content/_static_content_sidebar.html.erb +1 -1
  70. data/lib/views/frontend/spree/static_content/show.html.erb +18 -0
  71. data/solidus_static_content.gemspec +36 -31
  72. data/spec/controllers/spree/admin/pages_controller_spec.rb +11 -0
  73. data/spec/controllers/{static_content_controller_spec.rb → spree/static_content_controller_spec.rb} +9 -12
  74. data/spec/features/{admin → spree/admin}/pages_spec.rb +8 -5
  75. data/spec/features/{static_content_spec.rb → spree/static_content_spec.rb} +6 -4
  76. data/spec/helpers/{page_helper_spec.rb → spree/page_helper_spec.rb} +0 -0
  77. data/spec/lib/solidus_static_content/engine_spec.rb +14 -0
  78. data/spec/lib/{spree_static.content_spec.rb → solidus_static_content/route_matcher_spec.rb} +4 -13
  79. data/spec/models/{page_spec.rb → spree/page_spec.rb} +22 -7
  80. data/spec/spec_helper.rb +17 -40
  81. metadata +85 -177
  82. data/.travis.yml +0 -21
  83. data/app/assets/javascripts/spree/backend/spree_static_content.js +0 -1
  84. data/app/assets/javascripts/spree/frontend/spree_static_content.js +0 -1
  85. data/app/assets/stylesheets/spree/backend/spree_static_content.css +0 -3
  86. data/app/controllers/spree/admin/pages_controller.rb +0 -3
  87. data/app/overrides/pages_in_menu.rb +0 -5
  88. data/app/views/spree/admin/pages/_form.html.erb +0 -98
  89. data/app/views/spree/admin/pages/edit.html.erb +0 -18
  90. data/app/views/spree/admin/pages/index.html.erb +0 -51
  91. data/app/views/spree/admin/pages/new.html.erb +0 -18
  92. data/app/views/spree/static_content/show.html.erb +0 -26
  93. data/lib/spree_static_content/engine.rb +0 -17
  94. data/spec/factories/page_factory.rb +0 -18
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusStaticContent
4
+ module PermissionSets
5
+ class PageManagement < Spree::PermissionSets::Base
6
+ def activate!
7
+ can :manage, Spree::Page
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,54 +1,49 @@
1
1
  class Spree::Page < ActiveRecord::Base
2
+ acts_as_list
2
3
  default_scope -> { order("position ASC") }
3
4
 
4
- has_and_belongs_to_many :stores, :join_table => 'spree_pages_stores'
5
+ has_and_belongs_to_many :stores, join_table: 'spree_pages_stores'
5
6
 
6
7
  validates_presence_of :title
7
8
  validates_presence_of [:slug, :body], :if => :not_using_foreign_link?
8
9
  validates_presence_of :layout, :if => :render_layout_as_partial?
10
+ validates_presence_of :stores
9
11
 
10
12
  validates :slug, :uniqueness => true, :if => :not_using_foreign_link?
11
13
  validates :foreign_link, :uniqueness => true, :allow_blank => true
12
14
 
15
+ before_validation :generate_slug, if: :title?
16
+
13
17
  scope :visible, -> { where(:visible => true) }
14
18
  scope :header_links, -> { where(:show_in_header => true).visible }
15
19
  scope :footer_links, -> { where(:show_in_footer => true).visible }
16
20
  scope :sidebar_links, -> { where(:show_in_sidebar => true).visible }
21
+ scope :ordered_by_position, -> { order(:position) }
17
22
 
18
23
  scope :by_store, lambda { |store| joins(:stores).where("spree_pages_stores.store_id = ?", store) }
19
24
 
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
25
+ before_save :normalize_slug
28
26
 
29
27
  def link
30
28
  foreign_link.blank? ? slug : foreign_link
31
29
  end
32
30
 
31
+ def meta_title
32
+ super.presence || title
33
+ end
34
+
33
35
  private
34
36
 
35
- def update_positions_and_slug
37
+ def normalize_slug
36
38
  # ensure that all slugs start with a slash
37
39
  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
40
  end
50
41
 
51
42
  def not_using_foreign_link?
52
43
  foreign_link.blank?
53
44
  end
45
+
46
+ def generate_slug
47
+ self.slug ||= title.parameterize
48
+ end
54
49
  end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require "bundler/setup"
6
+ require "solidus_static_content"
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+ $LOAD_PATH.unshift(*Dir["#{__dir__}/../app/*"])
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ # require "pry"
14
+ # Pry.start
15
+
16
+ require "irb"
17
+ IRB.start(__FILE__)
data/bin/r ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ warn %{
4
+ DEPRECATION: bin/r has been replaced by bin/rails-engine, please use that
5
+ command instead.
6
+ }.strip
7
+
8
+ exec "#{__dir__}/rails-engine"
data/bin/rails CHANGED
@@ -1,7 +1,7 @@
1
- # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
1
+ #!/usr/bin/env ruby
2
2
 
3
- ENGINE_ROOT = File.expand_path('../..', __FILE__)
4
- ENGINE_PATH = File.expand_path('../../lib/spree_static_content/engine', __FILE__)
5
-
6
- require 'rails/all'
7
- require 'rails/engine/commands'
3
+ if %w[g generate].include? ARGV.first
4
+ exec "#{__dir__}/rails-engine", *ARGV
5
+ else
6
+ exec "#{__dir__}/rails-sandbox", *ARGV
7
+ end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('..', __dir__)
6
+ ENGINE_PATH = File.expand_path('../lib/solidus_static_content/engine', __dir__)
7
+
8
+ # Set up gems listed in the Gemfile.
9
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
10
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
11
+
12
+ require 'rails/all'
13
+ require 'rails/engine/commands'
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ app_root = 'sandbox'
4
+
5
+ unless File.exist? "#{app_root}/bin/rails"
6
+ warn 'Creating the sandbox app...'
7
+ Dir.chdir "#{__dir__}/.." do
8
+ system "#{__dir__}/sandbox" or begin # rubocop:disable Style/AndOr
9
+ warn 'Automatic creation of the sandbox app failed'
10
+ exit 1
11
+ end
12
+ end
13
+ end
14
+
15
+ Dir.chdir app_root
16
+ exec 'bin/rails', *ARGV
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "rubygems"
5
+ require "bundler/setup"
6
+
7
+ load Gem.bin_path("rake", "rake")
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ case "$DB" in
6
+ postgres|postgresql)
7
+ RAILSDB="postgresql"
8
+ ;;
9
+ mysql)
10
+ RAILSDB="mysql"
11
+ ;;
12
+ sqlite|'')
13
+ RAILSDB="sqlite3"
14
+ ;;
15
+ *)
16
+ echo "Invalid DB specified: $DB"
17
+ exit 1
18
+ ;;
19
+ esac
20
+
21
+ if [ ! -z $SOLIDUS_BRANCH ]
22
+ then
23
+ BRANCH=$SOLIDUS_BRANCH
24
+ else
25
+ BRANCH="master"
26
+ fi
27
+
28
+ extension_name="solidus_static_content"
29
+
30
+ # Stay away from the bundler env of the containing extension.
31
+ function unbundled {
32
+ ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- $@
33
+ }
34
+
35
+ rm -rf ./sandbox
36
+ unbundled bundle exec rails new sandbox --database="$RAILSDB" \
37
+ --skip-bundle \
38
+ --skip-git \
39
+ --skip-keeps \
40
+ --skip-rc \
41
+ --skip-spring \
42
+ --skip-test \
43
+ --skip-javascript
44
+
45
+ if [ ! -d "sandbox" ]; then
46
+ echo 'sandbox rails application failed'
47
+ exit 1
48
+ fi
49
+
50
+ cd ./sandbox
51
+ cat <<RUBY >> Gemfile
52
+ gem 'solidus', github: 'solidusio/solidus', branch: '$BRANCH'
53
+ gem 'solidus_auth_devise', '>= 2.1.0'
54
+ gem 'rails-i18n'
55
+ gem 'solidus_i18n'
56
+
57
+ gem '$extension_name', path: '..'
58
+
59
+ group :test, :development do
60
+ platforms :mri do
61
+ gem 'pry-byebug'
62
+ end
63
+ end
64
+ RUBY
65
+
66
+ unbundled bundle install --gemfile Gemfile
67
+
68
+ unbundled bundle exec rake db:drop db:create
69
+
70
+ unbundled bundle exec rails generate spree:install \
71
+ --auto-accept \
72
+ --user_class=Spree::User \
73
+ --enforce_available_locales=true \
74
+ --with-authentication=false \
75
+ $@
76
+
77
+ unbundled bundle exec rails generate solidus:auth:install
78
+
79
+ echo
80
+ echo "🚀 Sandbox app successfully created for $extension_name!"
81
+ echo "🚀 Using $RAILSDB and Solidus $BRANCH"
82
+ echo "🚀 Use 'export DB=[postgres|mysql|sqlite]' to control the DB adapter"
83
+ echo "🚀 Use 'export SOLIDUS_BRANCH=<BRANCH-NAME>' to control the Solidus version"
84
+ echo "🚀 This app is intended for test purposes."
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ warn %{
4
+ DEPRECATION: bin/sandbox_rails has been replaced by bin/rails-sandbox, please
5
+ use that command instead.
6
+ }.strip
7
+
8
+ exec "#{__dir__}/rails-sandbox"
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ gem install bundler --conservative
7
+ bundle update
8
+ bin/rake clobber
@@ -30,8 +30,10 @@ de:
30
30
  back_to_static_pages_list: "Zurück zu den statischen Seiten Liste"
31
31
  page: Seite
32
32
  pages: Seiten
33
- static_content:
34
- static_pages: Statische Seiten
35
- new_page: Neue Seite
36
- editing_page: Seite bearbeiten
37
- link: Link
33
+ stores: Shops
34
+ static_pages: Statische Seiten
35
+ new_page: Neue Seite
36
+ editing_page: Seite bearbeiten
37
+ link: Link
38
+ add_one: Erstelle einen
39
+
@@ -24,14 +24,16 @@ en:
24
24
  one: Page
25
25
  other: Pages
26
26
  spree:
27
+ stores: Stores
27
28
  admin:
28
29
  tab:
29
- Pages: Pages
30
- back_to_static_pages_list: "Back to static pages list"
30
+ pages: Pages
31
+ back_to_pages: "Back to static pages list"
31
32
  page: Page
32
33
  pages: Pages
33
- static_content:
34
- static_pages: Static pages
35
- new_page: New page
36
- editing_page: Editing page
37
- link: Link
34
+ stores: Stores
35
+ static_pages: Static pages
36
+ new_page: New page
37
+ editing_page: Editing page
38
+ link: Link
39
+ add_one: Create One
@@ -0,0 +1,38 @@
1
+ ---
2
+ es-MX:
3
+ activerecord:
4
+ attributes:
5
+ spree/page:
6
+ body: Cuerpo
7
+ foreign_link: Enlace externo (URL)
8
+ show_in_header: Mostrar en la cabecera
9
+ show_in_footer: Mostrar en el pie de página
10
+ layout: Disposición
11
+ meta_description: "Meta Descripción"
12
+ meta_keywords: "Meta Palabras"
13
+ meta_title: "Meta Título"
14
+ position: Posición
15
+ render_layout_as_partial: "Renderizar disposición como parciales"
16
+ show_in_sidebar: "Mostrar en el barra lateral"
17
+ slug: Slug
18
+ title: Título
19
+ visible: Visible
20
+ models:
21
+ spree/page:
22
+ few: Páginas
23
+ many: Páginas
24
+ one: Página
25
+ other: Páginas
26
+ spree:
27
+ admin:
28
+ tab:
29
+ pages: Páginas
30
+ back_to_static_pages_list: "Volver a la lista de páginas estáticas"
31
+ page: Página
32
+ pages: Páginas
33
+ stores: Tiendas
34
+ static_pages: "Páginas estáticas"
35
+ new_page: "Nueva página"
36
+ editing_page: "Edición de página"
37
+ link: Enlace
38
+ add_one: Crea uno
@@ -30,8 +30,9 @@ es:
30
30
  back_to_static_pages_list: "Volver a la lista de páginas estáticas"
31
31
  page: Página
32
32
  pages: Páginas
33
- static_content:
34
- static_pages: "Páginas estáticas"
35
- new_page: "Nueva página"
36
- editing_page: "Edición de página"
37
- link: Enlace
33
+ stores: Tiendas
34
+ static_pages: "Páginas estáticas"
35
+ new_page: "Nueva página"
36
+ editing_page: "Edición de página"
37
+ link: Enlace
38
+ add_one: Crea uno
@@ -30,8 +30,9 @@ et:
30
30
  back_to_static_pages_list: "Tagasi staatiliste lehtede nimekiri"
31
31
  page: Lehekülg
32
32
  pages: Leheküljed
33
- static_content:
34
- static_pages: Leheküljed
35
- new_page: Uus lehekülg
36
- editing_page: Muudan lehekülge
37
- link: Link
33
+ stores: Kauplustes
34
+ static_pages: Leheküljed
35
+ new_page: Uus lehekülg
36
+ editing_page: Muudan lehekülge
37
+ link: Link
38
+ add_one: Loo see
@@ -30,8 +30,10 @@ fr:
30
30
  back_to_static_pages_list: "Retour à la liste des pages statiques"
31
31
  page: Page
32
32
  pages: Pages
33
- static_content:
34
- editing_page: "Edition de la page"
35
- link: Lien
36
- new_page: "Nouvelle page"
37
- static_pages: "Pages statiques"
33
+ stores: Magasins
34
+ editing_page: "Edition de la page"
35
+ link: Lien
36
+ new_page: "Nouvelle page"
37
+ static_pages: "Pages statiques"
38
+ add_one: "Créer une"
39
+
@@ -30,8 +30,9 @@ it:
30
30
  back_to_static_pages_list: Torna alla lista delle pagine statiche
31
31
  page: Pagina
32
32
  pages: Pagine
33
- static_content:
34
- static_pages: Pagine statiche
35
- new_page: Nuova pagina
36
- editing_page: Modifica pagina
37
- link: Link
33
+ stores: I negozi
34
+ static_pages: Pagine statiche
35
+ new_page: Nuova pagina
36
+ editing_page: Modifica pagina
37
+ link: Link
38
+ add_one: Crearne uno
@@ -30,8 +30,10 @@ nl:
30
30
  back_to_static_pages_list: "Terug naar statische pagina's"
31
31
  page: Page
32
32
  pages: "Statische pagina's"
33
- static_content:
34
- editing_page: "Pagina bewerken"
35
- link: Link
36
- new_page: "Nieuwe pagina"
37
- static_pages: "Statische pagina's"
33
+ stores: Winkel
34
+ editing_page: "Pagina bewerken"
35
+ link: Link
36
+ new_page: "Nieuwe pagina"
37
+ static_pages: "Statische pagina's"
38
+ add_one: "Creëer er een"
39
+
@@ -32,8 +32,9 @@ pl:
32
32
  back_to_static_pages_list: "Powrót do listy stron statycznych"
33
33
  page: Strona
34
34
  pages: "Strony statyczne"
35
- static_content:
36
- editing_page: "Edycja strony"
37
- link: Odnośnik
38
- new_page: "Nowa strona"
39
- static_pages: "Strony statyczne"
35
+ stores: Sklepy
36
+ editing_page: "Edycja strony"
37
+ link: Odnośnik
38
+ new_page: "Nowa strona"
39
+ static_pages: "Strony statyczne"
40
+ add_one: "Stworzyć jeden"