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

feat: add arbitrary go code support #713

Merged
merged 6 commits into from
May 12, 2024
Merged

Conversation

joerdav
Copy link
Collaborator

@joerdav joerdav commented Apr 30, 2024

Closes #109

TODO:

  • Add docs
  • Add feature flag

@joerdav
Copy link
Collaborator Author

joerdav commented May 7, 2024

I've made a first pass at the experiment functionality. Next I'll look at documentation.

I do think that package level vars are the best way to do this without affecting the rest of the code massively, or causing a performance impact. Let me know what you think, happy to change, this approach was made basically copying and simplifying the GOEXPERIMENT code.

@a-h
Copy link
Owner

a-h commented May 12, 2024

I tried to add a generator test, but realised that the generator test couldn't run without the experiment being enabled, which complicated execution of the CI/CD processes, so best leave it for now.

I renamed TEMPLEXPERIMENT because it was messing with my eyes. I kept seeing TEMPLEX.

But I noticed the formatting of b := func() got a little messed up by the formatter.

package testfor

templ render(items []string) {
	{{ a := "a" }}
	<div>{ a }</div>
	{{b := func() string {
	return "b"
}
	}}
	<div>{ b() }</div>
	{{
	c := func() (string, error) {
		return "c", nil
	}
	}}
	<div>{ c() }</div>
}

Looks great!

@a-h a-h merged commit 750f91e into a-h:main May 12, 2024
@joerdav
Copy link
Collaborator Author

joerdav commented May 12, 2024

Good shout on those amends! Maybe worth us adding an experiment field to the editor plugins that allow for config so things like this can easily be enabled on the LSP.

@joerdav joerdav deleted the arbitrary-go-code branch May 14, 2024 14:33
@adpande
Copy link

adpande commented May 29, 2024

This is really awesome! I am already using it to generate random strings as ids in components. I dont have to pass them now as function parameters.

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

Successfully merging this pull request may close these issues.

generator: allow go code statements in templates
3 participants