yeojz / metalsmith-react-templates

A metalsmith plugin to render files using React / Preact / JSX based templates.
MIT License
92 stars 17 forks source link

Use of templateTag? #54

Closed benpolinsky closed 6 years ago

benpolinsky commented 7 years ago

Hi,

I'm attempting to use a different templateTag to render my contents into, but I'm having difficulty getting anything to work.

Do you just pass a function to templateTag?

reactTemplates({ templateTag: function(key){return new RegExp(pattern, 'g')} })

Looking through the code, I couldn't find the part where you were checking the options and applying a new templateTag based on this function.

yeojz commented 7 years ago

Hi @benpolinsky

Yes that is correct. The default is

const DEFAULT_PATTERN = (key) => (
  new RegExp(`{{${key}}}`, 'g')
);

and it can be found here: https://github.com/yeojz/metalsmith-react-templates/blob/master/src/jsx-render-engine/strategy/naive.js

It will be called when we're replacing values in the baseFile https://github.com/yeojz/metalsmith-react-templates/blob/master/src/jsx-render-engine/utils/applyBaseFile.js

yeojz commented 6 years ago

Closing this. Please re-open if you still have issues.