Support boolean attributes, related issue #170

This commit is contained in:
mattn
2013-11-25 01:35:26 +09:00
parent 8c1e42340d
commit fb096ac4d4
3 changed files with 70 additions and 43 deletions

View File

@@ -30,22 +30,26 @@ function! emmet#lang#haml#toString(settings, current, type, inline, filters, ite
if !has_key(current.attr, attr)
continue
endif
let val = current.attr[attr]
let Val = current.attr[attr]
if type(Val) == 2 && Val == function('emmet#types#true')
let tmp .= ' :' . attr . ' => true'
else
if dollar_expr
while val =~ '\$\([^#{]\|$\)'
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
while Val =~ '\$\([^#{]\|$\)'
let Val = substitute(Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
endwhile
let attr = substitute(attr, '\$$', itemno+1, '')
endif
let valtmp = substitute(val, '\${cursor}', '', '')
let valtmp = substitute(Val, '\${cursor}', '', '')
if attr == 'id' && len(valtmp) > 0
let str .= '#' . val
let str .= '#' . Val
elseif attr == 'class' && len(valtmp) > 0
let str .= '.' . substitute(val, ' ', '.', 'g')
let str .= '.' . substitute(Val, ' ', '.', 'g')
else
if len(tmp) > 0 | let tmp .= ',' | endif
let val = substitute(val, '\${cursor}', '', '')
let tmp .= ' :' . attr . ' => "' . val . '"'
let Val = substitute(Val, '\${cursor}', '', '')
let tmp .= ' :' . attr . ' => "' . Val . '"'
endif
endif
endfor
if len(tmp)

View File

@@ -197,15 +197,20 @@ function! emmet#lang#html#parseIntoTree(abbr, type)
break
endif
let key = split(amat, '=')[0]
let val = amat[len(key)+1:]
if val =~ '^["'']'
let val = val[1:-2]
let Val = amat[len(key)+1:]
if key =~ '\.$' && Val == ''
let key = key[:-2]
unlet Val
let Val = function('emmet#types#true')
elseif Val =~ '^["'']'
let Val = Val[1:-2]
endif
let current.attr[key] = val
let current.attr[key] = Val
if index(current.attrs_order, key) == -1
let current.attrs_order += [key]
endif
let atts = atts[stridx(atts, amat) + len(amat):]
unlet Val
endwhile
endif
let attr = substitute(strpart(attr, len(item)), '^\s*', '', '')
@@ -355,22 +360,36 @@ function! emmet#lang#html#toString(settings, current, type, inline, filters, ite
if !has_key(current.attr, attr)
continue
endif
let val = current.attr[attr]
let Val = current.attr[attr]
if type(Val) == 2 && Val == function('emmet#types#true')
unlet Val
let Val = 'true'
if g:emmet_html5
let str .= ' ' . attr
else
let str .= ' ' . attr . '="' . attr . '"'
endif
if emmet#useFilter(filters, 'c')
if attr == 'id' | let comment .= '#' . Val | endif
if attr == 'class' | let comment .= '.' . Val | endif
endif
else
if dollar_expr
while val =~ '\$\([^#{]\|$\)'
while Val =~ '\$\([^#{]\|$\)'
" TODO: regexp engine specified
if exists('&regexpengine')
let val = substitute(val, '\%#=1\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
let Val = substitute(Val, '\%#=1\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
else
let val = substitute(val, '\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
let Val = substitute(Val, '\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
endif
endwhile
let attr = substitute(attr, '\$$', itemno+1, '')
endif
let str .= ' ' . attr . '="' . val . '"'
let str .= ' ' . attr . '="' . Val . '"'
if emmet#useFilter(filters, 'c')
if attr == 'id' | let comment .= '#' . val | endif
if attr == 'class' | let comment .= '.' . val | endif
if attr == 'id' | let comment .= '#' . Val | endif
if attr == 'class' | let comment .= '.' . Val | endif
endif
endif
endfor
if len(comment) > 0

View File

@@ -29,14 +29,18 @@ function! emmet#lang#slim#toString(settings, current, type, inline, filters, ite
if !has_key(current.attr, attr)
continue
endif
let val = current.attr[attr]
let Val = current.attr[attr]
if type(Val) == 2 && Val == function('emmet#types#true')
let str .= ' ' . attr . '=true'
else
if dollar_expr
while val =~ '\$\([^#{]\|$\)'
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
while Val =~ '\$\([^#{]\|$\)'
let Val = substitute(Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
endwhile
endif
let attr = substitute(attr, '\$$', itemno+1, '')
let str .= ' ' . attr . '="' . val . '"'
let str .= ' ' . attr . '="' . Val . '"'
endif
endfor
let inner = ''