-
-
Notifications
You must be signed in to change notification settings - Fork 190
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
new arg --templates for parsing additional templates #403
new arg --templates for parsing additional templates #403
Conversation
Hi @laher, thanks for the PR! I definitely want to implement support for nested templates, and there's already some discussion in #210 about the right way to implement that support. So far the approach I'm leaning towards is this one: #210 (comment) Would you mind commenting on that issue, and letting me know whether that approach would work for you, or if you have reasons that it wouldn't? |
Interesting, thanks. I don't get why you'd treat templates as data, they're
exactly not the data. I'll reply later today in that thread with a more
thoughtful response :)
…On Wed, Sep 19, 2018, 9:07 AM Dave Henderson ***@***.***> wrote:
Hi @laher <https://github.com/laher>, thanks for the PR!
I definitely want to implement support for nested templates, and there's
already some discussion in #210
<#210> about the right
way to implement that support.
So far the approach I'm leaning towards is this one: #210 (comment)
<#210 (comment)>
Would you mind commenting on that issue, and letting me know whether that
approach would work for you, or if you have reasons that it wouldn't?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#403 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAHrlcXxcthIwebthA2G92tsCbIOXm3yks5ucWCjgaJpZM4Wul4l>
.
|
@hairyhenderson as discussed, I have implemented those local-filesystem use cases 1-4. I did do something differently, but I can change it if it doesn't work for you: I found that the standard library template.ParseFiles(...) uses the basename of the file as the template name, so it felt more natural to follow suit with that. i.e. instead of this: and instead of: I did do the directory-aliasing prefix though: What do you think? |
Yeah - I was a bit conflicted about that. The advantage is, of course, a shorter template name, but the disadvantage is that templates with the same filename in different directories will conflict. It's a relatively minority edge-case, but I'd rather be more explicit about the name, especially when you consider that you can always use an alias like Keeping the path as-is is also more in-line with what you get when you reference a directory, so I think I'd rather the internal consistency over the |
template.go
Outdated
return tp, err | ||
} | ||
for alias, path := range t.additionalTemplates { | ||
b, err := ioutil.ReadFile(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you'll need to add // nolint: gosec
above this line to get the linter to shut up:
template.go:43::warning: Potential file inclusion via variable,MEDIUM,HIGH (gosec)
It's more than a potential file inclusion, it's a deliberate file inclusion, but that's the whole point of this feature 😂
@laher Further to the comment above, this looks good so far, thank you for working on this! And when you get the CI build to pass (should just be a case of appeasing the linter - see inline comments about that), I'll get this merged. I'll follow up later with unit & integration tests, unless you want to add some yourself. This'll also need some changes to documentation - but again, I can take care of that unless you feel like it 😉. It can certainly happen in another PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few comments - see inline. Thanks for doing this work!
I got the CI passing, simplified Re testing: I've been testing manually on the CLI, it seems to work OK, but I think I'd need to rework the code in order to support the afero fs as in |
Thanks @laher - this is great, and I'll merge it at this point. I totally understand needing to switch contexts for a few days, you've already been very generous with your time. I'll merge this now, and will add some tests and docs for this. |
Does this seem like a good approach for loading additional templates like
{{ template "otherfile.tpl" }}
?I think couldn't think what to call the CLI arg - maybe
--additional-templates
is better, but here's a straw man.Cheers, great project, just this one thing missing IMO 👍 💯 ❤️