Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Slim templates

  • Loading branch information...
commit 9ef09b5558be510354cd41ba9f938278252e2b2d 1 parent 74d4a14
@seejohnrun authored
View
2  .vim/ftdetect/slim.vim
@@ -0,0 +1,2 @@
+autocmd BufNewFile,BufRead *.slim set filetype=slim
+autocmd FileType slim set tabstop=2|set shiftwidth=2|set expandtab
View
6 .vim/ftplugin/slim.vim
@@ -0,0 +1,6 @@
+setlocal tabstop=2
+setlocal softtabstop=2
+setlocal shiftwidth=2
+setlocal smarttab
+setlocal expandtab
+setlocal smartindent
View
75 .vim/indent/slim.vim
@@ -0,0 +1,75 @@
+" Vim indent file
+" Language: Slim
+
+if exists("b:did_indent")
+ finish
+endif
+runtime! indent/ruby.vim
+unlet! b:did_indent
+let b:did_indent = 1
+
+setlocal autoindent sw=2 et
+setlocal indentexpr=GetSlimIndent()
+setlocal indentkeys=o,O,*<Return>,},],0),!^F,=end,=else,=elsif,=rescue,=ensure,=when
+
+" Only define the function once.
+if exists("*GetSlimIndent")
+ finish
+endif
+
+let s:attributes = '\%({.\{-\}}\|\[.\{-\}\]\)'
+let s:tag = '\%([%.#][[:alnum:]_-]\+\|'.s:attributes.'\)*[<>]*'
+
+if !exists('g:haml_self_closing_tags')
+ let g:haml_self_closing_tags = 'meta|link|img|hr|br'
+endif
+
+function! GetSlimIndent()
+ let lnum = prevnonblank(v:lnum-1)
+ if lnum == 0
+ return 0
+ endif
+ let line = substitute(getline(lnum),'\s\+$','','')
+ let cline = substitute(substitute(getline(v:lnum),'\s\+$','',''),'^\s\+','','')
+ let lastcol = strlen(line)
+ let line = substitute(line,'^\s\+','','')
+ let indent = indent(lnum)
+ let cindent = indent(v:lnum)
+ if cline =~# '\v^-\s*%(elsif|else|when)>'
+ let indent = cindent < indent ? cindent : indent - &sw
+ endif
+ let increase = indent + &sw
+ if indent == indent(lnum)
+ let indent = cindent <= indent ? -1 : increase
+ endif
+
+ let group = synIDattr(synID(lnum,lastcol,1),'name')
+
+ if line =~ '^doctype'
+ return indent
+ elseif line =~ '^/\%(\[[^]]*\]\)\=$'
+ return increase
+ elseif line =~ '^[\.#]'
+ return increase
+ elseif line =~? '^div'
+ return increase
+ elseif group == 'hamlFilter'
+ return increase
+ elseif line =~ '^'.s:tag.'[&!]\=[=~-]\s*\%(\%(if\|else\|elsif\|unless\|case\|when\|while\|until\|for\|begin\|module\|class\|def\)\>\%(.*\<end\>\)\@!\|.*do\%(\s*|[^|]*|\)\=\s*$\)'
+ return increase
+ elseif line =~ '^'.s:tag.'[&!]\=[=~-].*,\s*$'
+ return increase
+ elseif line == '-#'
+ return increase
+ elseif group =~? '\v^(hamlSelfCloser)$' || line =~? '^\v('.g:haml_self_closing_tags.')>'
+ return indent
+ elseif group =~? '\v^(hamlTag|hamlAttributesDelimiter|hamlObjectDelimiter|hamlClass|hamlId|htmlTagName|htmlSpecialTagName)$'
+ return increase
+ elseif synIDattr(synID(v:lnum,1,1),'name') ==? 'hamlRubyFilter'
+ return GetRubyIndent()
+ else
+ return indent
+ endif
+endfunction
+
+" vim:set sw=2:
View
95 .vim/syntax/slim.vim
@@ -0,0 +1,95 @@
+" Vim syntax file
+" Language: Slim
+" Maintainer: Andrew Stone <andy@stonean.com>
+" Version: 1
+" Last Change: 2010 Sep 25
+" TODO: Feedback is welcomed.
+
+" Quit when a syntax file is already loaded.
+if exists("b:current_syntax")
+ finish
+endif
+
+if !exists("main_syntax")
+ let main_syntax = 'slim'
+endif
+
+" Allows a per line syntax evaluation.
+let b:ruby_no_expensive = 1
+
+" Include Ruby syntax highlighting
+syn include @slimRubyTop syntax/ruby.vim
+unlet! b:current_syntax
+" Include Haml syntax highlighting
+syn include @slimHaml syntax/haml.vim
+unlet! b:current_syntax
+
+syn match slimBegin "^\s*\(&[^= ]\)\@!" nextgroup=slimTag,slimClassChar,slimIdChar,slimRuby
+
+syn region rubyCurlyBlock start="{" end="}" contains=@slimRubyTop contained
+syn cluster slimRubyTop add=rubyCurlyBlock
+
+syn cluster slimComponent contains=slimClassChar,slimIdChar,slimWrappedAttrs,slimRuby,slimAttr,slimInlineTagChar
+
+syn keyword slimDocType contained html 5 1.1 strict frameset mobile basic transitional
+syn match slimDocTypeKeyword "^\s*\(doctype\)\s\+" nextgroup=slimDocType
+
+syn match slimTag "\w\+" contained contains=htmlTagName nextgroup=@slimComponent
+syn match slimIdChar "#{\@!" contained nextgroup=slimId
+syn match slimId "\%(\w\|-\)\+" contained nextgroup=@slimComponent
+syn match slimClassChar "\." contained nextgroup=slimClass
+syn match slimClass "\%(\w\|-\)\+" contained nextgroup=@slimComponent
+syn match slimInlineTagChar "\s*:\s*" contained nextgroup=slimTag,slimClassChar,slimIdChar
+
+syn region slimWrappedAttrs matchgroup=slimWrappedAttrsDelimiter start="\s*{\s*" skip="}\s*\"" end="\s*}\s*" contained contains=slimAttr nextgroup=slimRuby
+syn region slimWrappedAttrs matchgroup=slimWrappedAttrsDelimiter start="\s*\[\s*" end="\s*\]\s*" contained contains=slimAttr nextgroup=slimRuby
+syn region slimWrappedAttrs matchgroup=slimWrappedAttrsDelimiter start="\s*(\s*" end="\s*)\s*" contained contains=slimAttr nextgroup=slimRuby
+
+syn match slimAttr "\s*\%(\w\|-\)\+\s*" contained contains=htmlArg nextgroup=slimAttrAssignment
+syn match slimAttrAssignment "\s*=\s*" contained nextgroup=slimWrappedAttrValue,slimAttrString
+
+syn region slimWrappedAttrValue matchgroup=slimWrappedAttrValueDelimiter start="{" end="}" contained contains=slimAttrString,@slimRubyTop nextgroup=slimAttr,slimRuby,slimInlineTagChar
+syn region slimWrappedAttrValue matchgroup=slimWrappedAttrValueDelimiter start="\[" end="\]" contained contains=slimAttrString,@slimRubyTop nextgroup=slimAttr,slimRuby,slimInlineTagChar
+syn region slimWrappedAttrValue matchgroup=slimWrappedAttrValueDelimiter start="(" end=")" contained contains=slimAttrString,@slimRubyTop nextgroup=slimAttr,slimRuby,slimInlineTagChar
+
+syn region slimAttrString start=+\s*"+ skip=+\%(\\\\\)*\\"+ end=+"\s*+ contained contains=slimInterpolation,slimInterpolationEscape nextgroup=slimAttr,slimRuby,slimInlineTagChar
+syn region slimAttrString start=+\s*'+ skip=+\%(\\\\\)*\\"+ end=+'\s*+ contained contains=slimInterpolation,slimInterpolationEscape nextgroup=slimAttr,slimRuby,slimInlineTagChar
+
+syn region slimInnerAttrString start=+\s*"+ skip=+\%(\\\\\)*\\"+ end=+"\s*+ contained contains=slimInterpolation,slimInterpolationEscape nextgroup=slimAttr
+syn region slimInnerAttrString start=+\s*'+ skip=+\%(\\\\\)*\\"+ end=+'\s*+ contained contains=slimInterpolation,slimInterpolationEscape nextgroup=slimAttr
+
+syn region slimInterpolation matchgroup=slimInterpolationDelimiter start="#{" end="}" contains=@hamlRubyTop containedin=javascriptStringS,javascriptStringD,slimWrappedAttrs
+syn match slimInterpolationEscape "\\\@<!\%(\\\\\)*\\\%(\\\ze#{\|#\ze{\)"
+
+syn region slimRuby matchgroup=slimRubyOutputChar start="\s*[=]\==[']\=" skip=",\s*$" end="$" contained contains=@slimRubyTop keepend
+syn region slimRuby matchgroup=slimRubyChar start="\s*-" skip=",\s*$" end="$" contained contains=@slimRubyTop keepend
+
+syn match slimComment /^\(\s*\)[/].*\(\n\1\s.*\)*/
+syn match slimText /^\(\s*\)[`|'].*\(\n\1\s.*\)*/
+
+syn match slimFilter /\s*\w\+:\s*/ contained
+syn match slimHaml /^\(\s*\)\<haml:\>.*\(\n\1\s.*\)*/ contains=@slimHaml,slimFilter
+
+syn match slimIEConditional "\%(^\s*/\)\@<=\[\s*if\>[^]]*]" contained containedin=slimComment
+
+hi def link slimAttrString String
+hi def link slimBegin String
+hi def link slimClass Type
+hi def link slimClassChar Type
+hi def link slimComment Comment
+hi def link slimDocType Identifier
+hi def link slimDocTypeKeyword Keyword
+hi def link slimFilter Keyword
+hi def link slimIEConditional SpecialComment
+hi def link slimId Identifier
+hi def link slimIdChar Identifier
+hi def link slimInnerAttrString String
+hi def link slimInterpolationDelimiter Delimiter
+hi def link slimRubyChar Special
+hi def link slimRubyOutputChar Special
+hi def link slimText String
+hi def link slimWrappedAttrValueDelimiter Delimiter
+hi def link slimWrappedAttrsDelimiter Delimiter
+hi def link slimInlineTagChar Delimiter
+
+let b:current_syntax = "slim"
Please sign in to comment.
Something went wrong with that request. Please try again.