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

Feature Request: Allow datasources to be defined dynamically #349

Closed
osterman opened this issue Jul 3, 2018 · 6 comments
Closed

Feature Request: Allow datasources to be defined dynamically #349

osterman opened this issue Jul 3, 2018 · 6 comments

Comments

@osterman
Copy link

osterman commented Jul 3, 2018

what

  • Provide a getJSON and getYAML functions

why

  • Very common format for APIs and source files
  • Inline interpolation
  • The current --data parameter is insufficient for dynamic use cases (e.g. range over a list); it requires the caller to know in advance all the data endpoints

use-cases

Related

The immensely popular hugo CMS framework provides this method.

@hairyhenderson
Copy link
Owner

@osterman I've had thoughts in the past about being able to define datasources inline, which may be a good general-case way to achieve what you're looking for.

Something like:

{{ $d := datasource "https://github.com/cloudposse/geodesic/blob/master/README.yaml" }}
...

The idea is that the datasource function would recognize the first argument (which is supposed to be the datasource alias) as non-existant, but also as a URL, so it would allow it and dynamically add it to the list of datasources.

Another approach, which may help with re-use:

{{ $d := datasource "somealias=https://github.com/cloudposse/geodesic/blob/master/README.yaml" }}
...
{{ datasource "somealias" }} <- this now refers to the same datasource

Or it may even make more sense to not overload the datasource function and introduce a new function:

{{ defineDatasource "somealias" "https://github.com/cloudposse/geodesic/blob/master/README.yaml" }}
{{ $d := datasource "somealias" }}
...

I think I prefer this last one since it separates concerns... This could interact nicely with the -d flag, where the commandline overrides the defineDatasource function.

What do you think?

@osterman
Copy link
Author

osterman commented Jul 8, 2018

Your proposal sounds wonderful. I don't have a strong preference either way on the interface. I see the benefits of having a defineDatasource, albeit for my use-case not necessary. Also, the somealias would need to be dynamic when in the context of a range - thus providing limited utility and more complicated template code. For my use-case, your first example is most preferable.

@hairyhenderson
Copy link
Owner

Thanks for the feedback, @osterman - TBH I don't see why I can't support both the bare-url approach (first example) as well as the defineDatasource approach. They're slightly different depending on the use-case.

It turns out that defineDatasource seems to be a decent way to define a default datasource URL - something that could be very useful in shared templates with shared datsources. It's annoying to have to know all the -d arguments that have to be defined in order for the template to even render!

I think I'll implement both of these.

@osterman
Copy link
Author

It turns out that defineDatasource seems to be a decent way to define a default datasource URL

Yes, very nice indeed.

It's annoying to have to know all the -d arguments that have to be defined in order for the template to even render!

Yes, this has been a pain-point for us as well.

@hairyhenderson hairyhenderson changed the title Feature Request: Support for getJSON function Feature Request: Allow datasources to be defined dynamically Jul 27, 2018
@osterman
Copy link
Author

osterman commented Aug 1, 2018

Wow! @hairyhenderson didn't expect you would implement that so quickly. Eager to go check this out. Thanks again!

@hairyhenderson
Copy link
Owner

@osterman you're welcome! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants