Skip to content

Commit 7e00da6

Browse files
authored
Add Phoenix LiveEEx Template (.leex) file type support (2) (elixir-editors#490)
* Add Phoenix LiveEEx Template (.leex) file type support. Add LiveView sigil (~L"""LiveView""") support in .ex. Update README.md * update leex indentation and syntax specs removed duplicated live view sigil spec * fix leex test bugs
1 parent fbab531 commit 7e00da6

File tree

7 files changed

+30
-6
lines changed

7 files changed

+30
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Features:
1010

1111
* Syntax highlighting for Elixir and EEx files
12-
* Filetype detection for `.ex`, `.exs` and `.eex` files
12+
* Filetype detection for `.ex`, `.exs`, `.eex` and `.leex` files
1313
* Automatic indentation
1414
* Integration between Ecto projects and [vim-dadbod][] for running SQL queries
1515
on defined Ecto repositories

ftplugin/eelixir.vim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ if !exists("b:eelixir_subtype")
2020
let b:eelixir_subtype = matchstr(&filetype,'^eex\.\zs\w\+')
2121
endif
2222
if b:eelixir_subtype == ''
23-
let b:eelixir_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.eex\|\.eelixir\)\+$','',''),'\.\zs\w\+$')
23+
let b:eelixir_subtype = matchstr(&filetype,'^leex\.\zs\w\+')
24+
endif
25+
if b:eelixir_subtype == ''
26+
let b:eelixir_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.eex\|\.leex\|\.eelixir\)\+$','',''),'\.\zs\w\+$')
2427
endif
2528
if b:eelixir_subtype == 'ex'
2629
let b:eelixir_subtype = 'elixir'

ftplugin/elixir.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ let &l:path =
2828
\ &g:path
2929
\ ], ',')
3030
setlocal includeexpr=elixir#util#get_filename(v:fname)
31-
setlocal suffixesadd=.ex,.exs,.eex,.erl,.xrl,.yrl,.hrl
31+
setlocal suffixesadd=.ex,.exs,.eex,.leex,.erl,.xrl,.yrl,.hrl
3232

3333
let &l:define = 'def\(macro\|guard\|delegate\)\=p\='
3434

spec/spec_helper.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ def self.new
122122
end
123123
end
124124

125+
module EexBuffer
126+
def self.new
127+
Buffer.new(VIM, :leex)
128+
end
129+
end
130+
125131
RSpec::Matchers.define :be_typed_with_right_indent do |syntax|
126132
buffer = Buffer.new(VIM, syntax || :ex)
127133

@@ -144,7 +150,8 @@ def self.new
144150

145151
{
146152
be_elixir_indentation: :ex,
147-
be_eelixir_indentation: :eex
153+
be_eelixir_indentation: :eex,
154+
be_leelixir_indentation: :leex
148155
}.each do |matcher, type|
149156
RSpec::Matchers.define matcher do
150157
buffer = Buffer.new(VIM, type)
@@ -169,7 +176,8 @@ def self.new
169176

170177
{
171178
include_elixir_syntax: :ex,
172-
include_eelixir_syntax: :eex
179+
include_eelixir_syntax: :eex,
180+
include_leelixir_syntax: :leex
173181
}.each do |matcher, type|
174182
RSpec::Matchers.define matcher do |syntax, pattern|
175183
buffer = Buffer.new(VIM, type)

spec/syntax/sigil_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@
8787
it 'without escaped parenthesis' do
8888
expect('~S(\( )').not_to include_elixir_syntax('elixirRegexEscapePunctuation', '( ')
8989
end
90+
91+
it 'Live EEx' do
92+
expect('~L"""liveview template"""').to include_elixir_syntax('elixirSigilDelimiter', '"""')
93+
end
9094
end
9195

9296
describe 'lower case' do

syntax/eelixir.vim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ if !exists("b:eelixir_subtype")
2020
let b:eelixir_subtype = matchstr(&filetype,'^eex\.\zs\w\+')
2121
endif
2222
if b:eelixir_subtype == ''
23-
let b:eelixir_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.eex\|\.eelixir\)\+$','',''),'\.\zs\w\+$')
23+
let b:eelixir_subtype = matchstr(&filetype,'^leex\.\zs\w\+')
24+
endif
25+
if b:eelixir_subtype == ''
26+
let b:eelixir_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.eex\|\.leex\|\.eelixir\)\+$','',''),'\.\zs\w\+$')
2427
endif
2528
if b:eelixir_subtype == 'ex'
2629
let b:eelixir_subtype = 'elixir'

syntax/elixir.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ syn region elixirSigil matchgroup=elixirSigilDelimiter start="\~\l\/"
105105
syn region elixirSigil matchgroup=elixirSigilDelimiter start=+\~\a\z("""\)+ end=+^\s*\z1+ skip=+\\"+ fold
106106
syn region elixirSigil matchgroup=elixirSigilDelimiter start=+\~\a\z('''\)+ end=+^\s*\z1+ skip=+\\'+ fold
107107

108+
109+
" LiveView Sigils surrounded with ~L"""
110+
syntax include @HTML syntax/html.vim
111+
syntax region elixirLiveViewSigil matchgroup=elixirSigilDelimiter keepend start=+\~L\z("""\)+ end=+^\s*\z1+ skip=+\\"+ contains=@HTML fold
112+
113+
108114
" Documentation
109115
if exists('g:elixir_use_markdown_for_docs') && g:elixir_use_markdown_for_docs
110116
syn include @markdown syntax/markdown.vim

0 commit comments

Comments
 (0)