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

slate-sections-plugin - allow the .liquid file to match the folder name #1043

Open
justinmetros opened this issue Jul 1, 2019 · 1 comment

Comments

@justinmetros
Copy link

Problem

Feature Request:
When using the new Sections Plugin w/ folder structure ( very cool to be able to get syntax highlighting on the JSON ) - you end up with a ton of files named template.liquid which makes using them in an editor a little confusing. All the tabs are named template.liquid.

If would be cool if you could specify a wildcard for this.options.genericTemplateName so that it looks for a liquid file the same as its folder.

Maybe something like:

const slateSectionsOptions = {
  from: '/absolute/path/to/sections/source',
  to: '/absolute/path/to/sections/output',
  genericTemplateName: '*'
};

or

const slateSectionsOptions = {
  from: '/absolute/path/to/sections/source',
  to: '/absolute/path/to/sections/output',
  genericTemplateName: `${folderName}.liquid`
};

So instead of:

sections/header/template.liquid

we could do

sections/header/header.liquid

This would make using this folder structure on larger projects a bit easier to reason about with lots of files open in an editor.

Replication steps

None. Its currently behaving as outlined in docs.

More Information

I see this is tied to locales so when I tried to get this working I broke that. If I can find some time will try to put together a pull request with proper tests. But if any experts have a hotfix I could use on this specific project, thats awesome. Thanks, and great work on this!

@justinmetros
Copy link
Author

justinmetros commented Jul 1, 2019

Update:
Ugly fork here that breaks all tests, but otherwise seems to work?

Looks like it should accept any .liquid file in a folder and rename it to folderName.liquid.
i.e.
/src/sections/header/foo.liquid -> /dist/sections/header.liquid

To get locales to work the filename needs to match the folder name: /src/sections/header/header.liquid -> /dist/sections/header.liquid

This is a horrible mess I made here but it is keeping my editor nice and easy to navigate. Needs error checking and tests.

If anyone thinks this is a good idea, could probably clean it up and make some tests for a PR.

Also, maybe this all goes out the window if we start to do nested folders? Anyways, thanks in advance! Appreciate all your work on Slate :)

Edit: A few other benefits with this I noticed - finding files is A LOT easier ( using VSCode at least ). Also started putting the sectionName.js files in the sections folder so its all together and the .liquid and .js files are named the same. This feels like a better pattern than putting js in scripts/sections because its all together and just import it in the relevant template files.

Screen Shot 2019-07-01 at 8 39 01 PM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant