solidus_liquid 0.0.1.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +36 -0
  5. data/.travis.yml +10 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +3 -0
  8. data/Guardfile +37 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +84 -0
  11. data/Rakefile +35 -0
  12. data/app/controllers/concerns/solidus_liquid/liquid.rb +26 -0
  13. data/app/controllers/solidus_liquid/addresses_controller.rb +15 -0
  14. data/app/controllers/solidus_liquid/carts_controller.rb +15 -0
  15. data/app/controllers/solidus_liquid/collections_controller.rb +22 -0
  16. data/app/controllers/solidus_liquid/customers_controller.rb +16 -0
  17. data/app/controllers/solidus_liquid/home_controller.rb +15 -0
  18. data/app/controllers/solidus_liquid/liquid_controller.rb +25 -0
  19. data/app/controllers/solidus_liquid/orders_controller.rb +18 -0
  20. data/app/controllers/solidus_liquid/pages_controller.rb +22 -0
  21. data/app/controllers/solidus_liquid/products_controller.rb +30 -0
  22. data/app/controllers/solidus_liquid/registrations_controller.rb +25 -0
  23. data/app/controllers/solidus_liquid/responders/solidus_liquid/liquid_responder.rb +29 -0
  24. data/app/controllers/solidus_liquid/search_controller.rb +41 -0
  25. data/app/controllers/solidus_liquid/sessions_controller.rb +15 -0
  26. data/app/drops/rails_settings/scoped_settings_drop.rb +11 -0
  27. data/app/drops/solidus_liquid/errors_drop.rb +14 -0
  28. data/app/drops/solidus_liquid/link_drop.rb +15 -0
  29. data/app/drops/solidus_liquid/link_list_drop.rb +7 -0
  30. data/app/drops/solidus_liquid/nil_drop.rb +7 -0
  31. data/app/drops/solidus_liquid/page_drop.rb +7 -0
  32. data/app/drops/solidus_liquid/search_drop.rb +7 -0
  33. data/app/drops/spree/address_drop.rb +24 -0
  34. data/app/drops/spree/image_drop.rb +10 -0
  35. data/app/drops/spree/line_item_drop.rb +5 -0
  36. data/app/drops/spree/option_type_drop.rb +4 -0
  37. data/app/drops/spree/order_drop.rb +18 -0
  38. data/app/drops/spree/product_drop.rb +92 -0
  39. data/app/drops/spree/taxon_drop.rb +31 -0
  40. data/app/drops/spree/user_drop.rb +19 -0
  41. data/app/drops/spree/variant_drop.rb +80 -0
  42. data/app/filters/solidus_liquid/additional_filters.rb +22 -0
  43. data/app/filters/solidus_liquid/html_filters.rb +20 -0
  44. data/app/filters/solidus_liquid/money_filters.rb +15 -0
  45. data/app/filters/solidus_liquid/string_filters.rb +11 -0
  46. data/app/filters/solidus_liquid/url_filters.rb +55 -0
  47. data/app/helpers/solidus_liquid/liquid_helper.rb +107 -0
  48. data/app/helpers/solidus_liquid/shop_helper.rb +7 -0
  49. data/app/models/concerns/solidus_liquid/address.rb +15 -0
  50. data/app/models/concerns/solidus_liquid/full_name.rb +11 -0
  51. data/app/models/concerns/solidus_liquid/handle.rb +25 -0
  52. data/app/models/concerns/solidus_liquid/inventory_policy.rb +7 -0
  53. data/app/models/solidus_liquid/asset.rb +12 -0
  54. data/app/models/solidus_liquid/link.rb +10 -0
  55. data/app/models/solidus_liquid/link_list.rb +7 -0
  56. data/app/models/solidus_liquid/page.rb +5 -0
  57. data/app/models/solidus_liquid/setting.rb +8 -0
  58. data/app/models/solidus_liquid/theme.rb +19 -0
  59. data/app/models/spree/address_decorator.rb +20 -0
  60. data/app/models/spree/image_decorator.rb +19 -0
  61. data/app/models/spree/product_decorator.rb +14 -0
  62. data/app/models/spree/taxon_decorator.rb +5 -0
  63. data/app/models/spree/variant_decorator.rb +15 -0
  64. data/app/poro/solidus_liquid/search.rb +14 -0
  65. data/app/services/solidus_liquid/app_specific_string_io.rb +15 -0
  66. data/app/services/solidus_liquid/asset_compiler.rb +11 -0
  67. data/app/services/solidus_liquid/asset_postprocessor.rb +53 -0
  68. data/app/services/solidus_liquid/link_list_seeder.rb +26 -0
  69. data/app/services/solidus_liquid/liquid_asset_compiler.rb +19 -0
  70. data/app/services/solidus_liquid/scss_asset_compiler.rb +15 -0
  71. data/app/services/solidus_liquid/shop_settings_seeder.rb +26 -0
  72. data/app/services/solidus_liquid/theme_mechanic.rb +45 -0
  73. data/app/uploaders/solidus_liquid/asset_uploader.rb +10 -0
  74. data/app/views/solidus_liquid/global/content_for_header.html.erb +0 -0
  75. data/app/views/solidus_liquid/themes/skeleton-theme/README.md +54 -0
  76. data/app/views/solidus_liquid/themes/skeleton-theme/assets/arrow-down.svg.liquid +3 -0
  77. data/app/views/solidus_liquid/themes/skeleton-theme/assets/cart.svg.liquid +4 -0
  78. data/app/views/solidus_liquid/themes/skeleton-theme/assets/shop.js.liquid +75 -0
  79. data/app/views/solidus_liquid/themes/skeleton-theme/assets/shopify_common.js +14 -0
  80. data/app/views/solidus_liquid/themes/skeleton-theme/assets/style.scss.liquid +768 -0
  81. data/app/views/solidus_liquid/themes/skeleton-theme/config/settings.html +217 -0
  82. data/app/views/solidus_liquid/themes/skeleton-theme/config/settings_data.json +26 -0
  83. data/app/views/solidus_liquid/themes/skeleton-theme/layout/theme.liquid +181 -0
  84. data/app/views/solidus_liquid/themes/skeleton-theme/snippets/article-grid-item.liquid +73 -0
  85. data/app/views/solidus_liquid/themes/skeleton-theme/snippets/collection-grid-item.liquid +46 -0
  86. data/app/views/solidus_liquid/themes/skeleton-theme/snippets/collection-listing.liquid +46 -0
  87. data/app/views/solidus_liquid/themes/skeleton-theme/snippets/open-graph-tags.liquid +35 -0
  88. data/app/views/solidus_liquid/themes/skeleton-theme/snippets/product-grid-item.liquid +70 -0
  89. data/app/views/solidus_liquid/themes/skeleton-theme/snippets/site-nav.liquid +57 -0
  90. data/app/views/solidus_liquid/themes/skeleton-theme/snippets/social-links.liquid +42 -0
  91. data/app/views/solidus_liquid/themes/skeleton-theme/snippets/twitter-card.liquid +41 -0
  92. data/app/views/solidus_liquid/themes/skeleton-theme/templates/404.liquid +2 -0
  93. data/app/views/solidus_liquid/themes/skeleton-theme/templates/article.liquid +160 -0
  94. data/app/views/solidus_liquid/themes/skeleton-theme/templates/blog.grid.liquid +30 -0
  95. data/app/views/solidus_liquid/themes/skeleton-theme/templates/blog.liquid +92 -0
  96. data/app/views/solidus_liquid/themes/skeleton-theme/templates/cart.liquid +123 -0
  97. data/app/views/solidus_liquid/themes/skeleton-theme/templates/collection.liquid +102 -0
  98. data/app/views/solidus_liquid/themes/skeleton-theme/templates/customers/account.liquid +57 -0
  99. data/app/views/solidus_liquid/themes/skeleton-theme/templates/customers/activate_account.liquid +26 -0
  100. data/app/views/solidus_liquid/themes/skeleton-theme/templates/customers/addresses.liquid +173 -0
  101. data/app/views/solidus_liquid/themes/skeleton-theme/templates/customers/login.liquid +90 -0
  102. data/app/views/solidus_liquid/themes/skeleton-theme/templates/customers/order.liquid +103 -0
  103. data/app/views/solidus_liquid/themes/skeleton-theme/templates/customers/register.liquid +32 -0
  104. data/app/views/solidus_liquid/themes/skeleton-theme/templates/customers/reset_password.liquid +27 -0
  105. data/app/views/solidus_liquid/themes/skeleton-theme/templates/index.liquid +39 -0
  106. data/app/views/solidus_liquid/themes/skeleton-theme/templates/list-collections.liquid +19 -0
  107. data/app/views/solidus_liquid/themes/skeleton-theme/templates/page.liquid +16 -0
  108. data/app/views/solidus_liquid/themes/skeleton-theme/templates/product.liquid +202 -0
  109. data/app/views/solidus_liquid/themes/skeleton-theme/templates/search.liquid +72 -0
  110. data/bin/rails +12 -0
  111. data/config/app.yml +0 -0
  112. data/config/initializers/carrierwave.rb +25 -0
  113. data/config/initializers/devise.rb +286 -0
  114. data/config/initializers/form_tag.rb +43 -0
  115. data/config/initializers/liquid.rb +202 -0
  116. data/config/initializers/sass.rb +15 -0
  117. data/config/initializers/theme_settings.rb +29 -0
  118. data/config/routes.rb +48 -0
  119. data/db/migrate/20170223064316_create_solidus_liquid_assets.solidus_liquid.rb +14 -0
  120. data/db/migrate/20170223064317_create_solidus_liquid_themes.solidus_liquid.rb +10 -0
  121. data/db/migrate/20170223064318_create_solidus_liquid_link_lists.solidus_liquid.rb +12 -0
  122. data/db/migrate/20170223064319_create_solidus_liquid_links.solidus_liquid.rb +13 -0
  123. data/db/migrate/20170223064320_create_solidus_liquid_settings.solidus_liquid.rb +22 -0
  124. data/db/migrate/20170223064321_create_solidus_liquid_pages.solidus_liquid.rb +16 -0
  125. data/db/migrate/20170223064322_add_attributes_to_spree_users.solidus_liquid.rb +7 -0
  126. data/db/migrate/20170223064323_add_handle_to_spree_taxons.solidus_liquid.rb +7 -0
  127. data/lib/generators/solidus_liquid/install/install_generator.rb +13 -0
  128. data/lib/solidus_liquid.rb +11 -0
  129. data/lib/solidus_liquid/configuration.rb +21 -0
  130. data/lib/solidus_liquid/engine.rb +24 -0
  131. data/lib/solidus_liquid/factories.rb +7 -0
  132. data/lib/solidus_liquid/version.rb +3 -0
  133. data/lib/tasks/download_theme.rake +18 -0
  134. data/lib/tasks/seed_default_theme.rake +8 -0
  135. data/lib/tasks/seed_everything.rake +14 -0
  136. data/lib/tasks/seed_link_list.rake +8 -0
  137. data/lib/tasks/seed_shop_settings.rake +8 -0
  138. data/solidus_liquid.gemspec +56 -0
  139. metadata +586 -0
@@ -0,0 +1,25 @@
1
+ module SolidusLiquid
2
+ class LiquidController < ApplicationController
3
+ include ::Spree::Core::ControllerHelpers::Auth
4
+ include ::Spree::Core::ControllerHelpers::Order
5
+ include ::Spree::Core::ControllerHelpers::Pricing
6
+ include ::Spree::Core::ControllerHelpers::Store
7
+
8
+ # rescue_from ActiveRecord::RecordNotFound, with: :render_404_page
9
+
10
+ include SolidusLiquid::Liquid
11
+
12
+ def set_liquid_assigns
13
+ raise 'Need to call this from subclass'
14
+ end
15
+
16
+ def render_404_page(_exception = nil)
17
+ render(
18
+ status: :not_found,
19
+ template: controller_action_to_liquid_file_path(nil, 'home#missing'),
20
+ formats: [:html],
21
+ layout: theme_layout_file
22
+ )
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ module SolidusLiquid
2
+ class OrdersController < LiquidController
3
+ # Adds a new item to the order (creating a new order if none already exists)
4
+ def populate
5
+ order = current_order(create_order_if_necessary: true)
6
+ variant = Spree::Variant.find(params[:id])
7
+ quantity = params[:quantity].present? ? params[:quantity].to_i : 1
8
+
9
+ order.contents.add(variant, quantity)
10
+
11
+ redirect_to cart_path
12
+ end
13
+
14
+ def set_liquid_assigns
15
+ @liquid_assigns = {}
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ module SolidusLiquid
2
+ class PagesController < LiquidController
3
+ def show
4
+ render controller_action_to_liquid_file_path(page)
5
+ end
6
+
7
+ def set_liquid_assigns
8
+ @liquid_assigns = {
9
+ 'canonical_url' => "#{request.base_url}#{page.url}",
10
+ 'page' => page,
11
+ 'page_title' => page.title,
12
+ 'template' => 'page'
13
+ }
14
+ end
15
+
16
+ private
17
+
18
+ def page
19
+ @page ||= Page.find(params[:id])
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,30 @@
1
+ module SolidusLiquid
2
+ class ProductsController < LiquidController
3
+ before_action :load_collection
4
+
5
+ def show
6
+ render controller_action_to_liquid_file_path(product)
7
+ end
8
+
9
+ def set_liquid_assigns
10
+ @liquid_assigns = {
11
+ 'canonical_url' => "#{request.base_url}#{product.url}",
12
+ 'collection' => @collection,
13
+ 'page_title' => product.title,
14
+ 'product' => product,
15
+ 'template' => 'product'
16
+ }
17
+ end
18
+
19
+ private
20
+
21
+ def product
22
+ @product ||= Spree::Product.available.friendly.find(params[:id])
23
+ end
24
+
25
+ def load_collection
26
+ return unless params[:taxon_id].present?
27
+ @collection ||= Spree::Taxon.where(handle: params[:taxon_id]).first
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,25 @@
1
+ module SolidusLiquid
2
+ class RegistrationsController < ::Devise::RegistrationsController
3
+ include SolidusLiquid::Liquid
4
+
5
+ self.responder = SolidusLiquid::LiquidResponder
6
+
7
+ # rubocop:disable Metrics/LineLength
8
+ def set_liquid_assigns
9
+ @liquid_assigns = {
10
+ 'canonical_url' => "#{request.base_url}#{new_customer_registration_path}",
11
+ 'page_title' => 'Create Account',
12
+ 'template' => 'page'
13
+ }
14
+ end
15
+
16
+ before_action :configure_sign_up_params, only: [:create]
17
+
18
+ protected
19
+
20
+ def configure_sign_up_params
21
+ devise_parameter_sanitizer.permit(:sign_up,
22
+ keys: [:first_name, :last_name])
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,29 @@
1
+ module SolidusLiquid
2
+ class LiquidResponder < ::ActionController::Responder
3
+ DEFAULT_ACTIONS_FOR_VERBS = {
4
+ post: :new, patch: :edit, put: :edit, get: :new
5
+ }.freeze
6
+
7
+ include LiquidHelper
8
+
9
+ def to_html
10
+ liquid_assigns = controller.instance_variable_get(:@liquid_assigns)
11
+ liquid_assigns['form'] = resource
12
+
13
+ if options[:location].present?
14
+ redirect_to(options[:location])
15
+ else
16
+ render_liquid_from_controller_action
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def render_liquid_from_controller_action
23
+ controller_name = controller.controller_name
24
+ action_name = DEFAULT_ACTIONS_FOR_VERBS[request.request_method_symbol]
25
+ controller_action = "#{controller_name}##{action_name}"
26
+ render controller_action_to_liquid_file_path(resource, controller_action)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,41 @@
1
+ module SolidusLiquid
2
+ class SearchController < LiquidController
3
+ def index
4
+ render controller_action_to_liquid_file_path
5
+ end
6
+
7
+ def set_liquid_assigns
8
+ @liquid_assigns = {
9
+ 'canonical_url' => "#{request.base_url}#{search_path}",
10
+ 'page_title' => '',
11
+ 'search' => search,
12
+ 'template' => 'page'
13
+ }
14
+ end
15
+
16
+ private
17
+
18
+ def search
19
+ return @search if @search.present?
20
+
21
+ @search = if params[:q].blank?
22
+ Search.new
23
+ else
24
+ perform_search
25
+ end
26
+ end
27
+
28
+ def perform_search
29
+ product_scope = Spree::Product.accessible_by(
30
+ Spree::Ability.new(current_spree_user), :read
31
+ )
32
+ search_result = product_scope.ransack(params[:q]).result
33
+ Search.new(
34
+ performed: true,
35
+ results: search_result,
36
+ results_count: search_result.count,
37
+ terms: params[:q]
38
+ )
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,15 @@
1
+ module SolidusLiquid
2
+ class SessionsController < ::Devise::SessionsController
3
+ include SolidusLiquid::Liquid
4
+
5
+ self.responder = SolidusLiquid::LiquidResponder
6
+
7
+ def set_liquid_assigns
8
+ @liquid_assigns = {
9
+ 'canonical_url' => "#{request.base_url}#{new_customer_session_path}",
10
+ 'page_title' => 'Log in',
11
+ 'template' => 'page'
12
+ }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module RailsSettings
2
+ class ScopedSettingsDrop < ::Liquid::Rails::Drop
3
+ def liquid_method_missing(method)
4
+ if method.present?
5
+ ::SolidusLiquid::NilDrop.new(nil)
6
+ else
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ module SolidusLiquid
2
+ class ErrorsDrop < ::Liquid::Rails::Drop
3
+ attributes :messages
4
+
5
+ def initialize(errors)
6
+ @errors = errors
7
+ super
8
+ end
9
+
10
+ def to_liquid
11
+ @errors.full_messages
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module SolidusLiquid
2
+ class LinkDrop < ::Liquid::Rails::Drop
3
+ attributes :title, :url
4
+
5
+ belongs_to :link_list
6
+
7
+ def active
8
+ @context.registers[:controller].request.path == @object.url
9
+ end
10
+
11
+ def type
12
+ nil
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ module SolidusLiquid
2
+ class LinkListDrop < ::Liquid::Rails::Drop
3
+ attributes :id, :title, :handle
4
+
5
+ has_many :links
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module SolidusLiquid
2
+ class NilDrop < ::Liquid::Rails::Drop
3
+ def liquid_method_missing(_method)
4
+ nil
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module SolidusLiquid
2
+ class PageDrop < ::Liquid::Rails::Drop
3
+ attributes :id, :title, :body_html, :published_at, :author
4
+
5
+ alias content body_html
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module SolidusLiquid
2
+ class SearchDrop < ::Liquid::Rails::Drop
3
+ attributes :performed, :results_count, :terms
4
+
5
+ has_many :results
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ module Spree
2
+ class AddressDrop < ::Liquid::Rails::Drop
3
+ attributes :id, :address1, :address2, :city, :company, :country,
4
+ :country_code, :default, :first_name, :last_name, :latitude,
5
+ :longitude, :name, :phone, :province, :province_code, :street,
6
+ :zip
7
+
8
+ def country
9
+ @object.country.name
10
+ end
11
+
12
+ def country_code
13
+ @object.country.iso
14
+ end
15
+
16
+ def latitude
17
+ 0
18
+ end
19
+
20
+ def longitude
21
+ 0
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ module Spree
2
+ class ImageDrop < ::Liquid::Rails::Drop
3
+ attributes :id, :alt, :attached_to_variant?, :attachment, :position,
4
+ :product_id, :src, :variants
5
+
6
+ def to_json(_json)
7
+ @object.try(:attachment).try(:url).try(:to_json)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module Spree
2
+ class LineItemDrop < ::Liquid::Rails::Drop
3
+ has_one :id, :product, :quantity, :url
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module Spree
2
+ class OptionTypeDrop < ::Liquid::Rails::Drop
3
+ end
4
+ end
@@ -0,0 +1,18 @@
1
+ module Spree
2
+ class OrderDrop < ::Liquid::Rails::Drop
3
+ attributes :item_count, :total
4
+
5
+ belongs_to :customer
6
+
7
+ def attributes
8
+ {}
9
+ end
10
+
11
+ def items
12
+ @object.line_items
13
+ end
14
+
15
+ # TODO: make sure solidus total shows the same as shopfiy's total_price
16
+ alias total_price total
17
+ end
18
+ end
@@ -0,0 +1,92 @@
1
+ module Spree
2
+ class ProductDrop < ::Liquid::Rails::Drop
3
+ attributes :id, :available, :content, :compare_at_price,
4
+ :compare_at_price_max, :compare_at_price_min,
5
+ :compare_at_price_varies, :created_at, :description,
6
+ :featured_image, :handle, :images, :options, :price, :price_max,
7
+ :price_min, :price_varies, :published_at, :tags, :title, :type,
8
+ :variants, :vendor
9
+
10
+ def available
11
+ @object.available?
12
+ end
13
+
14
+ def collections
15
+ @object.taxons
16
+ end
17
+
18
+ alias content description
19
+
20
+ def url
21
+ @object.url
22
+ end
23
+
24
+ def variants
25
+ @object.variants.to_a.map do |v|
26
+ Spree::VariantDrop.new(v)
27
+ end
28
+ end
29
+
30
+ # warning
31
+ def compare_at_price
32
+ nil
33
+ end
34
+
35
+ def compare_at_price_max
36
+ 0
37
+ end
38
+
39
+ def compare_at_price_min
40
+ 0
41
+ end
42
+
43
+ def compare_at_price_varies
44
+ false
45
+ end
46
+
47
+ def price
48
+ (@object.price * 100).to_i
49
+ end
50
+
51
+ alias price_max price
52
+ alias price_min price
53
+
54
+ def price_varies
55
+ false
56
+ end
57
+
58
+ def tags
59
+ []
60
+ end
61
+
62
+ def type
63
+ ''
64
+ end
65
+
66
+ def vendor
67
+ SolidusLiquid::Setting['name']
68
+ end
69
+
70
+ # shopify json returns datetime in shop's timezone
71
+ alias published_at created_at
72
+
73
+ # error
74
+ # TODO: check if shopify returns variant images as well
75
+ # Spree::Product.images delegates to master variant
76
+ def images
77
+ @object.images.map(&:attachment).map(&:url)
78
+ end
79
+
80
+ def metafields
81
+ ::RailsSettings::ScopedSettingsDrop.new(@object.settings)
82
+ end
83
+
84
+ def options
85
+ @object.option_types.map(&:presentation)
86
+ end
87
+
88
+ def selected_or_first_available_variant
89
+ @object.variants.first
90
+ end
91
+ end
92
+ end