@spree/docs 0.1.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.
- package/README.md +54 -0
- package/dist/api-reference/platform/authentication.md +38 -0
- package/dist/api-reference/store-api/authentication.md +188 -0
- package/dist/api-reference/store-api/errors.md +277 -0
- package/dist/api-reference/store-api/idempotency.md +129 -0
- package/dist/api-reference/store-api/introduction.md +34 -0
- package/dist/api-reference/store-api/localization.md +279 -0
- package/dist/api-reference/store-api/metadata.md +160 -0
- package/dist/api-reference/store-api/monetary-amounts.md +65 -0
- package/dist/api-reference/store-api/querying.md +399 -0
- package/dist/api-reference/store-api/rate-limitting.md +103 -0
- package/dist/api-reference/store-api/relations.md +185 -0
- package/dist/api-reference/storefront/authentication.md +88 -0
- package/dist/api-reference/tutorials/adyen-integration-guide-for-android.md +165 -0
- package/dist/api-reference/tutorials/adyen-integration-guide-for-ios.md +194 -0
- package/dist/api-reference/tutorials/quick-checkout-with-stripe.md +248 -0
- package/dist/api-reference/v2/fetching-multiple-resources.md +26 -0
- package/dist/api-reference/v2/filtering-and-sorting.md +53 -0
- package/dist/api-reference/v2/introduction.md +22 -0
- package/dist/api-reference/v2/pagination.md +37 -0
- package/dist/api-reference/webhooks-events.md +883 -0
- package/dist/developer/admin/admin.md +205 -0
- package/dist/developer/admin/authentication.md +59 -0
- package/dist/developer/admin/components.md +711 -0
- package/dist/developer/admin/custom-css.md +243 -0
- package/dist/developer/admin/custom-javascript.md +116 -0
- package/dist/developer/admin/extending-ui.md +1964 -0
- package/dist/developer/admin/form-builder.md +444 -0
- package/dist/developer/admin/helper-methods.md +531 -0
- package/dist/developer/admin/navigation.md +805 -0
- package/dist/developer/admin/tables.md +491 -0
- package/dist/developer/advanced/adding_spree_to_rails_app.md +106 -0
- package/dist/developer/cli/quickstart.md +137 -0
- package/dist/developer/contributing/creating-an-extension.md +258 -0
- package/dist/developer/contributing/developing-spree.md +339 -0
- package/dist/developer/contributing/quickstart.md +32 -0
- package/dist/developer/contributing/updating-extensions.md +67 -0
- package/dist/developer/core-concepts/addresses.md +265 -0
- package/dist/developer/core-concepts/adjustments.md +107 -0
- package/dist/developer/core-concepts/architecture.md +177 -0
- package/dist/developer/core-concepts/calculators.md +323 -0
- package/dist/developer/core-concepts/customers.md +230 -0
- package/dist/developer/core-concepts/events.md +624 -0
- package/dist/developer/core-concepts/imports-exports.md +698 -0
- package/dist/developer/core-concepts/inventory.md +191 -0
- package/dist/developer/core-concepts/markets.md +250 -0
- package/dist/developer/core-concepts/media.md +167 -0
- package/dist/developer/core-concepts/metafields.md +187 -0
- package/dist/developer/core-concepts/orders.md +328 -0
- package/dist/developer/core-concepts/payments.md +710 -0
- package/dist/developer/core-concepts/pricing.md +163 -0
- package/dist/developer/core-concepts/products.md +360 -0
- package/dist/developer/core-concepts/promotions.md +322 -0
- package/dist/developer/core-concepts/reports.md +206 -0
- package/dist/developer/core-concepts/search-filtering.md +237 -0
- package/dist/developer/core-concepts/shipments.md +212 -0
- package/dist/developer/core-concepts/slugs.md +111 -0
- package/dist/developer/core-concepts/staff-roles.md +123 -0
- package/dist/developer/core-concepts/store-credits-gift-cards.md +317 -0
- package/dist/developer/core-concepts/stores.md +117 -0
- package/dist/developer/core-concepts/taxes.md +135 -0
- package/dist/developer/core-concepts/translations.md +120 -0
- package/dist/developer/core-concepts/users.md +299 -0
- package/dist/developer/core-concepts/webhooks.md +378 -0
- package/dist/developer/create-spree-app/quickstart.md +158 -0
- package/dist/developer/customization/api.md +93 -0
- package/dist/developer/customization/authentication.md +88 -0
- package/dist/developer/customization/checkout.md +204 -0
- package/dist/developer/customization/configuration.md +55 -0
- package/dist/developer/customization/decorators.md +523 -0
- package/dist/developer/customization/dependencies.md +232 -0
- package/dist/developer/customization/emails.md +21 -0
- package/dist/developer/customization/extensions.md +92 -0
- package/dist/developer/customization/metadata.md +236 -0
- package/dist/developer/customization/model-preferences.md +130 -0
- package/dist/developer/customization/permissions.md +265 -0
- package/dist/developer/customization/quickstart.md +229 -0
- package/dist/developer/customization/routes.md +24 -0
- package/dist/developer/customization/v4/admin-panel.md +78 -0
- package/dist/developer/customization/v4/authentication.md +210 -0
- package/dist/developer/customization/v4/checkout.md +212 -0
- package/dist/developer/customization/v4/deface.md +251 -0
- package/dist/developer/customization/v4/images.md +86 -0
- package/dist/developer/customization/v4/storefront.md +450 -0
- package/dist/developer/deployment/assets.md +87 -0
- package/dist/developer/deployment/aws.md +335 -0
- package/dist/developer/deployment/caching.md +27 -0
- package/dist/developer/deployment/cdn.md +39 -0
- package/dist/developer/deployment/database.md +155 -0
- package/dist/developer/deployment/docker.md +128 -0
- package/dist/developer/deployment/emails.md +77 -0
- package/dist/developer/deployment/environment_variables.md +111 -0
- package/dist/developer/deployment/heroku.md +51 -0
- package/dist/developer/deployment/render.md +95 -0
- package/dist/developer/getting-started/quickstart.md +82 -0
- package/dist/developer/how-to/custom-payment-method.md +374 -0
- package/dist/developer/how-to/custom-promotion.md +373 -0
- package/dist/developer/how-to/custom-report.md +387 -0
- package/dist/developer/how-to/custom-search-provider.md +230 -0
- package/dist/developer/multi-store/quickstart.md +71 -0
- package/dist/developer/multi-store/setup.md +38 -0
- package/dist/developer/multi-tenant/configuration.md +41 -0
- package/dist/developer/multi-tenant/core-concepts.md +75 -0
- package/dist/developer/multi-tenant/installation.md +96 -0
- package/dist/developer/multi-tenant/quickstart.md +20 -0
- package/dist/developer/multi-vendor/installation.md +45 -0
- package/dist/developer/multi-vendor/quickstart.md +17 -0
- package/dist/developer/sdk/admin/quickstart.md +22 -0
- package/dist/developer/sdk/authentication.md +89 -0
- package/dist/developer/sdk/configuration.md +225 -0
- package/dist/developer/sdk/quickstart.md +82 -0
- package/dist/developer/sdk/store/account.md +67 -0
- package/dist/developer/sdk/store/cart-checkout.md +140 -0
- package/dist/developer/sdk/store/markets.md +151 -0
- package/dist/developer/sdk/store/payments.md +96 -0
- package/dist/developer/sdk/store/products.md +149 -0
- package/dist/developer/sdk/store/wishlists.md +52 -0
- package/dist/developer/security/pci_compliance.md +15 -0
- package/dist/developer/security/security_policy.md +68 -0
- package/dist/developer/storefront/blocks.md +285 -0
- package/dist/developer/storefront/custom-css.md +260 -0
- package/dist/developer/storefront/custom-javascript.md +166 -0
- package/dist/developer/storefront/helper-methods.md +1288 -0
- package/dist/developer/storefront/links.md +298 -0
- package/dist/developer/storefront/nextjs/architecture.md +150 -0
- package/dist/developer/storefront/nextjs/customization.md +141 -0
- package/dist/developer/storefront/nextjs/deployment.md +180 -0
- package/dist/developer/storefront/nextjs/quickstart.md +92 -0
- package/dist/developer/storefront/nextjs/spree-next-package.md +314 -0
- package/dist/developer/storefront/pages.md +163 -0
- package/dist/developer/storefront/sections.md +569 -0
- package/dist/developer/storefront/storefront.md +56 -0
- package/dist/developer/storefront/themes.md +161 -0
- package/dist/developer/tutorial/admin.md +134 -0
- package/dist/developer/tutorial/extending-models.md +380 -0
- package/dist/developer/tutorial/file-uploads.md +121 -0
- package/dist/developer/tutorial/introduction.md +33 -0
- package/dist/developer/tutorial/model.md +41 -0
- package/dist/developer/tutorial/page-builder.md +487 -0
- package/dist/developer/tutorial/rich-text.md +73 -0
- package/dist/developer/tutorial/seo.md +332 -0
- package/dist/developer/tutorial/storefront.md +352 -0
- package/dist/developer/tutorial/testing.md +558 -0
- package/dist/developer/upgrades/2.0-to-2.1.md +46 -0
- package/dist/developer/upgrades/2.1-to-2.2.md +59 -0
- package/dist/developer/upgrades/2.2-to-2.3.md +44 -0
- package/dist/developer/upgrades/2.3-to-2.4.md +42 -0
- package/dist/developer/upgrades/3.0-to-3.1.md +47 -0
- package/dist/developer/upgrades/3.1-to-3.2.md +34 -0
- package/dist/developer/upgrades/3.2-to-3.3.md +70 -0
- package/dist/developer/upgrades/3.3-to-3.4.md +36 -0
- package/dist/developer/upgrades/3.4-to-3.5.md +44 -0
- package/dist/developer/upgrades/3.5-to-3.6.md +40 -0
- package/dist/developer/upgrades/3.6-to-3.7.md +62 -0
- package/dist/developer/upgrades/3.7-to-4.0.md +152 -0
- package/dist/developer/upgrades/4.0-to-4.1.md +92 -0
- package/dist/developer/upgrades/4.1-to-4.2.md +109 -0
- package/dist/developer/upgrades/4.10-to-5.0.md +129 -0
- package/dist/developer/upgrades/4.2-to-4.3.md +100 -0
- package/dist/developer/upgrades/4.3-to-4.4.md +125 -0
- package/dist/developer/upgrades/4.4-to-4.5.md +94 -0
- package/dist/developer/upgrades/4.5-to-4.6.md +119 -0
- package/dist/developer/upgrades/4.6-to-4.7.md +39 -0
- package/dist/developer/upgrades/4.8-to-4.9.md +24 -0
- package/dist/developer/upgrades/4.9-to-4.10.md +24 -0
- package/dist/developer/upgrades/4.x-to-4.8.md +52 -0
- package/dist/developer/upgrades/5.0-to-5.1.md +28 -0
- package/dist/developer/upgrades/5.1-to-5.2.md +127 -0
- package/dist/developer/upgrades/5.2-to-5.3.md +338 -0
- package/dist/developer/upgrades/5.3-to-5.4.md +248 -0
- package/dist/developer/upgrades/quickstart.md +36 -0
- package/dist/integrations/analytics/google-analytics.md +64 -0
- package/dist/integrations/analytics/google-tag-manager.md +78 -0
- package/dist/integrations/integrations.md +39 -0
- package/dist/integrations/marketing/klaviyo.md +99 -0
- package/dist/integrations/payments/adyen.md +90 -0
- package/dist/integrations/payments/paypal.md +41 -0
- package/dist/integrations/payments/razorpay.md +45 -0
- package/dist/integrations/payments/stripe.md +109 -0
- package/dist/integrations/search/meilisearch.md +236 -0
- package/dist/integrations/sso-mfa-social-login/admin-dashboard.md +57 -0
- package/dist/integrations/sso-mfa-social-login/storefront.md +56 -0
- package/package.json +27 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Deface Overrides
|
|
3
|
+
version: v4
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
> **WARNING:** Using Deface is no longer recommended, we strongly encourage you to use other ways to customize Spree.
|
|
7
|
+
|
|
8
|
+
## What is Deface?
|
|
9
|
+
|
|
10
|
+
Deface is a standalone Rails library that enables you to customize Erb templates without needing to directly edit the underlying view file. Deface allows you to use standard CSS3 style selectors to target any element including Ruby blocks, and perform an action against all the matching elements.
|
|
11
|
+
|
|
12
|
+
## Improving Our Extension Using Deface
|
|
13
|
+
|
|
14
|
+
### The Goal
|
|
15
|
+
|
|
16
|
+
Our goal is to add a field to the product edit admin page that allows the `sale_price` to be added or updated. We could do this by overriding the view Spree provides, but there are potential problems with this technique. If Spree updates the view in a new release we won't get the updated view as we are already overriding it. We would need to update our view with the new content from Spree and then add our customizations back in to stay fully up to date.
|
|
17
|
+
|
|
18
|
+
Let's do this instead using Deface, which we just learned about. Using Deface will allow us to keep our view customizations in one spot, `app/overrides`, and make sure we are always using the latest implementation of the view provided by Spree.
|
|
19
|
+
|
|
20
|
+
### The Implementation
|
|
21
|
+
|
|
22
|
+
We want to override the product edit admin page, so the view we want to modify in this case is the product form partial. This file's path will be `spree/admin/products/_form.html.erb`.
|
|
23
|
+
|
|
24
|
+
First, let's create the overrides directory with the following command:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
mkdir app/overrides
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
So we want to override `spree/admin/products/_form.html.erb`. Here is the part of the file we are going to add content to you can also view the [full file](https://github.com/spree/spree/blob/main/backend/app/views/spree/admin/products/_form.html.erb):
|
|
31
|
+
|
|
32
|
+
```erb
|
|
33
|
+
<div class="right four columns omega" data-hook="admin_product_form_right">
|
|
34
|
+
<%= f.field_container :price do %>
|
|
35
|
+
<%= f.label :price, raw(Spree.t(:master_price) + required_span_tag) %>
|
|
36
|
+
<%= f.text_field :price, value: number_to_currency(@product.price, unit: '')%>
|
|
37
|
+
<%= f.error_message_on :price %>
|
|
38
|
+
<% end %>
|
|
39
|
+
</div>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
We want our override to insert another field container after the price field container. We can do this by creating a new file `app/overrides/add_sale_price_to_product_edit.rb` and adding the following content:
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
Deface::Override.new(virtual_path: 'spree/admin/products/_form',
|
|
46
|
+
name: 'add_sale_price_to_product_edit',
|
|
47
|
+
insert_after: "erb[loud]:contains('text_field :price')",
|
|
48
|
+
text: "
|
|
49
|
+
<%%= f.field_container :sale_price do %>
|
|
50
|
+
<%%= f.label :sale_price, raw(Spree.t(:sale_price) + content_tag(:span, ' *')) %>
|
|
51
|
+
<%%= f.text_field :sale_price, value:
|
|
52
|
+
number_to_currency(@product.sale_price, unit: '') %>
|
|
53
|
+
<%%= f.error_message_on :sale_price %>
|
|
54
|
+
<%% end %>
|
|
55
|
+
")
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
We also need to delegate `sale_price` to the master variant in order to get the updated product edit form working.
|
|
59
|
+
|
|
60
|
+
We can do this by creating a new file `app/models/spree/product_decorator.rb` and adding the following content to it:
|
|
61
|
+
|
|
62
|
+
```ruby
|
|
63
|
+
module Spree
|
|
64
|
+
Product.class_eval do
|
|
65
|
+
delegate :sale_price, :sale_price=, to: :master
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Now, when we head to `http://localhost:3000/admin/products` and edit a product, we should be able to set a sale price for the product and be able to view it on our sale page, `http://localhost:3000/sale`. Note that you will likely need to restart our example Spree application created in the [Getting Started tutorial](/developer/getting-started/quickstart).
|
|
71
|
+
|
|
72
|
+
### Available actions
|
|
73
|
+
|
|
74
|
+
Deface applies an **action** to elements matching the supplied CSS selector. These actions are passed when defining a new override are supplied as the key while the CSS selector for the target elements is the value, for example:
|
|
75
|
+
|
|
76
|
+
```ruby
|
|
77
|
+
remove: "p.junk"
|
|
78
|
+
|
|
79
|
+
insert_after: "div#wow p.header"
|
|
80
|
+
|
|
81
|
+
insert_bottom: "ul#giant-list"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Deface currently supports the following actions:
|
|
85
|
+
|
|
86
|
+
* :remove - Removes all elements that match the supplied selector
|
|
87
|
+
* :replace - Replaces all elements that match the supplied selector, with the content supplied
|
|
88
|
+
* :replace_contents - Replaces the contents of all elements that match the supplied selector
|
|
89
|
+
* :surround - Surrounds all elements that match the supplied selector, expects replacement markup to contain <%%= render_original %> placeholder
|
|
90
|
+
* :surround_contents - Surrounds the contents of all elements that match the supplied selector, expects replacement markup to contain <%%= render_original %> placeholder
|
|
91
|
+
* :insert_after - Inserts after all elements that match the supplied selector
|
|
92
|
+
* :insert_before - Inserts before all elements that match the supplied selector
|
|
93
|
+
* :insert_top - Inserts inside all elements that match the supplied selector, as the first child
|
|
94
|
+
* :insert_bottom - Inserts inside all elements that match the supplied selector, as the last child
|
|
95
|
+
* :set_attributes - Sets attributes on all elements that match the supplied selector, replacing existing attribute value if present or adding if not. Expects :attributes option to be passed.
|
|
96
|
+
* :add_to_attributes - Appends value to attributes on all elements that match the supplied selector, adds attribute if not present. Expects :attributes option to be passed.
|
|
97
|
+
* :remove_from_attributes - Removes value from attributes on all elements that match the supplied selector. Expects :attributes option to be passed.
|
|
98
|
+
|
|
99
|
+
Not all actions are applicable to all elements. For example, \`:insert_top\` and \`:insert_bottom\` expects a parent element with children.
|
|
100
|
+
|
|
101
|
+
### Supplying content
|
|
102
|
+
|
|
103
|
+
Deface supports three options for supplying content to be used by an override:
|
|
104
|
+
|
|
105
|
+
* :text - String containing markup
|
|
106
|
+
* :partial - Relative path to a partial
|
|
107
|
+
* :template - Relative path to a template
|
|
108
|
+
|
|
109
|
+
As Deface operates on the Erb source the content supplied to an override can include Erb, it is not limited to just HTML. You also have access to all variables accessible in the original Erb context.
|
|
110
|
+
|
|
111
|
+
### Targeting elements
|
|
112
|
+
|
|
113
|
+
While Deface allows you to use a large subset of CSS3 style selectors as provided by Nokogiri, the majority of Spree's views have been updated to include a custom HTML attribute data-hook, which is designed to provide consistent targets for your overrides to use.
|
|
114
|
+
|
|
115
|
+
As Spree views are changed over coming versions, the original HTML elements maybe edited or be removed. We will endeavour to ensure that data-hook / id combination will remain consistent within any single view file where possible, thus making your overrides more robust and upgrade proof.
|
|
116
|
+
|
|
117
|
+
For example, spree/products/show.html.erb looks as follows:
|
|
118
|
+
|
|
119
|
+
```erb
|
|
120
|
+
<div data-hook="product_show" itemscope itemtype="http://schema.org/Product">
|
|
121
|
+
<%% body_id = 'product-details' %>
|
|
122
|
+
<div class="columns six alpha" data-hook="product_left_part">
|
|
123
|
+
<div class="row" data-hook="product_left_part_wrap">
|
|
124
|
+
<div id="product-images" data-hook="product_images">
|
|
125
|
+
<div id="main-image" data-hook>
|
|
126
|
+
<%%= render 'image' %>
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
<div id="thumbnails" data-hook>
|
|
130
|
+
<%%= render 'thumbnails', product: product %>
|
|
131
|
+
</div>
|
|
132
|
+
</div>
|
|
133
|
+
|
|
134
|
+
<div data-hook="product_properties">
|
|
135
|
+
<%%= render 'properties' %>
|
|
136
|
+
</div>
|
|
137
|
+
|
|
138
|
+
</div>
|
|
139
|
+
</div>
|
|
140
|
+
|
|
141
|
+
<div class="columns ten omega" data-hook="product_right_part">
|
|
142
|
+
<div class="row" data-hook="product_right_part_wrap">
|
|
143
|
+
|
|
144
|
+
<div id="product-description" data-hook="product_description">
|
|
145
|
+
|
|
146
|
+
<h1 class="product-title" itemprop="name"><%%= accurate_title %></h1>
|
|
147
|
+
|
|
148
|
+
<div itemprop="description" data-hook="description">
|
|
149
|
+
<%%= product_description(product) rescue Spree.t(:product_has_no_description) %>
|
|
150
|
+
</div>
|
|
151
|
+
|
|
152
|
+
<div id="cart-form" data-hook="cart_form">
|
|
153
|
+
<%%= render 'cart_form' %>
|
|
154
|
+
</div>
|
|
155
|
+
</div>
|
|
156
|
+
|
|
157
|
+
<%%= render 'taxons' %>
|
|
158
|
+
</div>
|
|
159
|
+
</div>
|
|
160
|
+
</div>
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
As you can see from the example above the `data-hook` can be present in a number of ways:
|
|
164
|
+
|
|
165
|
+
* On elements with **no** `id` attribute the `data-hook` attribute
|
|
166
|
+
|
|
167
|
+
contains a value similar to what would be included in the `id`
|
|
168
|
+
|
|
169
|
+
attribute.
|
|
170
|
+
|
|
171
|
+
* On elements with an `id` attribute the `data-hook` attribute does
|
|
172
|
+
|
|
173
|
+
**not** normally contain a value.
|
|
174
|
+
|
|
175
|
+
* Occasionally on elements with an `id` attribute the `data-hook` will
|
|
176
|
+
|
|
177
|
+
contain a value different from the elements id. This is generally to
|
|
178
|
+
|
|
179
|
+
support migration from the old 0.60.x style of hooks, where the old
|
|
180
|
+
|
|
181
|
+
hook names were converted into `data-hook` versions.
|
|
182
|
+
|
|
183
|
+
The suggested way to target an element is to use the `data-hook` attribute wherever possible. Here are a few examples based on **products/show.html.erb** above:
|
|
184
|
+
|
|
185
|
+
```ruby
|
|
186
|
+
replace: "[data-hook='product_show']"
|
|
187
|
+
|
|
188
|
+
insert_top: "#thumbnails[data-hook]"
|
|
189
|
+
|
|
190
|
+
remove: "[data-hook='cart_form']"
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
You can also use a combination of both styles of selectors in a single override to ensure maximum protection against changes:
|
|
194
|
+
|
|
195
|
+
```ruby
|
|
196
|
+
insert_top: "[data-hook='thumbnails'], #thumbnails[data-hook]"
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Targeting ruby blocks
|
|
200
|
+
|
|
201
|
+
Deface evaluates all the selectors passed against the original erb view contents and importantly not against the finished / generated HTML. In order for Deface to make ruby blocks contained in a view parseable they are converted into a pseudo markup as follows.
|
|
202
|
+
|
|
203
|
+
Given the following Erb file:
|
|
204
|
+
|
|
205
|
+
```erb
|
|
206
|
+
<%% if products.empty? %>
|
|
207
|
+
<%%= Spree.t(:no_products_found) %>
|
|
208
|
+
<%% elsif params.key?(:keywords) %>
|
|
209
|
+
<h3><%%= Spree.t(:products) %></h3>
|
|
210
|
+
<%% end %>
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Would be seen by Deface as:
|
|
214
|
+
|
|
215
|
+
```markup
|
|
216
|
+
<!-- <html>
|
|
217
|
+
<erb[silent]> if products.empty? </erb>
|
|
218
|
+
<erb[loud]> Spree.t(:no_products_found) </erb>
|
|
219
|
+
<erb[silent]> elsif params.key?(:keywords) </erb>
|
|
220
|
+
|
|
221
|
+
<h3><erb[loud]> Spree.t(:products) </erb></h3>
|
|
222
|
+
|
|
223
|
+
<erb[silent]> end </erb>
|
|
224
|
+
</html> -->
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
So you can target ruby code blocks with the same standard CSS3 style selectors, for example:
|
|
228
|
+
|
|
229
|
+
```ruby
|
|
230
|
+
replace: "erb[loud]:contains('t(:products)')"
|
|
231
|
+
|
|
232
|
+
insert_before: "erb[silent]:contains('elsif')"
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### View upgrade protection
|
|
236
|
+
|
|
237
|
+
To ensure upgrading between versions of Spree is as painless as possible, Deface supports an `:original` option that can contain a string of the original content that's being replaced. When Deface is applying the override it will ensure that the current source matches the value supplied and will output to the Rails application log if they are different.
|
|
238
|
+
|
|
239
|
+
These warnings are a good indicator that you need to review the source and ensure your replacement is adequately replacing all the functionality provided by Spree. This will help reduce unexpected issues after upgrades.
|
|
240
|
+
|
|
241
|
+
Once you've reviewed the new source you can update the `:original` value to new source to clear the warning.
|
|
242
|
+
|
|
243
|
+
Deface removes all whitespace from both the actual and \`:original\` source values before comparing, to reduce false warnings caused by basic whitespace differences.
|
|
244
|
+
|
|
245
|
+
### Organizing Overrides
|
|
246
|
+
|
|
247
|
+
The suggested method for organizing your overrides is to create a separate file for each override inside the **app/overrides** directory, naming each file the same as the **:name** specified within.
|
|
248
|
+
|
|
249
|
+
### More information on Deface
|
|
250
|
+
|
|
251
|
+
For more information and sample overrides please refer to its [README](https://github.com/spree/deface) file on GitHub.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Images
|
|
3
|
+
version: v4
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Overview
|
|
7
|
+
|
|
8
|
+
This guide explains how to change Product Images dimensions and different storage options for [ActiveStorage](https://edgeguides.rubyonrails.org/active_storage_overview.html) which is the default attachment storage system in Spree.
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## Dimensions
|
|
12
|
+
|
|
13
|
+
To change the default image dimensions or add new ones you need to create a decorator file:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
mkdir -p app/models/spree && touch app/models/spree/image_decorator.rb
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
with the following content:
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
module Spree
|
|
23
|
+
module ImageDecorator
|
|
24
|
+
module ClassMethods
|
|
25
|
+
def styles
|
|
26
|
+
{
|
|
27
|
+
# change existing default sizes used in Admin Panel and API
|
|
28
|
+
mini: '48x48>',
|
|
29
|
+
small: '100x100>',
|
|
30
|
+
product: '240x240>',
|
|
31
|
+
large: '600x600>',
|
|
32
|
+
# add your new size here, which will be automatically available in the API
|
|
33
|
+
my_custom_size: '1000x1000>'
|
|
34
|
+
}
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.prepended(base)
|
|
39
|
+
base.inheritance_column = nil
|
|
40
|
+
base.singleton_class.prepend ClassMethods
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
Image.prepend(ImageDecorator)
|
|
45
|
+
end
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Using image variations in templates
|
|
49
|
+
|
|
50
|
+
You can also create [image variations on the fly in your templates](https://guides.rubyonrails.org/active_storage_overview.html), eg.
|
|
51
|
+
|
|
52
|
+
```erb
|
|
53
|
+
<%= image_tag(main_app.url_for(@product.images.first.attachment.variant(resize: '150x150'))) %>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Storage service
|
|
57
|
+
|
|
58
|
+
By default Spree will use the storage service you have set in your environment file eg. `config/environments/development.rb`:
|
|
59
|
+
|
|
60
|
+
```ruby
|
|
61
|
+
config.active_storage.service = :amazon
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
If you have multiple storage services you can customize which storage service to use for images. This is done in the `config/initializers/spree.rb`:
|
|
65
|
+
|
|
66
|
+
```ruby
|
|
67
|
+
Spree.public_storage_service_name = :amazon
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The storage name needs to match the name you configured in `config/storage.yml`.
|
|
71
|
+
|
|
72
|
+
## Using CDNs
|
|
73
|
+
|
|
74
|
+
To use a CDN service such as AWS Cloudfront or Cloudflare, you need to set `Spree.cdn_host` to the hostname of your CDN service. This is done in the `config/initializers/spree.rb`:
|
|
75
|
+
|
|
76
|
+
```ruby
|
|
77
|
+
Spree.cdn_host = 'https://mycloudfrontserviceid.cloudfront.net'
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Spree will handle the rest as we have a built-in reverse proxy for ActiveStorage.
|
|
81
|
+
|
|
82
|
+
To use CDN in your templates please use `cdn_image_url` helper:
|
|
83
|
+
|
|
84
|
+
```erb
|
|
85
|
+
<%= main_app.cdn_image_url(@product.images.first.attachment.variant(resize: '150x150')) %>
|
|
86
|
+
```
|