From fb096ac4d45fd51620d09ac463f3e466e1f9565c Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 25 Nov 2013 01:35:26 +0900 Subject: [PATCH] Support boolean attributes, related issue #170 --- autoload/emmet/lang/haml.vim | 36 ++++++++++++---------- autoload/emmet/lang/html.vim | 59 ++++++++++++++++++++++++------------ autoload/emmet/lang/slim.vim | 18 ++++++----- 3 files changed, 70 insertions(+), 43 deletions(-) diff --git a/autoload/emmet/lang/haml.vim b/autoload/emmet/lang/haml.vim index 6b41983..9e1a418 100644 --- a/autoload/emmet/lang/haml.vim +++ b/autoload/emmet/lang/haml.vim @@ -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] - if dollar_expr - 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}', '', '') - if attr == 'id' && len(valtmp) > 0 - let str .= '#' . val - elseif attr == 'class' && len(valtmp) > 0 - let str .= '.' . substitute(val, ' ', '.', 'g') - else - if len(tmp) > 0 | let tmp .= ',' | endif - let val = substitute(val, '\${cursor}', '', '') - let tmp .= ' :' . attr . ' => "' . val . '"' + 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') + endwhile + let attr = substitute(attr, '\$$', itemno+1, '') + endif + let valtmp = substitute(Val, '\${cursor}', '', '') + if attr == 'id' && len(valtmp) > 0 + let str .= '#' . Val + elseif attr == 'class' && len(valtmp) > 0 + let str .= '.' . substitute(Val, ' ', '.', 'g') + else + if len(tmp) > 0 | let tmp .= ',' | endif + let Val = substitute(Val, '\${cursor}', '', '') + let tmp .= ' :' . attr . ' => "' . Val . '"' + endif endif endfor if len(tmp) diff --git a/autoload/emmet/lang/html.vim b/autoload/emmet/lang/html.vim index b34ddc4..9ccc769 100644 --- a/autoload/emmet/lang/html.vim +++ b/autoload/emmet/lang/html.vim @@ -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] - if dollar_expr - while val =~ '\$\([^#{]\|$\)' - " TODO: regexp engine specified - if exists('®expengine') - 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') - endif - endwhile - let attr = substitute(attr, '\$$', itemno+1, '') - endif - let str .= ' ' . attr . '="' . val . '"' - if emmet#useFilter(filters, 'c') - if attr == 'id' | let comment .= '#' . val | endif - if attr == 'class' | let comment .= '.' . val | endif + 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 =~ '\$\([^#{]\|$\)' + " TODO: regexp engine specified + if exists('®expengine') + 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') + endif + endwhile + let attr = substitute(attr, '\$$', itemno+1, '') + endif + let str .= ' ' . attr . '="' . Val . '"' + if emmet#useFilter(filters, 'c') + if attr == 'id' | let comment .= '#' . Val | endif + if attr == 'class' | let comment .= '.' . Val | endif + endif endif endfor if len(comment) > 0 diff --git a/autoload/emmet/lang/slim.vim b/autoload/emmet/lang/slim.vim index 43161b9..8a6967a 100644 --- a/autoload/emmet/lang/slim.vim +++ b/autoload/emmet/lang/slim.vim @@ -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] - if dollar_expr - while val =~ '\$\([^#{]\|$\)' - let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') - endwhile + 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') + endwhile + endif + let attr = substitute(attr, '\$$', itemno+1, '') + let str .= ' ' . attr . '="' . Val . '"' endif - let attr = substitute(attr, '\$$', itemno+1, '') - let str .= ' ' . attr . '="' . val . '"' endfor let inner = ''