Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: add basic templ support #98

Merged
merged 1 commit into from
Jul 3, 2024

Conversation

tommsawyer
Copy link
Contributor

Added basic support for templ files. Docs for templ commenting here: https://templ.guide/syntax-and-usage/comments

In general we are using html-style comments inside components, and go-style comments outside.

@haydenrou
Copy link

Something like this would be awesome out of the box, thanks!

I've added the solution to my own dotfiles here for the time-being. It works great except for one thing - the templ builtin function templ myComponent() { will be commented like <!-- templ myComponent() { -->. Is that something we could accommodate for?

@JoosepAlviste
Copy link
Owner

JoosepAlviste commented Mar 26, 2024

Hey, thanks for the PR! Supporting templ makes a lot of sense since it seems to be very similar to JSX.

In order to handle the templ myComponent() { line correctly, I think that we can use component_block instead of component_declaration as the node.

If we wanted to have a bit more robust support for templ, then we could also handle this case (but it's probably not required yet). What should happen in the following lines?

package main

templ hello(name string) {
	<div>
        <h1>Howdy foks</h1>
        Hello, { name }

        <hr style="padding: 10px"
            if true {  <-- this line, for example, and the next one
                class="itIsTrue"
            }
        />
    </div>
}

Here's how it would work with component_block:

Screen.Recording.2024-03-26.at.22.18.13.mov

@zyriab
Copy link

zyriab commented Jul 2, 2024

Hello! Any plan to merge this PR soon? :)

@JoosepAlviste JoosepAlviste merged commit 87b7849 into JoosepAlviste:main Jul 3, 2024
1 check passed
JoosepAlviste added a commit that referenced this pull request Jul 3, 2024
@JoosepAlviste
Copy link
Owner

Merged and pushed the small fix myself, thanks for the reminder 👍

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants