fix snippets for haml & slim.

This commit is contained in:
mattn
2012-06-11 19:15:45 +09:00
parent 5011ea1dc6
commit d19b2b4fcd
6 changed files with 109 additions and 24 deletions

View File

@@ -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

View File

@@ -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*\%({\(.*\)}\)'

View File

@@ -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}\)>'

View File

@@ -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\+\(.*\)'