Skip to content

Commit

Permalink
[Go] Add Template Snippets (#3764)
Browse files Browse the repository at this point in the history
This commit adds basic snippets for template related interpolations.

Examples:

    tif      => {{ if | }}
    tifend   => {{ if | }} ... {{ end }}
    telse    => {{ else }}

Triggers follow the scheme to prefix each valid template keyword with `t`.
  • Loading branch information
deathaxe authored Aug 2, 2023
1 parent 6160ce5 commit f0756c2
Show file tree
Hide file tree
Showing 18 changed files with 143 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Go/Snippets/Template/block-end.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<snippet>
<content><![CDATA[${TM_TEMPLATE_START}block "${1:name}"${TM_TEMPLATE_END}
$0
${TM_TEMPLATE_START}end${TM_TEMPLATE_END}]]></content>
<tabTrigger>tblockend</tabTrigger>
<scope>(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template</scope>
<description>{{block "name"}} ... {{end}}</description>
</snippet>
6 changes: 6 additions & 0 deletions Go/Snippets/Template/block.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<snippet>
<content><![CDATA[${TM_TEMPLATE_START}block "${1:name}"${TM_TEMPLATE_END}]]></content>
<tabTrigger>tblock</tabTrigger>
<scope>(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template</scope>
<description>{{block "name"}}</description>
</snippet>
6 changes: 6 additions & 0 deletions Go/Snippets/Template/break.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<snippet>
<content><![CDATA[${TM_TEMPLATE_START}break${TM_TEMPLATE_END}]]></content>
<tabTrigger>tbreak</tabTrigger>
<scope>(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template</scope>
<description>{{break}}</description>
</snippet>
6 changes: 6 additions & 0 deletions Go/Snippets/Template/continue.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<snippet>
<content><![CDATA[${TM_TEMPLATE_START}continue${TM_TEMPLATE_END}]]></content>
<tabTrigger>tcontinue</tabTrigger>
<scope>(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template</scope>
<description>{{continue}}</description>
</snippet>
6 changes: 6 additions & 0 deletions Go/Snippets/Template/define.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<snippet>
<content><![CDATA[${TM_TEMPLATE_START}define "${1:name}"${TM_TEMPLATE_END}]]></content>
<tabTrigger>tdefine</tabTrigger>
<scope>(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template</scope>
<description>{{define "name"}}</description>
</snippet>
6 changes: 6 additions & 0 deletions Go/Snippets/Template/else if.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<snippet>
<content><![CDATA[${TM_TEMPLATE_START}else if ${1:pipeline}${TM_TEMPLATE_END}]]></content>
<tabTrigger>telseif</tabTrigger>
<scope>(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template</scope>
<description>{{else if ...}}</description>
</snippet>
6 changes: 6 additions & 0 deletions Go/Snippets/Template/else.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<snippet>
<content><![CDATA[${TM_TEMPLATE_START}else${TM_TEMPLATE_END}]]></content>
<tabTrigger>telse</tabTrigger>
<scope>(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template</scope>
<description>{{else}}</description>
</snippet>
6 changes: 6 additions & 0 deletions Go/Snippets/Template/end.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<snippet>
<content><![CDATA[${TM_TEMPLATE_START}end${TM_TEMPLATE_END}]]></content>
<tabTrigger>tend</tabTrigger>
<scope>(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template</scope>
<description>{{end}}</description>
</snippet>
8 changes: 8 additions & 0 deletions Go/Snippets/Template/if-end.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<snippet>
<content><![CDATA[${TM_TEMPLATE_START}if ${1:pipeline}${TM_TEMPLATE_END}
$0
${TM_TEMPLATE_START}end${TM_TEMPLATE_END}]]></content>
<tabTrigger>tifend</tabTrigger>
<scope>(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template</scope>
<description>{{if ...}} ... {{end}}</description>
</snippet>
6 changes: 6 additions & 0 deletions Go/Snippets/Template/if.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<snippet>
<content><![CDATA[${TM_TEMPLATE_START}if ${1:pipeline}${TM_TEMPLATE_END}]]></content>
<tabTrigger>tif</tabTrigger>
<scope>(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template</scope>
<description>{{if ...}}</description>
</snippet>
6 changes: 6 additions & 0 deletions Go/Snippets/Template/partial.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<snippet>
<content><![CDATA[${TM_TEMPLATE_START}partial "${1:name}"${TM_TEMPLATE_END}]]></content>
<tabTrigger>tpartial</tabTrigger>
<scope>(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template</scope>
<description>{{partial "name"}}</description>
</snippet>
8 changes: 8 additions & 0 deletions Go/Snippets/Template/range-end.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<snippet>
<content><![CDATA[${TM_TEMPLATE_START}range ${1:pipeline}${TM_TEMPLATE_END}
$0
${TM_TEMPLATE_START}end${TM_TEMPLATE_END}]]></content>
<tabTrigger>trangeend</tabTrigger>
<scope>(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template</scope>
<description>{{range ...}}...{{end}}</description>
</snippet>
6 changes: 6 additions & 0 deletions Go/Snippets/Template/range.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<snippet>
<content><![CDATA[${TM_TEMPLATE_START}range ${1:pipeline}${TM_TEMPLATE_END}]]></content>
<tabTrigger>trange</tabTrigger>
<scope>(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template</scope>
<description>{{range ...}}</description>
</snippet>
6 changes: 6 additions & 0 deletions Go/Snippets/Template/template.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<snippet>
<content><![CDATA[${TM_TEMPLATE_START}template "${1:header}" ${0:.}${TM_TEMPLATE_END}]]></content>
<tabTrigger>ttemplate</tabTrigger>
<scope>(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template</scope>
<description>{{template "name" .}}</description>
</snippet>
6 changes: 6 additions & 0 deletions Go/Snippets/Template/var.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<snippet>
<content><![CDATA[${TM_TEMPLATE_START}.${0:Var}${TM_TEMPLATE_END}]]></content>
<tabTrigger>tvar</tabTrigger>
<scope>(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template</scope>
<description>{{.Var}}</description>
</snippet>
8 changes: 8 additions & 0 deletions Go/Snippets/Template/with-end.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<snippet>
<content><![CDATA[${TM_TEMPLATE_START}with ${1:pipeline}${TM_TEMPLATE_END}
$0
${TM_TEMPLATE_START}end${TM_TEMPLATE_END}]]></content>
<tabTrigger>twithend</tabTrigger>
<scope>(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template</scope>
<description>{{with ...}}...{{end}}</description>
</snippet>
6 changes: 6 additions & 0 deletions Go/Snippets/Template/with.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<snippet>
<content><![CDATA[${TM_TEMPLATE_START}with ${1:pipeline}${TM_TEMPLATE_END}]]></content>
<tabTrigger>twith</tabTrigger>
<scope>(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template</scope>
<description>{{with ...}}</description>
</snippet>
33 changes: 33 additions & 0 deletions Go/Template.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<!--
Template begin and end punctuation to wrap snippets into,
when expanding within plain HTML, Markdown, CSS, JavaScript or Go strings.
These variables are used to share snippets accross
plain text and template source code and to be able to adjust
whether templates are wrapped with whitespace.
-->
<key>scope</key>
<string>(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template</string>
<key>settings</key>
<dict>
<key>shellVariables</key>
<array>
<dict>
<key>name</key>
<string>TM_TEMPLATE_START</string>
<key>value</key>
<string><![CDATA[{{ ]]></string>
</dict>
<dict>
<key>name</key>
<string>TM_TEMPLATE_END</string>
<key>value</key>
<string><![CDATA[ }}]]></string>
</dict>
</array>
</dict>
</dict>
</plist>

0 comments on commit f0756c2

Please sign in to comment.