kickstart icon indicating copy to clipboard operation
kickstart copied to clipboard

Clarify copy_without_render

Open cdlm opened this issue 1 year ago • 6 comments

It's not clear what copy_without_render will be matched against and how.

Judging from the source code the glob pattern is used as-is, against the "real" path (fully resolved in the filesystem? relative to output directory?) of the destination where the template file would be copied to, but:

  • does that include the output directory (--output-dir CLI option) ?
  • it doesn't seem like template variables are expanded in the glob, which makes it impossible to match individual files when those have templated names (say I need to render most files in template/there/*.html except for template/there/{{name}}.html)
  • what about matching template-relative paths (so, the source files)?

cdlm avatar Oct 10 '24 08:10 cdlm

  1. Not sure, would have to test it
  2. Correct, they are not templated right now it could be added
  3. Ideally that's how it would work

Keats avatar Oct 11 '24 11:10 Keats

I've added templating for copy_without_render elements in https://github.com/Keats/kickstart/pull/69 could you try it and come up with a simple template for it as example?

I've also ensured that the globs match without needing to include the directory (whether ./ if running in the current dir or defined via --output-dir) if you want to try.

Keats avatar Dec 05 '24 11:12 Keats

Just tried, seems to work.

I think my usecase was generating a project file with a templated name, but contents with Tera-like syntax that would cause problems… I'll have to try to remember precisely. I've since rewritten the template I needed with cookiecutter and that contains a justfile that uses variables, and a LaTeX file whose name i wanted to be templated, but has stuff wrapped in double braces all over the place.

cdlm avatar Dec 05 '24 13:12 cdlm

Anything else you're missing from cookiecutter? I'm implement pre-gen/post-gen hooks right now

Keats avatar Dec 05 '24 14:12 Keats

Okay I think I found why I wanted copy_without_render to work. A file {{basename}}.tex included macro definitions like:

\newcommand\foo[1]{%
  \texttt{#1}}

I wanted a templated file name, otherwise I might as well do a simple copy. But it was acceptable not rendering the contents: only the document title came from variables, and I often change that anyways once I'm writing.

Tera doesn't like either {% and {#, even between {% raw %}…{% endraw %}. And I can't separate those characters without impacting what the LaTeX code does. With cookiecutter I ended up re-configuring the Jinja2 delimiters to include a non-breaking space inside the braces, bypassing the syntax overlap with LaTeX.

cdlm avatar Dec 05 '24 15:12 cdlm

I see, so rendering the filename/dir name only but not the content. Makes sense.

Keats avatar Dec 05 '24 19:12 Keats