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

Inject multiple times to the same file #36

Closed
GuyPie opened this issue Mar 14, 2018 · 7 comments
Closed

Inject multiple times to the same file #36

GuyPie opened this issue Mar 14, 2018 · 7 comments

Comments

@GuyPie
Copy link

GuyPie commented Mar 14, 2018

When trying to inject multiple times to the same file, only one of the injections applies.

@jondot
Copy link
Owner

jondot commented Mar 14, 2018

Hi! currently this is by design. Multiple different injections require multiple different files. If you have a ton of injections, which make up most of the content of a file, consider rebuilding the entire file with generators each time.

@GuyPie
Copy link
Author

GuyPie commented Mar 14, 2018

That was fast! Unfortunately re-generating the entire file isn't possible for me, specifically what I'm trying to do is add an import to a file and then use that import, so I need to insert two non-consecutive lines, but I don't want the rest of the file to change, nor can I tell what its current content is.

@tobmaster
Copy link
Contributor

@GuyPie You can write multiple template files that target the same file but different before/after locations.
e.g:
01_inject_a_file.txt

---
to: path/to/file.txt
inject: true
after: LOCATION_A
---
first injection

02_inject_b_file.txt

---
to: path/to/file.txt
inject: true
after: LOCATION_B
---
second injection

That way you should be able to achive your goal while separating the different "concerns".

Hope it helps

@GuyPie
Copy link
Author

GuyPie commented Mar 14, 2018

Thanks @tobmaster, but that's exactly what I tried initially and it doesn't work - what ends up happening is only one the injections takes effect.

@tobmaster
Copy link
Contributor

Oh, I thought I tried that before. Then sorry for misleading you. I will retry it

@tobmaster
Copy link
Contributor

tobmaster commented Mar 14, 2018

I retried it successfully in hygen 1.4.8 with this:
https://gist.github.com/tobmaster/8489f1b0a850216c73c2619144a69e90

It produced in some/target.txt

We say:
Salve

Hello


to

- John

- Maria

Have you checked the regex for insertion?

@GuyPie
Copy link
Author

GuyPie commented Mar 14, 2018

You're right! I had a skip_if that stopped it from working. Sorry, closing this.

@GuyPie GuyPie closed this as completed Mar 14, 2018
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

3 participants