Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

[WIP] Slate Sections Plugin #982

Merged
merged 57 commits into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
d855a38
initial commit
Feb 7, 2019
7c422ee
oops
Feb 7, 2019
5506a74
tests
Feb 15, 2019
801db79
working plugin, tests need to be redone
Feb 18, 2019
8828fdd
Basic tests and forgot schema tag
Feb 19, 2019
805da12
Using lodash instead of manual recursion
Feb 19, 2019
b41a1e9
initial commit
Feb 7, 2019
63927c8
oops
Feb 7, 2019
6541b7a
tests
Feb 15, 2019
652290a
working plugin, tests need to be redone
Feb 18, 2019
6fdf028
Basic tests and forgot schema tag
Feb 19, 2019
c92a131
Using lodash instead of manual recursion
Feb 19, 2019
db82238
accept head yarn.lock
Feb 19, 2019
1badb00
Working towards pr review
Feb 20, 2019
431ee19
More descriptive test names, using config values
Feb 20, 2019
c6323d8
Lot of changes to clean up
Feb 21, 2019
46d1c12
clean up eslint warnings
Feb 21, 2019
48c7b6f
More descriptive tests and updated tests
Feb 21, 2019
0b750fd
Rename test file as per request
Feb 21, 2019
bb49649
Simplifying snapshots
Feb 21, 2019
95b7fd8
Some detailed comments
Feb 21, 2019
1bb3f24
Forgot to document a function
Feb 21, 2019
5bf2bcf
Removing manual path manipulation, and making generic template name a…
Feb 25, 2019
804641f
using readJson instead of parsing readfile
Feb 25, 2019
78b51a8
Move plugin to core webpack instead of prod
Feb 25, 2019
9fab84d
One source of changes to compilation assets
Feb 26, 2019
ecc2cf5
Assigning output key to variable in test suite
Feb 26, 2019
048ffa2
Option Validation
Feb 28, 2019
ce2131c
Unnecessary parameter
Feb 28, 2019
fd68bd4
Initial README
Mar 1, 2019
b6a8b1d
Minor reviesions
Mar 1, 2019
f0f5be0
Validate Options refactor, and name/version changes
Mar 1, 2019
b067420
ReadME changes
Mar 1, 2019
e4bfad2
Fix typo in package.json
Mar 4, 2019
454f2ff
Update packages/slate-sections-plugin/README.md
t-kelly Mar 4, 2019
303db58
Getting through yarn lint
Mar 4, 2019
f3cc03f
prettifying the json output
Mar 4, 2019
e863841
Remove default option from example in readme
Mar 4, 2019
ce395bd
Left some debugger statements
Mar 4, 2019
1d4dea6
Update packages/slate-sections-plugin/index.js
Mar 5, 2019
0cddf60
Update packages/slate-sections-plugin/README.md
Mar 5, 2019
acc5950
Update packages/slate-sections-plugin/README.md
Mar 5, 2019
a93b9df
Update packages/slate-sections-plugin/README.md
Mar 5, 2019
626f215
Update packages/slate-sections-plugin/README.md
Mar 5, 2019
1f8e920
Update packages/slate-sections-plugin/README.md
Mar 5, 2019
2196044
Update packages/slate-sections-plugin/README.md
Mar 5, 2019
75d0ce3
Update packages/slate-sections-plugin/README.md
Mar 5, 2019
8ffc188
Update packages/slate-sections-plugin/README.md
Mar 5, 2019
456de58
Update packages/slate-sections-plugin/README.md
Mar 5, 2019
a923148
Update packages/slate-sections-plugin/README.md
Mar 5, 2019
0231bdd
Update packages/slate-sections-plugin/README.md
Mar 5, 2019
ea664ff
Update packages/slate-sections-plugin/README.md
Mar 5, 2019
ecee588
Update packages/slate-sections-plugin/README.md
Mar 5, 2019
3fdd03d
Update packages/slate-sections-plugin/README.md
Mar 5, 2019
f12958c
Update packages/slate-sections-plugin/README.md
Mar 5, 2019
850139e
Update packages/slate-sections-plugin/index.js
Mar 5, 2019
af56e04
Changing based on PR requests
Mar 5, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@
"name": "slate",
"private": true,
"author": "Shopify Inc.",
"description": "A theme scaffold and command line tool for developing Shopify themes.",
"keywords": [
"slate",
"shopify",
"theme",
"CLI"
],
"description":
"A theme scaffold and command line tool for developing Shopify themes.",
"keywords": ["slate", "shopify", "theme", "CLI"],
"engine": ">=8.9.4",
"homepage": "https://shopify.github.io/slate/",
"bugs": "https://github.com/Shopify/slate/issues",
Expand Down Expand Up @@ -47,7 +43,5 @@
"trailingComma": "es5",
"bracketSpacing": false
},
"workspaces": [
"packages/*"
]
"workspaces": ["packages/*"]
}
166 changes: 166 additions & 0 deletions packages/slate-sections-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# @shopify/slate-sections-plugin

The plugin handles the taking your sections folder, and outputting files that will work in production. There are 2 supported sections folder structures.
harshal317 marked this conversation as resolved.
Show resolved Hide resolved

## How to use
harshal317 marked this conversation as resolved.
Show resolved Hide resolved

First install the plugin

```
npm install @shopify/slate-sections-plugin --save-dev
```

or

```
yarn add @shopify/slate-sections-plugin --dev
```

Then add it to your webpack config, an example below.

```js
const SlateSectionsPlugin = require('@shopify/slate-sections-plugin');

const slateSectionsOptions = {
from: '/absolute/path/to/sections/source',
to: '/absolute/path/to/sections/output',
genericTemplateName: 'template.liquid',
harshal317 marked this conversation as resolved.
Show resolved Hide resolved
};

module.exports = {
plugins: [new SlateSectionsPlugin({slateSectionsOptions})],
};
```

## Options

| Option | Required? | Type | Default | Description |
| ------------------- | --------- | ------ | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| from | Yes | String | undefined | The absolute path to the folder containing your sections, typically ./src/sections |
| to | Yes | String | undefined | The absolute path to the folder where your sections will be outputted to, typically ./dist/sections |
| genericTemplateName | No | String | 'template.liquid' | If you're using the 'Sections as Folders' structure, your template names by default need to be 'template.liquid'. You may change this value if you would like to. |

## Sections as Liquid Files

You may structure your sections folder such that it exists of simply liquid templates which will get copied into the build.
harshal317 marked this conversation as resolved.
Show resolved Hide resolved

```bash
./sections
├── blog-posts.liquid
├── collection-list.liquid
├── featured-collection.liquid
├── featured-product.liquid
├── footer.json
harshal317 marked this conversation as resolved.
Show resolved Hide resolved
├── footer.liquid
├── header.liquid
├── image-with-text.liquid
├── newsletter.liquid
├── product.liquid
└── rich-text.liquid
```

This structure simply tells the plugin to copy the liquid files into the dist sections folder
harshal317 marked this conversation as resolved.
Show resolved Hide resolved

## Sections as Folders

You may separate your schema from your liquid by creating a folder for your section. This increases maintainability and provides syntax highlighting on your json objects.
harshal317 marked this conversation as resolved.
Show resolved Hide resolved

In order to have separate schema files, you must create a folder for the section and within that folder you need a `template.liquid` which will take the name of the directory it is in, and you may optionally have a `schema.json` file with contents that will be appended to the liquid in `{% schema %}` tags.
harshal317 marked this conversation as resolved.
Show resolved Hide resolved

### Example

```bash
./sections/article-template
├── schema.json
└── template.liquid
```

This will create an `article-template.liquid` with the contents of the `template.liquid` file and with json wrapped in `{% schema %}` tags, which will be outputted to the sections dist folder.
harshal317 marked this conversation as resolved.
Show resolved Hide resolved

## Translations

If you need settings in your schema that require multiple translations, you could specify that by doing as such
harshal317 marked this conversation as resolved.
Show resolved Hide resolved

```json
{
"name": {
"de": "Posts",
"en": "Posts",
"es": "Publicaciones",
"fr": "Articles",
"it": "Articoli",
"ja": "投稿",
"pt-BR": "posts"
},
"settings": [
{
"type": "checkbox",
"id": "image_parallax",
"label": {
"de": "Parallax-Animation für Bild anzeigen",
"en": "Show image parallax animation",
"es": "Mostrar animación de paralaje de imagen",
"fr": "Afficher l'animation en parallaxe",
"it": "Mostra animazione parallasse immagine",
"ja": "画像のパララックスアニメーションを表示する",
"pt-BR": "Exibir animação de paralaxe da imagem"
}
}
]
}
```

However as the number of languages add up for your theme, and when you have many settings that require translations, this can result in a very large json file that becomes difficult to maintain. This plugin allows you to seperate the translations into different files increasing the maintainability of your project.
harshal317 marked this conversation as resolved.
Show resolved Hide resolved

First you specify your main schema (`schema.json`) as such,
harshal317 marked this conversation as resolved.
Show resolved Hide resolved

```json
{
"name": {
"t": "name"
},
"settings": [
{
"type": "checkbox",
"id": "image_parallax",
"label": {
"t": "settings.image_parallax.label"
}
}
]
}
```

For every key with multiple translations you specify an object with a `t` key and its value is the key to retrieve the translation from a different json object as the one shown below. You would have a translation object such as the one below for every language you would like to support.
harshal317 marked this conversation as resolved.
Show resolved Hide resolved

```json
{
"name": "Posts",
"settings": {
"image_parallax": {
"label": "Show image parallax animation",
"info": "Only shows on desktop"
}
}
}
```

The plugin will take care of combining all the translations into an object such as the one displayed initially. To specify the locale code of your json file, you must name it [`localecode`].json
harshal317 marked this conversation as resolved.
Show resolved Hide resolved

Below is an example of what your section's folder may look like.
harshal317 marked this conversation as resolved.
Show resolved Hide resolved

```json
./sections/article-template
├── locales
│   ├── de.json
│   ├── en.json
│   ├── es.json
│   ├── fr.json
│   ├── it.json
│   ├── ja.json
│   └── pt-BR.json
├── schema.json
└── template.liquid
```

This will all get combined and outputted into a single `article-template.liquid`
harshal317 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`section that has template living in folders with schema.json and no locales 1`] = `undefined`;

exports[`section that has template living in folders with schema.json and no locales 2`] = `undefined`;

exports[`section that has template living in folders with schema.json and no locales 3`] = `
"
<section>
<h2>{{ section.name }}</h2>
</section>

{% schema %}
{
\\"name\\": \\"Test\\"
}
{% endschema %}"
`;

exports[`sections that have templates living in folders with a schema.json and locales to go with aswell 1`] = `
"<div class=\\"article\\" data-section-id=\\"{{ section.id }}\\" data-section-type=\\"article-template\\">
<h1 class=\\"article__title h2\\">{{ article.title }}</h1>
</div>
"
`;

exports[`sections that have templates living in folders with a schema.json and locales to go with aswell 2`] = `
Object {
"name": Object {
"de": "Posts",
"en": "Posts",
"es": "Publicaciones",
"fr": "Articles",
"it": "Articoli",
"ja": "投稿",
"pt-BR": "posts",
},
"settings": Array [
Object {
"id": "image_parallax",
"info": Object {
"de": "Wird nur auf dem Desktop angezeigt",
"en": "Only shows on desktop",
"es": "Solo se muestra en el escritorio",
"fr": "Ne s'affiche que sur le bureau",
"it": "Appare solo su desktop",
"ja": "デスクトップにのみ表示する",
"pt-BR": "Aparece apenas na área de trabalho",
},
"label": Object {
"de": "Parallax-Animation für Bild anzeigen",
"en": "Show image parallax animation",
"es": "Mostrar animación de paralaje de imagen",
"fr": "Afficher l'animation en parallaxe",
"it": "Mostra animazione parallasse immagine",
"ja": "画像のパララックスアニメーションを表示する",
"pt-BR": "Exibir animação de paralaxe da imagem",
},
"type": "checkbox",
},
],
}
`;

exports[`sections with no seperate schemas, with liquid files that just need to be copied over 1`] = `undefined`;

exports[`sections with no seperate schemas, with liquid files that just need to be copied over 2`] = `
"
<section>
<h2>{{ section.name }}</h2>
</section>

{% schema %}
{
\\"name\\": \\"Test\\",
}
{% endschema %}
"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "Posts",
"settings": {
"image_parallax": {
"label": "Parallax-Animation für Bild anzeigen",
"info": "Wird nur auf dem Desktop angezeigt"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "Posts",
"settings": {
"image_parallax": {
"label": "Show image parallax animation",
"info": "Only shows on desktop"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "Publicaciones",
"settings": {
"image_parallax": {
"label": "Mostrar animación de paralaje de imagen",
"info": "Solo se muestra en el escritorio"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "Articles",
"settings": {
"image_parallax": {
"label": "Afficher l'animation en parallaxe",
"info": "Ne s'affiche que sur le bureau"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "Articoli",
"settings": {
"image_parallax": {
"label": "Mostra animazione parallasse immagine",
"info": "Appare solo su desktop"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "投稿",
"settings": {
"image_parallax": {
"label": "画像のパララックスアニメーションを表示する",
"info": "デスクトップにのみ表示する"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "posts",
"settings": {
"image_parallax": {
"label": "Exibir animação de paralaxe da imagem",
"info": "Aparece apenas na área de trabalho"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": {
"t": "name"
},
"settings": [
{
"type": "checkbox",
"id": "image_parallax",
"label": {
"t": "settings.image_parallax.label"
},
"info": {
"t": "settings.image_parallax.info"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="article" data-section-id="{{ section.id }}" data-section-type="article-template">
<h1 class="article__title h2">{{ article.title }}</h1>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Test"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

<section>
<h2>{{ section.name }}</h2>
</section>

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

<section>
<h2>{{ section.name }}</h2>
</section>

{% schema %}
{
"name": "Test",
}
{% endschema %}
Loading