Skip to content

Commit

Permalink
Add templ language (#6798)
Browse files Browse the repository at this point in the history
* feat: templ support

* chore: address comments

* chore: add to README
  • Loading branch information
tris203 committed Jun 7, 2024
1 parent 2723b1f commit c95904f
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,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 @@ -1074,6 +1074,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
8 changes: 8 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8455,6 +8455,14 @@ sed:
ace_mode: text
tm_scope: source.sed
language_id: 847830017
templ:
type: markup
color: "#66D0DD"
extensions:
- ".templ"
ace_mode: text
tm_scope: source.templ
language_id: 795579337
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/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -668,5 +668,6 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
- **reStructuredText:** [Lukasa/language-restructuredtext](https://github.com/Lukasa/language-restructuredtext)
- **robots.txt:** [Nixinova/NovaGrammars](https://github.com/Nixinova/NovaGrammars)
- **sed:** [Alhadis/language-sed](https://github.com/Alhadis/language-sed)
- **templ:** [templ-go/templ-vscode](https://github.com/templ-go/templ-vscode)
- **wisp:** [atom/language-clojure](https://github.com/atom/language-clojure)
- **xBase:** [hernad/atom-language-harbour](https://github.com/hernad/atom-language-harbour)
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: []

0 comments on commit c95904f

Please sign in to comment.