neoformat
neoformat copied to clipboard
How to formatting ERB files, like html.erb and js.erb
Now i use prettier for html.erb files. like init.vim autocmd BufNewFile,BufRead *.html.erb set filetype=html let g:neoformat_enabled_html = ['prettier']
but it working incorrect for example all tags ERB <%=%> formatting in one line
<% if condition %>
<%= lint_to :example %>
<%= input :example, "qweqwe" %>
<% end %>
to
<% if condition %> <%= link_to example %> <%= input
:example, "qweqwe" %><% end %>
etc
I haven't tried js.erb but for html.erb, I'm using htmlbeautifier with the following in ~/.config/nvim/autoload/neoformat/formatters/eruby.vim
function! neoformat#formatters#eruby#enabled() abort
return ['htmlbeautifier']
endfunction
function! neoformat#formatters#eruby#htmlbeautifier() abort
return {
\ 'exe': 'htmlbeautifier',
\ 'args': ['--keep-blank-lines', '1'],
\ 'stdin': 1
\ }
endfunction
Using lua config in Neovim, i just set these variables:
vim.g.neoformat_enabled_eruby = { "erbformat", "htmlbeautifier" }
vim.g.neoformat_eruby_erbformat = { exe = "erb-format", args = { "--stdin" }, stdin = 1 }
vim.g.neoformat_eruby_htmlbeautifier = { exe = "htmlbeautifier", args = { "--keep-blank-lines", '1' }, stdin = 1 }
I use erb-format, that'll seems to work.
Or one can create the autoload/neoformat/formatters/eruby.vim like above and prepend other formatters:
function! neoformat#formatters#eruby#enabled() abort
return ['erbformat', 'htmlbeautifier']
endfunction
function! neoformat#formatters#eruby#erbformat() abort
return {
\ 'exe': 'erb-format',
\ 'args': ['--stdin'],
\ 'stdin': 1
\ }
endfunction
function! neoformat#formatters#eruby#htmlbeautifier() abort
return {
\ 'exe': 'htmlbeautifier',
\ 'args': ['--keep-blank-lines', '1'],
\ 'stdin': 1
\ }
endfunction