forked from VimPlug/emmet-vim
fix snippets for haml & slim.
This commit is contained in:
@@ -157,17 +157,8 @@ function! zencoding#toString(...)
|
||||
let tmp = substitute(tmp, '|', '${cursor}', 'g')
|
||||
endif
|
||||
let tmp = substitute(tmp, '\${zenname}', current.name, 'g')
|
||||
if zencoding#isExtends(type, "css") && zencoding#useFilter(filters, 'fc')
|
||||
let tmp = substitute(tmp, '^\([^:]\+\):\([^;]*;\)', '\1: \2', '')
|
||||
if current.important
|
||||
let tmp = substitute(tmp, ';', ' !important;', '')
|
||||
endif
|
||||
endif
|
||||
for attr in keys(current.attr)
|
||||
let val = current.attr[attr]
|
||||
let tmp = substitute(tmp, '\${' . attr . '}', val, 'g')
|
||||
endfor
|
||||
let str .= tmp
|
||||
let snippet_node = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 0, 'parent': {}, 'value': '{'.tmp.'}', 'pos': 0, 'important': current.important }
|
||||
let str = zencoding#lang#{rtype}#toString(s:zen_settings, snippet_node, type, inline, filters, group_itemno, indent)
|
||||
else
|
||||
if len(current.name)
|
||||
let str .= current.name
|
||||
@@ -209,15 +200,6 @@ function! zencoding#getResource(type, name, default)
|
||||
endif
|
||||
let ret = a:default
|
||||
|
||||
if has_key(s:zen_settings[a:type], a:name)
|
||||
let v = s:zen_settings[a:type][a:name]
|
||||
if type(ret) == 3 || type(ret) == 4
|
||||
call s:mergeConfig(ret, s:zen_settings[a:type][a:name])
|
||||
else
|
||||
let ret = s:zen_settings[a:type][a:name]
|
||||
endif
|
||||
endif
|
||||
|
||||
if has_key(s:zen_settings[a:type], 'extends')
|
||||
let extends = s:zen_settings[a:type].extends
|
||||
if type(extends) == 1
|
||||
@@ -231,6 +213,16 @@ function! zencoding#getResource(type, name, default)
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
if has_key(s:zen_settings[a:type], a:name)
|
||||
let v = s:zen_settings[a:type][a:name]
|
||||
if type(ret) == 3 || type(ret) == 4
|
||||
call s:mergeConfig(ret, s:zen_settings[a:type][a:name])
|
||||
else
|
||||
let ret = s:zen_settings[a:type][a:name]
|
||||
endif
|
||||
endif
|
||||
|
||||
return ret
|
||||
endfunction
|
||||
|
||||
@@ -451,6 +443,12 @@ function! zencoding#imageSize()
|
||||
return zencoding#lang#{rtype}#imageSize()
|
||||
endfunction
|
||||
|
||||
function! zencoding#encodeImage()
|
||||
let type = zencoding#getFileType()
|
||||
let rtype = len(globpath(&rtp, 'autoload/zencoding/lang/'.type.'.vim')) ? type : 'html'
|
||||
return zencoding#lang#{rtype}#encodeImage()
|
||||
endfunction
|
||||
|
||||
function! zencoding#toggleComment()
|
||||
let type = zencoding#getFileType()
|
||||
let rtype = len(globpath(&rtp, 'autoload/zencoding/lang/'.type.'.vim')) ? type : 'html'
|
||||
@@ -1339,10 +1337,30 @@ let s:zen_settings = {
|
||||
\ }
|
||||
\ },
|
||||
\ 'haml': {
|
||||
\ 'extends': 'html'
|
||||
\ 'indentation': ' ',
|
||||
\ 'extends': 'html',
|
||||
\ 'snippets': {
|
||||
\ 'html:5': "!!! 5\n"
|
||||
\ ."%html{:lang => \"${lang}\"}\n"
|
||||
\ ."\t%head\n"
|
||||
\ ."\t\t%meta{:charset => \"${charset}\"\n"
|
||||
\ ."\t\t%title\n"
|
||||
\ ."\t%body\n"
|
||||
\ ."\t\t${child}|\n"
|
||||
\ },
|
||||
\ },
|
||||
\ 'slim': {
|
||||
\ 'extends': 'html'
|
||||
\ 'indentation': ' ',
|
||||
\ 'extends': 'html',
|
||||
\ 'snippets': {
|
||||
\ 'html:5': "doctype 5\n"
|
||||
\ ."html lang=\"${lang}\"\n"
|
||||
\ ."\thead\n"
|
||||
\ ."\t\tmeta charset=\"${charset}\"\n"
|
||||
\ ."\t\ttitle\n"
|
||||
\ ."\tbody\n"
|
||||
\ ."\t\t${child}|\n"
|
||||
\ },
|
||||
\ },
|
||||
\ 'xhtml': {
|
||||
\ 'extends': 'html'
|
||||
|
||||
@@ -15,9 +15,11 @@ function! zencoding#lang#css#parseIntoTree(abbr, type)
|
||||
if tag_name =~ '.!$'
|
||||
let tag_name = tag_name[:-2]
|
||||
let important = 1
|
||||
else
|
||||
let important = 0
|
||||
endif
|
||||
" make default node
|
||||
let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': 0 }
|
||||
let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': important }
|
||||
let current.name = tag_name
|
||||
|
||||
" aliases
|
||||
@@ -45,12 +47,21 @@ function! zencoding#lang#css#parseIntoTree(abbr, type)
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#css#toString(settings, current, type, inline, filters, itemno, indent)
|
||||
return ''
|
||||
let current = a:current
|
||||
let value = current.value[1:-2]
|
||||
let value = substitute(value, '^\([^:]\+\):\([^;]*;\)', '\1: \2', '')
|
||||
if current.important
|
||||
let value = substitute(value, ';', ' !important;', '')
|
||||
endif
|
||||
return value
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#css#imageSize()
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#css#encodeImage()
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#css#parseTag(tag)
|
||||
return {}
|
||||
endfunction
|
||||
|
||||
@@ -75,6 +75,11 @@ function! zencoding#lang#haml#toString(settings, current, type, inline, filters,
|
||||
let inner = substitute(inner, "\n $", "", 'g')
|
||||
let str .= "\n " . inner
|
||||
endif
|
||||
else
|
||||
let str = current.value[1:-2]
|
||||
let str = substitute(str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let str = substitute(str, '\${nr}', "\n", 'g')
|
||||
let str = substitute(str, '\\\$', '$', 'g')
|
||||
endif
|
||||
let str .= "\n"
|
||||
return str
|
||||
@@ -101,6 +106,9 @@ function! zencoding#lang#haml#imageSize()
|
||||
call setline('.', substitute(matchstr(line, '^\s*') . haml, "\n", "", "g"))
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#haml#encodeImage()
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#haml#parseTag(tag)
|
||||
let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0 }
|
||||
let mx = '%\([a-zA-Z][a-zA-Z0-9]*\)\s*\%({\(.*\)}\)'
|
||||
|
||||
@@ -303,6 +303,14 @@ function! zencoding#lang#html#toString(settings, current, type, inline, filters,
|
||||
let current_name = substitute(current_name, '\$$', itemno+1, '')
|
||||
|
||||
let str = ''
|
||||
if len(current_name) == 0
|
||||
let text = current.value[1:-2]
|
||||
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let text = substitute(text, '\${nr}', "\n", 'g')
|
||||
let text = substitute(text, '\\\$', '$', 'g')
|
||||
return text
|
||||
endif
|
||||
if len(current_name) > 0
|
||||
let str .= '<' . current_name
|
||||
for attr in keys(current.attr)
|
||||
let val = current.attr[attr]
|
||||
@@ -392,6 +400,34 @@ function! zencoding#lang#html#imageSize()
|
||||
call zencoding#util#setContent(img_region, html)
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#html#encodeImage()
|
||||
let img_region = zencoding#util#searchRegion('<img\s', '>')
|
||||
if !zencoding#util#regionIsValid(img_region) || !zencoding#util#cursorInRegion(img_region)
|
||||
return
|
||||
endif
|
||||
let content = zencoding#util#getContent(img_region)
|
||||
if content !~ '^<img[^><]\+>$'
|
||||
return
|
||||
endif
|
||||
let current = zencoding#lang#html#parseTag(content)
|
||||
if empty(current) || !has_key(current.attr, 'src')
|
||||
return
|
||||
endif
|
||||
let fn = current.attr.src
|
||||
if fn !~ '^\(/\|http\)'
|
||||
let fn = simplify(expand('%:h') . '/' . fn)
|
||||
endif
|
||||
|
||||
let [width, height] = zencoding#util#getImageSize(fn)
|
||||
if width == -1 && height == -1
|
||||
return
|
||||
endif
|
||||
let current.attr.width = width
|
||||
let current.attr.height = height
|
||||
let html = zencoding#toString(current, 'html', 1)
|
||||
call zencoding#util#setContent(img_region, html)
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#html#parseTag(tag)
|
||||
let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0 }
|
||||
let mx = '<\([a-zA-Z][a-zA-Z0-9]*\)\(\%(\s[a-zA-Z][a-zA-Z0-9]\+=\%([^"'' \t]\+\|"[^"]\{-}"\|''[^'']\{-}''\)\s*\)*\)\(/\{0,1}\)>'
|
||||
|
||||
@@ -60,6 +60,11 @@ function! zencoding#lang#slim#toString(settings, current, type, inline, filters,
|
||||
let inner = substitute(inner, "\n $", "", 'g')
|
||||
let str .= "\n " . inner
|
||||
endif
|
||||
else
|
||||
let str = current.value[1:-2]
|
||||
let str = substitute(str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let str = substitute(str, '\${nr}', "\n", 'g')
|
||||
let str = substitute(str, '\\\$', '$', 'g')
|
||||
endif
|
||||
if str !~ "\n$"
|
||||
let str .= "\n"
|
||||
@@ -88,6 +93,9 @@ function! zencoding#lang#slim#imageSize()
|
||||
call setline('.', substitute(matchstr(line, '^\s*') . slim, "\n", "", "g"))
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#slim#encodeImage()
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#slim#parseTag(tag)
|
||||
let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0 }
|
||||
let mx = '\([a-zA-Z][a-zA-Z0-9]*\)\s\+\(.*\)'
|
||||
|
||||
@@ -532,6 +532,10 @@ finish
|
||||
'query': "bg+$$$$",
|
||||
'result': "background: #FFF url($$$$) 0 0 no-repeat;",
|
||||
},
|
||||
{
|
||||
'query': "bg+!$$$$",
|
||||
'result': "background: #FFF url($$$$) 0 0 no-repeat !important;",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user