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 templ elements, and templ block elements #51

Merged
merged 16 commits into from
Jun 20, 2022
Merged

Conversation

joerdav
Copy link
Collaborator

@joerdav joerdav commented Jun 8, 2022

No description provided.

@joerdav joerdav changed the title feat: add html-style call templates and block templates feat: add templ elements, and templ block elements Jun 10, 2022
@joerdav
Copy link
Collaborator Author

joerdav commented Jun 10, 2022

@a-h I'm happy that this works as expected now.
Would be good to get your eyes over it first and make sure it's acceptable.
I left callTemplatesExpressions in for backwards compatability, was this right?

Copy link
Owner

@a-h a-h left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is looking good. I've suggested a couple of minor bits and pieces. Nothing major.

parser/v2/expressionparser.go Outdated Show resolved Hide resolved
return templ.ComponentFunc(func(ctx context.Context, w io.Writer) (err error) {
ctx, _ = templ.RenderedCSSClassesFromContext(ctx)
ctx, _ = templ.RenderedScriptsFromContext(ctx)
var_1 := ctx
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to create a variable instead of using ctx directly? I can't see why childrenVar is used, would be good to remove it if possible, just because it's state inside the generator.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was to prevent children being used in components that are nested, I separated it into its own context so that only the { children... } further down can access that context.

If that makes sense.

Otherwise if another templElement was rendered in this component it would get the children passed in, which is bad.

example/posts.templ Outdated Show resolved Hide resolved
generator/test-templ-element/template.templ Outdated Show resolved Hide resolved
generator/test-templ-element/render_test.go Outdated Show resolved Hide resolved
parser/v2/templelementparser_test.go Outdated Show resolved Hide resolved
parser/v2/templelementparser_test.go Outdated Show resolved Hide resolved
parser/v2/templelementparser_test.go Outdated Show resolved Hide resolved
parser/v2/templelementparser_test.go Outdated Show resolved Hide resolved
runtime.go Outdated Show resolved Hide resolved
joerdav and others added 10 commits June 10, 2022 09:14
Co-authored-by: Adrian Hesketh <a-h@users.noreply.github.com>
Co-authored-by: Adrian Hesketh <a-h@users.noreply.github.com>
Co-authored-by: Adrian Hesketh <a-h@users.noreply.github.com>
Co-authored-by: Adrian Hesketh <a-h@users.noreply.github.com>
Co-authored-by: Adrian Hesketh <a-h@users.noreply.github.com>
Co-authored-by: Adrian Hesketh <a-h@users.noreply.github.com>
Co-authored-by: Adrian Hesketh <a-h@users.noreply.github.com>
Co-authored-by: Adrian Hesketh <a-h@users.noreply.github.com>
Co-authored-by: Adrian Hesketh <a-h@users.noreply.github.com>
@joerdav
Copy link
Collaborator Author

joerdav commented Jun 10, 2022

Was thinking of updating the "Write" function of the calltemplate expression to write out the new syntax. So templ fmt would migrate {! render } to @render.

@a-h a-h merged commit 06fdb56 into a-h:main Jun 20, 2022
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.

2 participants