summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2013-09-12 17:34:37 +0200
committerAdam Stankiewicz <sheerun@sher.pl>2013-09-12 17:34:37 +0200
commit2ed8751feb4e78fd37a822581a3ec4f7bfd627db (patch)
treec5686cab46f580a748d433c7c5272076dc588602
parent3bd65161236bf5344619861fbe18b30f5bfd1a23 (diff)
downloadvim-polyglot-2ed8751feb4e78fd37a822581a3ec4f7bfd627db.tar.gz
vim-polyglot-2ed8751feb4e78fd37a822581a3ec4f7bfd627db.zip
Add handlebars templates support
-rwxr-xr-xbuild.sh1
-rw-r--r--ftdetect/handlebars.vim3
-rw-r--r--ftplugin/handlebars.vim22
-rw-r--r--syntax/handlebars.vim83
4 files changed, 109 insertions, 0 deletions
diff --git a/build.sh b/build.sh
index 743ff4a2..7fe7fa07 100755
--- a/build.sh
+++ b/build.sh
@@ -45,6 +45,7 @@ syntax 'mutewinter/tomdoc.vim' &
syntax 'mutewinter/nginx.vim' &
syntax 'timcharper/textile.vim' &
syntax 'tpope/vim-markdown' &
+syntax 'nono/vim-handlebars' &
syntax 'acustodioo/vim-tmux' &
syntax 'groenewege/vim-less' &
syntax 'wavded/vim-stylus' &
diff --git a/ftdetect/handlebars.vim b/ftdetect/handlebars.vim
new file mode 100644
index 00000000..45198d66
--- /dev/null
+++ b/ftdetect/handlebars.vim
@@ -0,0 +1,3 @@
+if has("autocmd")
+ au BufNewFile,BufRead *.{handlebars,hb,hbs,hbt}{,.erb} set ft=html syntax=handlebars | runtime! ftplugin/handlebars.vim ftplugin/handlebars*.vim ftplugin/handlebars/*.vim
+endif
diff --git a/ftplugin/handlebars.vim b/ftplugin/handlebars.vim
new file mode 100644
index 00000000..c4a5dace
--- /dev/null
+++ b/ftplugin/handlebars.vim
@@ -0,0 +1,22 @@
+" Taken from https://github.com/juvenn/mustache.vim/blob/master/ftplugin/mustache.vim
+
+let s:cpo_save = &cpo
+set cpo&vim
+
+" Matchit support for Handlebars
+" extending HTML matchit groups
+if exists("loaded_matchit") && exists("b:match_words")
+ let b:match_words = b:match_words
+ \ . ',{:},[:],(:),'
+ \ . '\%({{\)\@<=#\s*\%(if\|unless\)\s*.\{-}}}'
+ \ . ':'
+ \ . '\%({{\)\@<=\s*else\s*}}'
+ \ . ':'
+ \ . '\%({{\)\@<=/\s*\%(if\|unless\)\s*}},'
+ \ . '\%({{\)\@<=[#^]\s*\([-0-9a-zA-Z_?!/.]\+\).\{-}}}'
+ \ . ':'
+ \ . '\%({{\)\@<=/\s*\1\s*}}'
+endif
+
+let &cpo = s:cpo_save
+unlet s:cpo_save
diff --git a/syntax/handlebars.vim b/syntax/handlebars.vim
new file mode 100644
index 00000000..fd7618b5
--- /dev/null
+++ b/syntax/handlebars.vim
@@ -0,0 +1,83 @@
+" Handlebars syntax
+" Language: Handlebars
+" Maintainer: Bruno Michel <brmichel@free.fr>
+" Last Change: Mar 8th, 2013
+" Version: 0.3
+" URL: https://github.com/nono/vim-handlebars
+
+if version < 600
+ syntax clear
+elseif exists("b:current_syntax")
+ finish
+endif
+
+if !exists("main_syntax")
+ let main_syntax = 'html'
+endif
+
+ru! syntax/html.vim
+unlet b:current_syntax
+
+
+syn keyword hbsTodo TODO FIXME XXX contained
+
+syn match hbsError /}}}\?/
+syn match hbsInsideError /{{[{#<>=!\/]\?/ containedin=@hbsInside
+
+syn cluster htmlHbsContainer add=htmlHead,htmlTitle,htmlString,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6
+syn region hbsInside start=/{{/ end=/}}/ keepend transparent containedin=@htmlHbsContainer
+
+syn match hbsHandlebars "{{\|}}" containedin=hbsInside
+syn match hbsUnescape "{{{\|}}}" containedin=hbsInside
+syn match hbsOperators "=\|\.\|/" containedin=hbsInside
+
+syn region hbsSection start="{{[#/]"lc=2 end=/}}/me=e-2 containedin=hbsInside
+syn region hbsPartial start=/{{[<>]/lc=2 end=/}}/me=e-2 containedin=hbsInside
+syn region hbsMarkerSet start=/{{=/lc=2 end=/=}}/me=e-2 containedin=hbsInside
+
+syn region hbsComment start=/{{!/rs=s+2 end=/}}/re=e-2 containedin=htmlHead contains=hbsTodo,Todo
+syn region hbsBlockComment start=/{{!--/rs=s+2 end=/--}}/re=e-2 containedin=htmlHead contains=hbsTodo,Todo
+syn region hbsQString start=/'/ skip=/\\'/ end=/'/ containedin=hbsInside
+syn region hbsDQString start=/"/ skip=/\\"/ end=/"/ containedin=hbsInside
+
+syn match hbsConditionals "\([/#]\(if\|unless\)\|else\)" containedin=hbsInside
+syn match hbsHelpers "[/#]\(with\|each\)" containedin=hbsInside
+
+
+" Define the default highlighting.
+" For version 5.7 and earlier: only when not done already
+" For version 5.8 and later: only when an item doesn't have highlighting yet
+if version >= 508 || !exists("did_lisp_syntax_inits")
+ if version < 508
+ let did_lisp_syntax_inits = 1
+ command -nargs=+ HiLink hi link <args>
+ else
+ command -nargs=+ HiLink hi def link <args>
+ endif
+
+ HiLink hbsTodo Todo
+
+ HiLink hbsError Error
+ HiLink hbsInsideError Error
+
+ HiLink hbsHandlebars Identifier
+ HiLink hbsUnescape Special
+ HiLink hbsOperators Operator
+
+ HiLink hbsConditionals Conditional
+ HiLink hbsHelpers Repeat
+
+ HiLink hbsSection Number
+ HiLink hbsPartial Include
+ HiLink hbsMarkerSet Number
+
+ HiLink hbsBlockComment Comment
+ HiLink hbsComment Comment
+ HiLink hbsQString String
+ HiLink hbsDQString String
+
+ delcommand HiLink
+endif
+
+
+let b:current_syntax = 'handlebars'