mirror of
https://github.com/mattn/emmet-vim.git
synced 2026-10-19 12:21:25 +08:00
Refactoring
This commit is contained in:
14 files changed
+2452
-2452
No files matched your search
+90
-90
@@ -3,24 +3,24 @@ function! emmet#lang#elm#findTokens(str) abort
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#elm#parseIntoTree(abbr, type) abort
|
||||
let tree = emmet#lang#html#parseIntoTree(a:abbr, a:type)
|
||||
if len(tree.child) < 2 | return tree | endif
|
||||
let l:tree = emmet#lang#html#parseIntoTree(a:abbr, a:type)
|
||||
if len(l:tree.child) < 2 | return l:tree | endif
|
||||
|
||||
" Add ',' nodes between root elements.
|
||||
let new_children = []
|
||||
for child in tree.child[0:-2]
|
||||
let comma = emmet#newNode()
|
||||
let comma.name = ','
|
||||
call add(new_children, child)
|
||||
call add(new_children, comma)
|
||||
let l:new_children = []
|
||||
for l:child in l:tree.child[0:-2]
|
||||
let l:comma = emmet#newNode()
|
||||
let l:comma.name = ','
|
||||
call add(l:new_children, l:child)
|
||||
call add(l:new_children, l:comma)
|
||||
endfor
|
||||
call add(new_children, tree.child[-1])
|
||||
let tree.child = new_children
|
||||
return tree
|
||||
call add(l:new_children, l:tree.child[-1])
|
||||
let l:tree.child = l:new_children
|
||||
return l:tree
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#elm#renderNode(node)
|
||||
let elm_nodes = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'
|
||||
let l:elm_nodes = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'
|
||||
\, 'div', 'p', 'hr', 'pre', 'blockquote'
|
||||
\, 'span', 'a', 'code', 'em', 'strong', 'i', 'b', 'u', 'sub', 'sup', 'br'
|
||||
\, 'ol', 'ul', 'li', 'dl', 'dt', 'dd'
|
||||
@@ -37,14 +37,14 @@ function! emmet#lang#elm#renderNode(node)
|
||||
\, 'mark', 'ruby', 'rt', 'rp', 'bdi', 'bdo', 'wbr'
|
||||
\, 'details', 'summary', 'menuitem', 'menu']
|
||||
|
||||
if index(elm_nodes, a:node) >= 0
|
||||
if index(l:elm_nodes, a:node) >= 0
|
||||
return a:node
|
||||
endif
|
||||
return 'node "' . a:node . '"'
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#elm#renderParam(param)
|
||||
let elm_events = ["onClick", "onDoubleClick"
|
||||
let l:elm_events = ["onClick", "onDoubleClick"
|
||||
\, "onMouseDown", "onMouseUp"
|
||||
\, "onMouseEnter", "onMouseLeave"
|
||||
\, "onMouseOver", "onMouseOut"
|
||||
@@ -52,10 +52,10 @@ function! emmet#lang#elm#renderParam(param)
|
||||
\, "onBlur", "onFocus"
|
||||
\, "on", "onWithOptions", "Options", "defaultOptions"
|
||||
\, "targetValue", "targetChecked", "keyCode"]
|
||||
if index(elm_events, a:param) >= 0
|
||||
if index(l:elm_events, a:param) >= 0
|
||||
return a:param
|
||||
endif
|
||||
let elm_attributes = ["style", "map" , "class", "id", "title", "hidden"
|
||||
let l:elm_attributes = ["style", "map" , "class", "id", "title", "hidden"
|
||||
\, "type", "type_", "value", "defaultValue", "checked", "placeholder", "selected"
|
||||
\, "accept", "acceptCharset", "action", "autocomplete", "autofocus"
|
||||
\, "disabled", "enctype", "formaction", "list", "maxlength", "minlength", "method", "multiple"
|
||||
@@ -75,7 +75,7 @@ function! emmet#lang#elm#renderParam(param)
|
||||
\, "challenge", "keytype"
|
||||
\, "cite", "datetime", "pubdate", "manifest"]
|
||||
|
||||
if index(elm_attributes, a:param) >= 0
|
||||
if index(l:elm_attributes, a:param) >= 0
|
||||
if a:param == 'type'
|
||||
return 'type_'
|
||||
endif
|
||||
@@ -85,130 +85,130 @@ function! emmet#lang#elm#renderParam(param)
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#elm#toString(settings, current, type, inline, filters, itemno, indent) abort
|
||||
let settings = a:settings
|
||||
let current = a:current
|
||||
let type = a:type
|
||||
let inline = a:inline
|
||||
let filters = a:filters
|
||||
let itemno = a:itemno
|
||||
let indent = emmet#getIndentation(type)
|
||||
let dollar_expr = emmet#getResource(type, 'dollar_expr', 1)
|
||||
let str = ''
|
||||
let l:settings = a:settings
|
||||
let l:current = a:current
|
||||
let l:type = a:type
|
||||
let l:inline = a:inline
|
||||
let l:filters = a:filters
|
||||
let l:itemno = a:itemno
|
||||
let l:indent = emmet#getIndentation(l:type)
|
||||
let l:dollar_expr = emmet#getResource(l:type, 'dollar_expr', 1)
|
||||
let l:str = ''
|
||||
|
||||
" comma between items with *, eg. li*3
|
||||
if itemno > 0
|
||||
let str = ", "
|
||||
if l:itemno > 0
|
||||
let l:str = ", "
|
||||
endif
|
||||
|
||||
let current_name = current.name
|
||||
if dollar_expr
|
||||
let current_name = substitute(current.name, '\$$', itemno+1, '')
|
||||
let l:current_name = l:current.name
|
||||
if l:dollar_expr
|
||||
let l:current_name = substitute(l:current.name, '\$$', l:itemno+1, '')
|
||||
endif
|
||||
|
||||
if len(current.name) > 0
|
||||
if len(l:current.name) > 0
|
||||
" inserted root comma nodes
|
||||
if current_name == ','
|
||||
if l:current_name == ','
|
||||
return "\n, "
|
||||
endif
|
||||
let str .= emmet#lang#elm#renderNode(current_name)
|
||||
let tmp = ''
|
||||
for attr in emmet#util#unique(current.attrs_order + keys(current.attr))
|
||||
if !has_key(current.attr, attr)
|
||||
let l:str .= emmet#lang#elm#renderNode(l:current_name)
|
||||
let l:tmp = ''
|
||||
for l:attr in emmet#util#unique(l:current.attrs_order + keys(l:current.attr))
|
||||
if !has_key(l:current.attr, l:attr)
|
||||
continue
|
||||
endif
|
||||
let Val = current.attr[attr]
|
||||
let l:Val = l:current.attr[l:attr]
|
||||
|
||||
let attr = emmet#lang#elm#renderParam(attr)
|
||||
let l:attr = emmet#lang#elm#renderParam(l:attr)
|
||||
|
||||
if type(Val) == 2 && Val == function('emmet#types#true')
|
||||
let tmp .= ', ' . attr . ' True'
|
||||
if type(l:Val) == 2 && l:Val == function('emmet#types#true')
|
||||
let l:tmp .= ', ' . l:attr . ' True'
|
||||
else
|
||||
if dollar_expr
|
||||
while Val =~# '\$\([^#{]\|$\)'
|
||||
let Val = substitute(Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
if l:dollar_expr
|
||||
while l:Val =~# '\$\([^#{]\|$\)'
|
||||
let l:Val = substitute(l:Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
endwhile
|
||||
let attr = substitute(attr, '\$$', itemno+1, '')
|
||||
let l:attr = substitute(l:attr, '\$$', l:itemno+1, '')
|
||||
endif
|
||||
let valtmp = substitute(Val, '\${cursor}', '', '')
|
||||
if attr ==# 'id' && len(valtmp) > 0
|
||||
let tmp .=', id "' . Val . '"'
|
||||
elseif attr ==# 'class' && len(valtmp) > 0
|
||||
let tmp .= ', class "' . substitute(Val, '\.', ' ', 'g') . '"'
|
||||
let l:valtmp = substitute(l:Val, '\${cursor}', '', '')
|
||||
if l:attr ==# 'id' && len(l:valtmp) > 0
|
||||
let l:tmp .=', id "' . l:Val . '"'
|
||||
elseif l:attr ==# 'class' && len(l:valtmp) > 0
|
||||
let l:tmp .= ', class "' . substitute(l:Val, '\.', ' ', 'g') . '"'
|
||||
else
|
||||
let tmp .= ', ' . attr . ' "' . Val . '"'
|
||||
let l:tmp .= ', ' . l:attr . ' "' . l:Val . '"'
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
|
||||
if ! len(tmp)
|
||||
let str .= ' []'
|
||||
if ! len(l:tmp)
|
||||
let l:str .= ' []'
|
||||
else
|
||||
let tmp = strpart(tmp, 2)
|
||||
let str .= ' [ ' . tmp . ' ]'
|
||||
let l:tmp = strpart(l:tmp, 2)
|
||||
let l:str .= ' [ ' . l:tmp . ' ]'
|
||||
endif
|
||||
|
||||
" No children quit early
|
||||
if len(current.child) == 0 && len(current.value) == 0
|
||||
if len(l:current.child) == 0 && len(l:current.value) == 0
|
||||
"Place cursor in node with no value or children
|
||||
let str .= ' [${cursor}]'
|
||||
return str
|
||||
let l:str .= ' [${cursor}]'
|
||||
return l:str
|
||||
endif
|
||||
|
||||
let inner = ''
|
||||
let l:inner = ''
|
||||
|
||||
" Parent contex text
|
||||
if len(current.value) > 0
|
||||
let text = current.value[1:-2]
|
||||
if dollar_expr
|
||||
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')
|
||||
" let str = substitute(str, '\$#', text, 'g')
|
||||
let inner .= ', text "' . text . '"'
|
||||
if len(l:current.value) > 0
|
||||
let l:text = l:current.value[1:-2]
|
||||
if l:dollar_expr
|
||||
let l:text = substitute(l:text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
let l:text = substitute(l:text, '\${nr}', "\n", 'g')
|
||||
let l:text = substitute(l:text, '\\\$', '$', 'g')
|
||||
" let l:str = substitute(l:str, '\$#', l:text, 'g')
|
||||
let l:inner .= ', text "' . l:text . '"'
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
" Has children
|
||||
for child in current.child
|
||||
if len(child.name) == 0 && len(child.value) > 0
|
||||
for l:child in l:current.child
|
||||
if len(l:child.name) == 0 && len(l:child.value) > 0
|
||||
" Text node
|
||||
let text = child.value[1:-2]
|
||||
if dollar_expr
|
||||
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')
|
||||
let l:text = l:child.value[1:-2]
|
||||
if l:dollar_expr
|
||||
let l:text = substitute(l:text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
let l:text = substitute(l:text, '\${nr}', "\n", 'g')
|
||||
let l:text = substitute(l:text, '\\\$', '$', 'g')
|
||||
endif
|
||||
let inner .= ', text "' . text . '"'
|
||||
let l:inner .= ', text "' . l:text . '"'
|
||||
else
|
||||
" Other nodes
|
||||
let inner .= ', ' . emmet#toString(child, type, inline, filters, 0, indent)
|
||||
let l:inner .= ', ' . emmet#toString(l:child, l:type, l:inline, l:filters, 0, l:indent)
|
||||
endif
|
||||
endfor
|
||||
|
||||
let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g')
|
||||
let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g')
|
||||
let inner = strpart(inner, 2)
|
||||
let l:inner = substitute(l:inner, "\n", "\n" . escape(l:indent, '\'), 'g')
|
||||
let l:inner = substitute(l:inner, "\n" . escape(l:indent, '\') . '$', '', 'g')
|
||||
let l:inner = strpart(l:inner, 2)
|
||||
|
||||
let inner = substitute(inner, ' ', '', 'g')
|
||||
let l:inner = substitute(l:inner, ' ', '', 'g')
|
||||
|
||||
if ! len(inner)
|
||||
let str .= ' []'
|
||||
if ! len(l:inner)
|
||||
let l:str .= ' []'
|
||||
else
|
||||
let str .= ' [ ' . inner . ' ]'
|
||||
let l:str .= ' [ ' . l:inner . ' ]'
|
||||
endif
|
||||
|
||||
else
|
||||
let str = current.value[1:-2]
|
||||
if dollar_expr
|
||||
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')
|
||||
let l:str = l:current.value[1:-2]
|
||||
if l:dollar_expr
|
||||
let l:str = substitute(l:str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
let l:str = substitute(l:str, '\${nr}', "\n", 'g')
|
||||
let l:str = substitute(l:str, '\\\$', '$', 'g')
|
||||
endif
|
||||
endif
|
||||
|
||||
let str .= "\n"
|
||||
return str
|
||||
let l:str .= "\n"
|
||||
return l:str
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#elm#imageEncode() abort
|
||||
|
||||
Reference in new issue
Block a user