From 1a9b6d1c2a9add239d354dd95393e07f609fdfbc Mon Sep 17 00:00:00 2001 From: Buddy Sandidge Date: Wed, 19 Feb 2014 22:11:14 -0800 Subject: [PATCH] Squashed 'vim/bundle/mustache/' content from commit 0c3900b42 git-subtree-dir: vim/bundle/mustache git-subtree-split: 0c3900b42a81ec79885cf984ad33b2280697c7c9 --- README.md | 96 +++++++++++++++++++++++++++++++++++++++++++ example.mustache | 50 ++++++++++++++++++++++ ftdetect/mustache.vim | 3 ++ ftplugin/mustache.vim | 63 ++++++++++++++++++++++++++++ syntax/mustache.vim | 75 +++++++++++++++++++++++++++++++++ 5 files changed, 287 insertions(+) create mode 100644 README.md create mode 100644 example.mustache create mode 100644 ftdetect/mustache.vim create mode 100644 ftplugin/mustache.vim create mode 100644 syntax/mustache.vim diff --git a/README.md b/README.md new file mode 100644 index 0000000..7835192 --- /dev/null +++ b/README.md @@ -0,0 +1,96 @@ +mustache and handlebars mode for vim +==================================== + +**Note**: This repo is deprecated, active development moved to +[mustache/vim-mode](http://github.com/mustache/vim-mode). + +A vim plugin for working with [mustache][mustache] and +[handlebars][handlebars] templates. It has: + + - syntax highlighting + - matchit support + - mustache abbreviations (optional) + - section movement mappings `[[` and `]]` + + +### Install for pathogen + + cd ~/.vim/ + git submodule add git://github.com/mustache/vim-mode.git bundle/mustache + vim bundle/mustache/example.mustache + +Get [pathogen][pathogen]. + +### Manually Install + + cd ~/.local/src + git clone git://github.com/mustache/vim-mode.git mustache.vim + cp -R mustache.vim/syntax/* ~/.vim/syntax/ + cp -R mustache.vim/ftdetect/* ~/.vim/ftdetect/ + cp -R mustache.vim/ftplugin/* ~/.vim/ftplugin/ + vim mustache.vim/example.mustache + +### Mustache Abbreviations + +You can activate mustache abbreviations by putting this line in your `.vimrc`: +`let g:mustache_abbreviations = 1` + +Now you get a set of convenient abbreviations. Underscore `_` indicates where +your cursor ends up after typing an abbreviation: + - `{{` => `{{_}}` + - `{{{` => `{{{_}}}` + - `{{!` => `{{!_}}` + - `{{>` => `{{>_}}` + - `{{<` => `{{<_}}` + - `{{#` produces + + ``` + {{# _}} + {{/}} + ``` + - `{{if` produces + + ``` + {{#if _}} + {{/if}} + ``` + - `{{ife` produces + + ``` + {{#if _}} + {{else}} + {{/if}} + ``` + +### Section movement mappings + +Following the vim convention of jumping from section to section, `[[` and `]]` +mappings are implemented for easier movement between mustache tags. + + - `]]` jumps to the first following tag + - `[[` jumps to the first previous tag + +Count with section movements is supported: + + - `2]]` jumps to the second next tag + +## Maintainers + +* [Bruno Michel](http://github.com/nono) +* [Bruno Sutic](http://github.com/bruno-) +* [Juvenn Woo](http://github.com/juvenn) + +This is combined work from +[juvenn/mustache.vim](http://github.com/juvenn/mustache.vim) and +[nono/vim-handlebars](http://github.com/nono/vim-handlebars). + +---- + +Thanks [@5long](http://github.com/5long) for adding matchit support. + +You're encouraged to propose ideas or have discussions via github +issues. + +[mustache]: http://mustache.github.io +[handlebars]: http://handlebarsjs.com +[pathogen]: https://github.com/tpope/vim-pathogen diff --git a/example.mustache b/example.mustache new file mode 100644 index 0000000..b579adb --- /dev/null +++ b/example.mustache @@ -0,0 +1,50 @@ + + + + + {{title}} + + {{!}} + + +
+

Mustache Showdown

+ + Basic mustache {{hello}} + {{ hello}}, {{hello }} and {{ hello }} are OK + + {{d d d}} + + {{Everything will be hilighted here}} + + Mustaches hilighted in + attribute value + + {{#repo}} + This is an mustache [enumerable] section +
  • {{ name }}
  • + {{/repo}} + + You can {{{yield}}} here + + {{! <> this is a comment TODO:}} + + This is a partial {{> partial1 }} + Yet another partial {{< partial2 }}, for ctemplate + + {{=<% %>=}}Sorry, cusomized delimiter not handled yet<%={{}}=%> + + {{#if some_helper}} + And here is an example of handlebars if... + {{else}} + ... with optional else added. Try matchit `%` command over if/else/if. + {{/if}} + + Thanks goes to {{@defunkt}} + Feedback/blames go to {{@juvenn}} + {{Frustrations}} go to /dev/null +
    + + + + diff --git a/ftdetect/mustache.vim b/ftdetect/mustache.vim new file mode 100644 index 0000000..e3bb34f --- /dev/null +++ b/ftdetect/mustache.vim @@ -0,0 +1,3 @@ +if has("autocmd") + au BufNewFile,BufRead *.mustache,*.handlebars,*.hbs,*.hogan,*.hulk,*.hjs set filetype=html syntax=mustache | runtime! ftplugin/mustache.vim ftplugin/mustache*.vim ftplugin/mustache/*.vim +endif diff --git a/ftplugin/mustache.vim b/ftplugin/mustache.vim new file mode 100644 index 0000000..7401e8e --- /dev/null +++ b/ftplugin/mustache.vim @@ -0,0 +1,63 @@ +let s:cpo_save = &cpo +set cpo&vim + +" Matchit support for Mustache & 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 + +if exists("g:mustache_abbreviations") + inoremap {{{ {{{}}} + inoremap {{ {{}} + inoremap {{! {{!}} + inoremap {{< {{<}} + inoremap {{> {{>}} + inoremap {{# {{#}}{{/}} + inoremap {{if {{#if }}{{/if}} + inoremap {{ife {{#if }}{{else}}{{/if}} +endif + + +" Section movement +" Adapted from vim-ruby - many thanks to the maintainers of that plugin + +function! s:sectionmovement(pattern,flags,mode,count) + norm! m' + if a:mode ==# 'v' + norm! gv + endif + let i = 0 + while i < a:count + let i = i + 1 + " saving current position + let line = line('.') + let col = col('.') + let pos = search(a:pattern,'W'.a:flags) + " if there's no more matches, return to last position + if pos == 0 + call cursor(line,col) + return + endif + endwhile +endfunction + +nnoremap [[ :call sectionmovement('{{','b','n',v:count1) +nnoremap ]] :call sectionmovement('{{','' ,'n',v:count1) +xnoremap [[ :call sectionmovement('{{','b','v',v:count1) +xnoremap ]] :call sectionmovement('{{','' ,'v',v:count1) + + +let &cpo = s:cpo_save +unlet s:cpo_save + +" vim: nofoldenable diff --git a/syntax/mustache.vim b/syntax/mustache.vim new file mode 100644 index 0000000..ef4fb79 --- /dev/null +++ b/syntax/mustache.vim @@ -0,0 +1,75 @@ +" Mustache & Handlebars syntax +" Language: Mustache, Handlebars +" Maintainer: Juvenn Woo +" Screenshot: http://imgur.com/6F408 +" Version: 2 +" Last Change: Mar 24th 2013 +" Remark: +" It lexically hilights embedded mustaches (exclusively) in html file. +" While it was written for Ruby-based Mustache template system, it should +" work for Google's C-based *ctemplate* as well as Erlang-based *et*. All +" of them are, AFAIK, based on the idea of ctemplate. +" References: +" [Mustache](http://github.com/defunkt/mustache) +" [Handlebars](https://github.com/wycats/handlebars.js) +" [ctemplate](http://code.google.com/p/google-ctemplate/) +" [ctemplate doc](http://google-ctemplate.googlecode.com/svn/trunk/doc/howto.html) +" [et](http://www.ivan.fomichev.name/2008/05/erlang-template-engine-prototype.html) +" TODO: Feedback is welcomed. + + +" Read the HTML syntax to start with +if version < 600 + so :p:h/html.vim +else + runtime! syntax/html.vim + unlet b:current_syntax +endif + +if version < 600 + syntax clear +elseif exists("b:current_syntax") + finish +endif + +" Standard HiLink will not work with included syntax files +if version < 508 + command! -nargs=+ HtmlHiLink hi link +else + command! -nargs=+ HtmlHiLink hi def link +endif + +syntax match mustacheError '}}}\?' +syntax match mustacheInsideError '{{[{#<>=!\/]\?' containedin=@mustacheInside +syntax region mustacheVariable matchgroup=mustacheMarker start=/{{/ end=/}}/ containedin=@htmlMustacheContainer +syntax region mustacheVariableUnescape matchgroup=mustacheMarker start=/{{{/ end=/}}}/ containedin=@htmlMustacheContainer +syntax region mustacheSection matchgroup=mustacheMarker start='{{[#/]' end=/}}/ containedin=@htmlMustacheContainer +syntax region mustachePartial matchgroup=mustacheMarker start=/{{[<>]/ end=/}}/ +syntax region mustacheMarkerSet matchgroup=mustacheMarker start=/{{=/ end=/=}}/ +syntax region mustacheComment start=/{{!/ end=/}}/ contains=Todo containedin=htmlHead + + +" Clustering +syntax cluster mustacheInside add=mustacheVariable,mustacheVariableUnescape,mustacheSection,mustachePartial,mustacheMarkerSet +syntax cluster htmlMustacheContainer add=htmlHead,htmlTitle,htmlString,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6,htmlLink,htmlBold,htmlUnderline,htmlItalic + +" Hilighting +" mustacheInside hilighted as Number, which is rarely used in html +" you might like change it to Function or Identifier +HtmlHiLink mustacheVariable Number +HtmlHiLink mustacheVariableUnescape Number +HtmlHiLink mustachePartial Number +HtmlHiLink mustacheSection Number +HtmlHiLink mustacheMarkerSet Number + +HtmlHiLink mustacheComment Comment +HtmlHiLink mustacheMarker Special +HtmlHiLink mustacheError Error +HtmlHiLink mustacheInsideError Error + +syn region mustacheScriptTemplate start=++me=s-1 keepend +\ contains=mustacheError,mustacheInsideError,mustacheVariable,mustacheVariableUnescape,mustacheSection,mustachePartial,mustacheMarkerSet,mustacheComment,htmlHead,htmlTitle,htmlString,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6,htmlTag,htmlEndTag,htmlTagName,htmlSpecialChar,htmlLink,htmlBold,htmlUnderline,htmlItalic + +let b:current_syntax = "mustache" +delcommand HtmlHiLink