Giter Site home page Giter Site logo

james-andrewsmith / prettier-plugin-go-jet-template Goto Github PK

View Code? Open in Web Editor NEW

This project forked from niklaspor/prettier-plugin-go-template

0.0 0.0 0.0 570 KB

Prettier formatting for jet templates ๐Ÿน

Home Page: prettier-plugin-go-template-niklaspor.vercel.app

License: MIT License

JavaScript 0.48% TypeScript 64.32% HTML 35.21%

prettier-plugin-go-jet-template's Introduction

prettier-plugin-go-template

NPM Badge CodeCov Badge Contributions Badge

Formatter plugin for go template files. The only peer dependency is prettier.

npm install --save-dev prettier prettier-plugin-go-template

Starting with Prettier 3 auto-discovery has been removed. Configuration is required โฌ‡๏ธ

// .prettierrc
{
  "plugins": ["prettier-plugin-go-template"]
}

The following file types will be detected automatically: .gohtml, .gotmpl, .go.tmpl, .tmpl, .tpl, .html.tmpl If you want to add support for .html read the section on it below the examples.

Input Output
{{ if or .Prev .Next -}}
{{ $p := where site.Pages }}
<div class="my-navigation">
{{ with $p.Next . -}}
<a href="{{ .RelPermalink }}">
<div class="row">
<div class="cell py-2">
  {{ .Title }} 
</div> </div> </a>
{{ end -}}
</div>
{{ end -}}
{{ if or .Prev .Next -}}
  {{ $p := where site.Pages }}
  <div class="my-navigation">
    {{ with $p.Next . -}}
      <a href="{{ .RelPermalink }}">
        <div class="row">
          <div class="cell py-2">{{ .Title }}</div>
        </div>
      </a>
    {{ end -}}
  </div>
{{ end -}}

GoHugo / .html

To use it with GoHugo and basic .html files, you'll have to override the used parser inside your .prettierrc file:

{
  "plugins": ["prettier-plugin-go-template"],
  "overrides": [
    {
      "files": ["*.html"],
      "options": {
        "parser": "go-template",
      },
    },
  ],
}

VSCode

Make sure to always have installed both dependencies:

  • prettier
  • prettier-plugin-go-template

Also make sure that they are installed inside the same scope. Install both globally (npm i -g) or locally โ€“ otherwise prettier may not pick up the plugin.

Note: The global setup additional requires setting your VSCode prettier path to your global prettier path. You can read in this issue how to set it up โ€“ should be doable in less than a minute if you have npm & VSCode already running.

Additional Options

// .prettierrc
{
  /**
   * Enables & disables spacing between go statements.
   * E.g. {{ statement }} vs {{statement}}.
   * Default: true
   */
  "goTemplateBracketSpacing": true
}

Ignoring Code

Single Block

<div>
  <!-- prettier-ignore -->
  {{if }}
  {{end }}
</div>

Multiline

<html>
  {{/* prettier-ignore-start */}}
  <script>
    {{if }}
    Whatever.
    {{else }}
    Psych.
    {{end }}
  </script>
  {{/* prettier-ignore-end */}}
</html>

Contributors โœจ

Thanks goes to these wonderful people (emoji key):


alqu

๐Ÿ› โš ๏ธ ๐Ÿ’ป

Gabriel Monteagudo

๐Ÿ›

Bryan

๐Ÿ›

Andreas Richter

๐Ÿ›

Noah Brenner

๐Ÿ’ป ๐Ÿ“–

silverwind

๐Ÿค”

Charles Pence

๐Ÿ›

Caleb Jasik

๐Ÿ› ๐Ÿ“– ๐Ÿ’ก ๐Ÿค” ๐Ÿšง ๐Ÿ’ฌ

Dan Gold

๐Ÿ›

Michael Lynch

๐Ÿ›

This project follows the all-contributors specification. Contributions of any kind welcome!

prettier-plugin-go-jet-template's People

Contributors

allcontributors[bot] avatar coliff avatar dependabot[bot] avatar jasikpark avatar niklaspor avatar noahbrenner avatar v-ji avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.