Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating jinja2 templates from example files which have static values #25

Open
jayvdb opened this issue May 29, 2018 · 6 comments
Open
Milestone

Comments

@jayvdb
Copy link
Member

jayvdb commented May 29, 2018

An idea I had was wanted to have some templates which are jinja-ified versions of example files.

The best way to explain it is with a real case.

https://github.com/ogrisel/python-appveyor-demo is an example repo that I have helped build.

While I could possibly moban-ise it, I am not sure the main maintainer would agree, as that repo is supposed to look easy, and moban looks complicated ;-)

I can use the new copy: to obtain the two files in https://github.com/ogrisel/python-appveyor-demo/tree/master/appveyor

However I want a jinja-ified version of https://github.com/ogrisel/python-appveyor-demo/blob/master/appveyor.yml

I could manually build the jinja version, but I would prefer the template to be automatically maintained whenever the source file is updated.

Essentially, I need to go backwards. file -> template

One way to achieve this is for files to be generated from jinja2 global functions, ala #23

@chfw
Copy link
Member

chfw commented May 29, 2018

I have done some similar thing: write change log in yml and get them into changelog.rst. You can check if it is related to your thinking.

Reference:

https://github.com/moremoban/moban/blob/master/mobanfile#L11
https://github.com/moremoban/pypi-mobans/blob/master/templates/CHANGELOG.rst.jj2

@jayvdb
Copy link
Member Author

jayvdb commented May 30, 2018

moremoban/pypi-mobans#21 (comment) is more what I mean --- sometimes an upstream example file, or a upstream template, has some literal text which needs to be removed or replaced. This is a copy+fix type problem, and I'd love to use moban for that.

@chfw
Copy link
Member

chfw commented May 30, 2018

this is reverse the direction of moban. What moban does is take a template and a data dict and produce templated output. now, the reverse is: take a templated file and apply some "magic" then produce the template, which can be used in forward direction.

I wondered how to generalize the "magic". When I did CHANGELOG.rst -> changelog.yml + changelog.rst.jj2, the "magic" is specific to CHANGELOG.rst in my style.

@jayvdb
Copy link
Member Author

jayvdb commented May 30, 2018

Only magic I can think of is allowing a list of regex transforms for each target. While it would be more common to use with copy , regex could also be used after templating as quick fixes to temporarily workaround limitations of any upstream templates.

@jayvdb
Copy link
Member Author

jayvdb commented Jun 7, 2018

This could be done as a template engine, which looks for configuration values and replaces them with the configuration keys.

@jayvdb
Copy link
Member Author

jayvdb commented Jun 8, 2018

@jayvdb jayvdb added this to the 0.6.0 milestone Jan 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants