metalsmith / layouts

A metalsmith plugin for layouts
MIT License
116 stars 49 forks source link

Feature/directory fallback #98

Closed zakhenry closed 8 years ago

zakhenry commented 8 years ago

Includes #97 as this PR is depended on it

Closes #97

doodzik commented 8 years ago

Thank you for your PR.

Can you give us your reasoning behind this feature.

zakhenry commented 8 years ago

Hi, the feature is basically for layout inheritance. In my case a module provides a basic layout that a developer can override the default layouts/partials if they desire.

zakhenry commented 8 years ago

Snippet of my metalsmith config file:

.use(layouts({
      engine: 'handlebars',
      directory: pathConfig.templates,
      directoryFallback: __dirname + '/templates',
      partials: pathConfig.partials,
      partialsFallback: __dirname + '/templates/partials',
      exposeConsolidate: (requires) => {
        requires.handlebars = handlebars;
      }
    }))

Note that the fallbacks are in the current module, but the "parent" npm module passes in configuration to pathConfig.partials which are checked first.

doodzik commented 8 years ago

Wouldn't it be more feasible to put this functionality into its own metalsmith-plugin?

zakhenry commented 8 years ago

Possibly, but only if metalsmith provided a file retrieval api (that all other plugins used) for reading files as plugins like this one read the filesystem directly.

ismay commented 8 years ago

@zakhenry Layout inheritance is already possible with metalsmith-in-place and languages like swig or nunjucks (i.e. languages that support inheritance). Metalsmith-layouts is meant as a (simple) shim for languages that don't support inheritance.

I would like to refrain from complicating metalsmith-layouts by adding features for inheritance, and instead like to point you to metalsmith-in-place which already serves that purpose. Closing, but feel free to keep the discussion going if you feel otherwise.

zakhenry commented 8 years ago

@ismay I understand the desire to avoid complication, and am happy to have this feature remain shelved, however I disagree that this specific feature is doable with metalsmith-in-place & nunjucks for example. Their template inheritance pattern does not allow for lazy overloading of templates which this pr addresses.

I probably have a very unique case anyway, with the metalsmith configuration residing in a child npm module with it's fallbacks there too.

zakhenry commented 8 years ago

If anyone else comes across this thread and would like this feature, I have deployed to https://www.npmjs.com/package/@xiphiaz/metalsmith-layouts

ismay commented 8 years ago

Yeah I understand.

I probably have a very unique case anyway, with the metalsmith configuration residing in a child npm module with it's fallbacks there too.

Yeah I think this is beyond what most people use this module for. If we implement it there probably won't be a lot of people that use it, and it could cause confusion. Good idea to publish a fork! 👍