workarea-swatches 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +20 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  4. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.gitignore +21 -0
  7. data/CHANGELOG.md +121 -0
  8. data/CODE_OF_CONDUCT.md +3 -0
  9. data/CONTRIBUTING.md +3 -0
  10. data/Gemfile +17 -0
  11. data/LICENSE +52 -0
  12. data/README.md +40 -0
  13. data/Rakefile +60 -0
  14. data/app/assets/javascripts/workarea/storefront/swatches/modules/product_summary_swatches.js +63 -0
  15. data/app/assets/stylesheets/workarea/storefront/swatches/components/_option_button.scss +17 -0
  16. data/app/assets/stylesheets/workarea/storefront/swatches/components/_swatch_facet.scss +25 -0
  17. data/app/assets/stylesheets/workarea/storefront/swatches/components/_swatch_options.scss +54 -0
  18. data/app/controllers/workarea/admin/catalog_product_swatches_controller.rb +47 -0
  19. data/app/controllers/workarea/admin/catalog_swatches_controller.rb +48 -0
  20. data/app/controllers/workarea/storefront/products_controller.decorator +12 -0
  21. data/app/helpers/workarea/storefront/swatches_helper.rb +84 -0
  22. data/app/models/workarea/catalog/product.decorator +7 -0
  23. data/app/models/workarea/catalog/product_swatch.rb +10 -0
  24. data/app/models/workarea/catalog/swatch.rb +37 -0
  25. data/app/models/workarea/search/settings.decorator +8 -0
  26. data/app/queries/workarea/search/category_browse.decorator +7 -0
  27. data/app/queries/workarea/search/product_search.decorator +7 -0
  28. data/app/queries/workarea/search/swatched_facets.rb +19 -0
  29. data/app/queries/workarea/search/swatches_facet.rb +13 -0
  30. data/app/seeds/workarea/swatches_seeds.rb +37 -0
  31. data/app/view_models/workarea/storefront/product_templates/swatches_view_model.rb +57 -0
  32. data/app/views/workarea/admin/activities/_catalog_product_swatch_create.html.haml +10 -0
  33. data/app/views/workarea/admin/activities/_catalog_product_swatch_destroy.html.haml +10 -0
  34. data/app/views/workarea/admin/activities/_catalog_swatch_create.html.haml +12 -0
  35. data/app/views/workarea/admin/activities/_catalog_swatch_destroy.html.haml +10 -0
  36. data/app/views/workarea/admin/catalog_product_swatches/edit.html.haml +52 -0
  37. data/app/views/workarea/admin/catalog_product_swatches/index.html.haml +65 -0
  38. data/app/views/workarea/admin/catalog_products/_swatches_card.html.haml +27 -0
  39. data/app/views/workarea/admin/catalog_swatches/_primary_navigation.html.haml +1 -0
  40. data/app/views/workarea/admin/catalog_swatches/index.html.haml +78 -0
  41. data/app/views/workarea/api/storefront/facets/_swatches.json.jbuilder +17 -0
  42. data/app/views/workarea/storefront/facets/_swatches.html.haml +14 -0
  43. data/app/views/workarea/storefront/products/_swatch_summary.html.haml +17 -0
  44. data/app/views/workarea/storefront/products/templates/_swatches.html.haml +79 -0
  45. data/bin/rails +19 -0
  46. data/config/initializers/dragonfly.rb +11 -0
  47. data/config/initializers/workarea.rb +40 -0
  48. data/config/locales/en.yml +52 -0
  49. data/config/routes.rb +15 -0
  50. data/lib/tasks/swatches_tasks.rake +4 -0
  51. data/lib/workarea/swatches.rb +11 -0
  52. data/lib/workarea/swatches/engine.rb +12 -0
  53. data/lib/workarea/swatches/version.rb +5 -0
  54. data/test/dummy/Rakefile +6 -0
  55. data/test/dummy/app/assets/config/manifest.js +4 -0
  56. data/test/dummy/app/assets/javascripts/application.js +13 -0
  57. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  58. data/test/dummy/app/controllers/application_controller.rb +3 -0
  59. data/test/dummy/app/helpers/application_helper.rb +2 -0
  60. data/test/dummy/app/jobs/application_job.rb +2 -0
  61. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  62. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  63. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  64. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  65. data/test/dummy/bin/bundle +3 -0
  66. data/test/dummy/bin/rails +4 -0
  67. data/test/dummy/bin/rake +4 -0
  68. data/test/dummy/bin/setup +30 -0
  69. data/test/dummy/bin/update +26 -0
  70. data/test/dummy/bin/yarn +11 -0
  71. data/test/dummy/config.ru +5 -0
  72. data/test/dummy/config/application.rb +30 -0
  73. data/test/dummy/config/boot.rb +5 -0
  74. data/test/dummy/config/cable.yml +10 -0
  75. data/test/dummy/config/environment.rb +5 -0
  76. data/test/dummy/config/environments/development.rb +51 -0
  77. data/test/dummy/config/environments/production.rb +88 -0
  78. data/test/dummy/config/environments/test.rb +44 -0
  79. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  80. data/test/dummy/config/initializers/assets.rb +14 -0
  81. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  82. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  83. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  84. data/test/dummy/config/initializers/inflections.rb +16 -0
  85. data/test/dummy/config/initializers/mime_types.rb +4 -0
  86. data/test/dummy/config/initializers/workarea.rb +5 -0
  87. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  88. data/test/dummy/config/locales/en.yml +33 -0
  89. data/test/dummy/config/puma.rb +56 -0
  90. data/test/dummy/config/routes.rb +5 -0
  91. data/test/dummy/config/secrets.yml +32 -0
  92. data/test/dummy/config/spring.rb +6 -0
  93. data/test/dummy/db/seeds.rb +2 -0
  94. data/test/dummy/log/.keep +0 -0
  95. data/test/factories/workarea/swatches.rb +14 -0
  96. data/test/integration/workarea/admin/product_swatches_integration_test.rb +43 -0
  97. data/test/integration/workarea/admin/swatches_integration_test.rb +37 -0
  98. data/test/integration/workarea/storefront/swatches_integration_test.rb +72 -0
  99. data/test/system/workarea/admin/swatches_system_test.rb +58 -0
  100. data/test/system/workarea/storefront/browse_swatches_system_test.rb +50 -0
  101. data/test/system/workarea/storefront/swatches_system_test.rb +101 -0
  102. data/test/teaspoon_env.rb +6 -0
  103. data/test/test_helper.rb +10 -0
  104. data/test/view_models/workarea/storefront/product_templates/swatches_view_model_test.rb +74 -0
  105. data/workarea-swatches.gemspec +19 -0
  106. metadata +147 -0
data/bin/rails ADDED
@@ -0,0 +1,19 @@
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('../..', __FILE__)
6
+ ENGINE_PATH = File.expand_path('../../lib/workarea/swatches/engine', __FILE__)
7
+ APP_PATH = File.expand_path('../../test/dummy/config/application', __FILE__)
8
+
9
+ # Set up gems listed in the Gemfile.
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
11
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
12
+
13
+ require 'action_controller/railtie'
14
+ require 'action_view/railtie'
15
+ require 'action_mailer/railtie'
16
+ require 'rails/test_unit/railtie'
17
+ require 'sprockets/railtie'
18
+ require 'teaspoon-mocha'
19
+ require 'rails/engine/commands'
@@ -0,0 +1,11 @@
1
+ processors = Dragonfly.app(:workarea).processors.names
2
+
3
+ Dragonfly.app(:workarea).configure do
4
+ unless processors.include?(:facet_swatch)
5
+ processor :facet_swatch do |content|
6
+ content.process!(:encode, :jpg, Workarea.config.jpg_encode_options)
7
+ content.process!(:thumb, '20x')
8
+ content.process!(:optim)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+ Workarea.configure do |config|
2
+ config.product_templates << :swatches
3
+
4
+ config.seeds.insert_after(
5
+ 'Workarea::ProductsSeeds',
6
+ 'Workarea::SwatchesSeeds'
7
+ )
8
+
9
+ # Determines which option is used for displaying swatches on
10
+ # browse pages. Return the option you would like to be used. We pass the
11
+ # product in case there are other factors to base sorting on.
12
+ config.browse_swatch_option = ->(product, options) { options.first }
13
+ end
14
+
15
+ Workarea.append_partials(
16
+ 'admin.catalog_menu',
17
+ 'workarea/admin/catalog_swatches/primary_navigation'
18
+ )
19
+
20
+ Workarea.append_partials(
21
+ 'admin.catalog_product_cards',
22
+ 'workarea/admin/catalog_products/swatches_card'
23
+ )
24
+
25
+ Workarea::Plugin.append_stylesheets(
26
+ 'storefront.components',
27
+ 'workarea/storefront/swatches/components/option_button',
28
+ 'workarea/storefront/swatches/components/swatch_facet',
29
+ 'workarea/storefront/swatches/components/swatch_options'
30
+ )
31
+
32
+ Workarea::Plugin.append_javascripts(
33
+ 'storefront.modules',
34
+ 'workarea/storefront/swatches/modules/product_summary_swatches'
35
+ )
36
+
37
+ Workarea.append_partials(
38
+ 'storefront.product_summary',
39
+ 'workarea/storefront/products/swatch_summary'
40
+ )
@@ -0,0 +1,52 @@
1
+ en:
2
+ workarea:
3
+ admin:
4
+ activities:
5
+ catalog_product_swatch_create_html: added a swatch to %{name}
6
+ catalog_product_swatch_destroy_html: removed a swatch from %{name}
7
+ catalog_category_create_html: created the %{name} swatch
8
+ catalog_category_destroy_html: removed the %{name} swatch
9
+ fields:
10
+ color: Color
11
+ catalog_product_swatches:
12
+ edit:
13
+ edit_swatch_for: Edit swatch for %{product}
14
+ edit_swatch: Edit Swatch
15
+ swatch: Swatch
16
+ without_options: Without options
17
+ flash_messages:
18
+ saved: Your swatch has been saved
19
+ removed: Your swatch has been removed
20
+ error: There was an error saving your changes
21
+ index:
22
+ add_new_swatch: Add New Swatch
23
+ create_swatch: Create Swatch
24
+ delete_confirmation: Are you sure you want to delete this swatch?
25
+ no_product_swatches: No product swatches
26
+ product_swatches: Product Swatches
27
+ swatch: Swatch
28
+ swatches_for: Swatches for %{product}
29
+ swatches: Swatches
30
+ without_options: Without options
31
+ catalog_products:
32
+ cards:
33
+ swatches:
34
+ add_swatches: Add Swatches
35
+ description: Override or add custom swatches for this product to show on the swatches detail page template.
36
+ manage_swatches: Manage Swatches
37
+ title: Swatches
38
+ catalog_swatches:
39
+ flash_messages:
40
+ saved: Your swatch has been saved
41
+ removed: Your swatch has been removed
42
+ error: There was an error saving your changes
43
+ index:
44
+ page_title: Swatches
45
+ description: Swatches are used by the swatches product template and can be setup as filters for categories and search.
46
+ no_swatches: No swatches setup yet, add one below!
47
+ add_new: Add New
48
+ manage_filters: Manage Filters
49
+ swatch_filters: Swatch Filters
50
+ swatch_facets_info: Filters in this list will will show their values with swatches when displayed on category browse pages and search results.
51
+ primary_navigation:
52
+ swatches: Swatches
data/config/routes.rb ADDED
@@ -0,0 +1,15 @@
1
+ Workarea::Admin::Engine.routes.draw do
2
+ resources :catalog_swatches, except: [:new, :show, :edit]
3
+
4
+ resources :catalog_products, only: [] do
5
+ resources :swatches,
6
+ except: [:new, :show, :edit],
7
+ controller: 'catalog_product_swatches'
8
+ end
9
+ end
10
+
11
+ Workarea::Storefront::Engine.routes.draw do
12
+ resources :products, only: [] do
13
+ member { get 'summary' }
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :swatches do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,11 @@
1
+ require 'workarea'
2
+ require 'workarea/storefront'
3
+ require 'workarea/admin'
4
+
5
+ require 'workarea/swatches/engine'
6
+ require 'workarea/swatches/version'
7
+
8
+ module Workarea
9
+ module Swatches
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module Workarea
2
+ module Swatches
3
+ class Engine < ::Rails::Engine
4
+ include Workarea::Plugin
5
+ isolate_namespace Workarea::Swatches
6
+
7
+ config.to_prepare do
8
+ Storefront::ApplicationController.helper(Storefront::SwatchesHelper)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Workarea
2
+ module Swatches
3
+ VERSION = '1.0.5'.freeze
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,4 @@
1
+
2
+ //= link_tree ../images
3
+ //= link_directory ../javascripts .js
4
+ //= link_directory ../stylesheets .css
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery with: :exception
3
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationJob < ActiveJob::Base
2
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ layout 'mailer'
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= csrf_meta_tags %>
6
+
7
+ <%= stylesheet_link_tag 'application', media: 'all' %>
8
+ <%= javascript_include_tag 'application' %>
9
+ </head>
10
+
11
+ <body>
12
+ <%= yield %>
13
+ </body>
14
+ </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ include FileUtils
5
+
6
+ # path to your application root.
7
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8
+
9
+ def system!(*args)
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
14
+ # This script is a starting point to setup your application.
15
+ # Add necessary setup steps to this file.
16
+
17
+ puts '== Installing dependencies =='
18
+ system! 'gem install bundler --conservative'
19
+ system('bundle check') || system!('bundle install')
20
+
21
+ # Install JavaScript dependencies if using Yarn
22
+ # system('bin/yarn')
23
+
24
+
25
+ puts "\n== Removing old logs and tempfiles =="
26
+ system! 'bin/rails log:clear tmp:clear'
27
+
28
+ puts "\n== Restarting application server =="
29
+ system! 'bin/rails restart'
30
+ end
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ include FileUtils
5
+
6
+ # path to your application root.
7
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8
+
9
+ def system!(*args)
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
14
+ # This script is a way to update your development environment automatically.
15
+ # Add necessary update steps to this file.
16
+
17
+ puts '== Installing dependencies =='
18
+ system! 'gem install bundler --conservative'
19
+ system('bundle check') || system!('bundle install')
20
+
21
+ puts "\n== Removing old logs and tempfiles =="
22
+ system! 'bin/rails log:clear tmp:clear'
23
+
24
+ puts "\n== Restarting application server =="
25
+ system! 'bin/rails restart'
26
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ VENDOR_PATH = File.expand_path('..', __dir__)
3
+ Dir.chdir(VENDOR_PATH) do
4
+ begin
5
+ exec "yarnpkg #{ARGV.join(" ")}"
6
+ rescue Errno::ENOENT
7
+ $stderr.puts 'Yarn executable was not detected in the system.'
8
+ $stderr.puts 'Download Yarn at https://yarnpkg.com/en/docs/install'
9
+ exit 1
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require_relative 'config/environment'
4
+
5
+ run Rails.application
@@ -0,0 +1,30 @@
1
+ require_relative 'boot'
2
+
3
+ # Pick the frameworks you want:
4
+ # require "active_record/railtie"
5
+ require 'action_controller/railtie'
6
+ require 'action_view/railtie'
7
+ require 'action_mailer/railtie'
8
+ require 'active_job/railtie'
9
+ require 'action_cable/engine'
10
+ require 'rails/test_unit/railtie'
11
+ require 'sprockets/railtie'
12
+
13
+ # Workarea must be required before other gems to ensure control over Rails.env
14
+ # for running tests
15
+ require 'workarea/core'
16
+ require 'workarea/admin'
17
+ require 'workarea/storefront'
18
+ Bundler.require(*Rails.groups)
19
+ require 'workarea/swatches'
20
+
21
+ module Dummy
22
+ class Application < Rails::Application
23
+ # Initialize configuration defaults for originally generated Rails version.
24
+ config.load_defaults 5.1
25
+
26
+ # Settings in config/environments/* take precedence over those specified here.
27
+ # Application configuration should go into files in config/initializers
28
+ # -- all .rb files in that directory are automatically loaded.
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
@@ -0,0 +1,10 @@
1
+ development:
2
+ adapter: async
3
+
4
+ test:
5
+ adapter: async
6
+
7
+ production:
8
+ adapter: redis
9
+ url: redis://localhost:6379/1
10
+ channel_prefix: dummy_production
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require_relative 'application'
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!