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

Add templ language #6798

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,9 @@
[submodule "vendor/grammars/tcl.tmbundle"]
path = vendor/grammars/tcl.tmbundle
url = https://github.com/textmate/tcl.tmbundle
[submodule "vendor/grammars/templ-vscode"]
path = vendor/grammars/templ-vscode
url = https://github.com/templ-go/templ-vscode.git
[submodule "vendor/grammars/textmate.tmbundle"]
path = vendor/grammars/textmate.tmbundle
url = https://github.com/textmate/textmate.tmbundle
Expand Down
2 changes: 2 additions & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,8 @@ vendor/grammars/syntax:
vendor/grammars/tcl.tmbundle:
- source.tcl
- text.html.tcl
vendor/grammars/templ-vscode:
- source.templ
vendor/grammars/textmate.tmbundle:
- source.regexp.oniguruma
- source.tm-properties
Expand Down
7 changes: 7 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8388,6 +8388,13 @@ sed:
ace_mode: text
tm_scope: source.sed
language_id: 847830017
templ:
tris203 marked this conversation as resolved.
Show resolved Hide resolved
type: programming
tris203 marked this conversation as resolved.
Show resolved Hide resolved
color: "#66D0DD"
extensions:
- ".templ"
ace_mode: text
language_id: 795579337
tris203 marked this conversation as resolved.
Show resolved Hide resolved
wisp:
type: programming
ace_mode: clojure
Expand Down
62 changes: 62 additions & 0 deletions samples/templ/posts.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import "fmt"
import "time"

templ headerTemplate(name string) {
<header data-testid="headerTemplate">
<h1>{ name }</h1>
</header>
}

templ footerTemplate() {
<footer data-testid="footerTemplate">
<div>&copy; { fmt.Sprintf("%d", time.Now().Year()) }</div>
</footer>
}

templ navTemplate() {
<nav data-testid="navTemplate">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/posts">Posts</a></li>
</ul>
</nav>
}

templ layout(name string) {
<html>
<head><title>{ name }</title></head>
<body>
@headerTemplate(name)
@navTemplate()
<main>
{ children... }
</main>
</body>
@footerTemplate()
</html>
}

templ postsTemplate(posts []Post) {
<div data-testid="postsTemplate">
for _, p := range posts {
<div data-testid="postsTemplatePost">
<div data-testid="postsTemplatePostName">{ p.Name }</div>
<div data-testid="postsTemplatePostAuthor">{ p.Author }</div>
</div>
}
</div>
}

templ home() {
@layout("Home") {
<div data-testid="homeTemplate">Welcome to my website.</div>
}
}

templ posts(posts []Post) {
@layout("Posts") {
@postsTemplate(posts)
}
}
1 change: 1 addition & 0 deletions vendor/grammars/templ-vscode
Submodule templ-vscode added at 541375
31 changes: 31 additions & 0 deletions vendor/licenses/git_submodule/templ-vscode.dep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: templ-vscode
version: 541375467092a84f73421546f3cbf603e03f3f59
type: git_submodule
homepage: https://github.com/templ-go/templ-vscode.git
license: mit
licenses:
- sources: LICENSE
text: |
MIT License

Copyright (c) 2023 Adrian Hesketh

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
notices: []