pingy-cli icon indicating copy to clipboard operation
pingy-cli copied to clipboard

how to add data.json to pug rendering?

Open afknapping opened this issue 7 years ago • 1 comments

I wonder how I can pass data into the pug rendering process.

I found this:

...with something like render(view, { locals: { projects: myObjectHere }})

but would want to have that in a seperate json or even better yml file.

if that is not currently possible (which i guess), where would i hack that in? for example, i found pug being mentioned in node_modules/@pingy/compile/lib/compile.js but not sure where or how to continue from there...

My usecase is having text snippets I want to use consistently through the UI and change them in one place only... like the copy "continue" in some buttons and the like...

afknapping avatar Nov 03 '18 11:11 afknapping

Yes, it's not supported. Happy to take PRs though because it's a useful feature.

If you wanted to pass in extra options to Pug then you would add it to the transpilerOptions object here.

You could do something like check if the engine is pug and then search for a json file that has your locals in it.

if (adapter.engineName === 'pug') {
  const parentDir = path.basename(pathName)
  const dataPath = path.join(parentDir, 'data.json')
  // TODO: Check if dataPath exists and is valid JSON
  // TODO: If it exists then read the json and add it to `transpilerOptions`
}

davej avatar Nov 03 '18 12:11 davej