fxbois / web-mode

web template editing mode for emacs
https://web-mode.org
GNU General Public License v3.0
1.63k stars 262 forks source link

Feature request, Antlers template support #1262

Closed 8cylinder closed 1 year ago

8cylinder commented 1 year ago

Hi, I would like to request Antlers support in web-mode. This is the templating language for the Statamic cms. The following has been taken from Statamic's antlers documentation.

If you need any more info, I'll be glad to trackdown what ever you need.

Delimiters

Tags

These are all acceptably formatted tags.

Variable must start with an alpha character or underscore (a-zA-Z_), followed by any number of additional uppercase or lowercase alphanumeric characters, hyphens, or underscores (a-zA-Z_0-9). Spaces or other special characters are not allowed.

Indenting

If:

{{ if meta_title }}
  {{ meta_title }}
{{ elseif title }}
  {{ title }}
{{ else }}
  {{ site:name }}
{{ /if }}

{{ if neighbor == "Kramer" }}
  <p>These pretzels are making me thirsty!</p>
{{ elseif neighbor == "Newman" }}
  <div>
    <p>Hello...Newman.</p>
  </div>
{{ else }}
  <!-- Who are you? -->
{{ /if }}

Unless:

{{ unless logged_in }}
  You see a large wardrobe in front of you.
{{ /unless }}

Switch:

{{ size = 'lg' }}

<div style="{{ switch
  (
    (size == 'sm') => '(min-width: 768px) 35vw, 90vw',
    (size == 'md') => '(min-width: 768px) 55vw, 90vw',
    (size == 'lg') => '(min-width: 768px) 75vw, 90vw',
    (size == 'xl') => '90vw',
    () => '100vw'
  )
}}">

Results in: <div style="(min-width: 768px) 75vw, 90vw">

More complicated

Unfortunately any tag can have a closing tag. It's probably not realistic to try and find a closing tag for all the variables since there is know way to tell if it is iterable or not, but, if you do have a way to do that, that would be awesome.

{{some_things}}
  <li>"value" is a built in variable in antlers: {{value}}</li>
{{/some_things}}
fxbois commented 1 year ago

The last commit brings some compatibility

8cylinder commented 1 year ago

Thanks, that works great!
Web-mode is hands down my favorite emacs mode and makes my life better.