support (bg+)+c like format.

This commit is contained in:
mattn
2012-10-24 11:13:34 +09:00
parent 95455cc4c8
commit 672af42b71

View File

@@ -8,100 +8,108 @@ function! zencoding#lang#css#parseIntoTree(abbr, type)
let prefix = 0 let prefix = 0
let value = '' let value = ''
" emmet
let prop = matchlist(abbr, '^\(-\{0,1}[a-zA-Z]\+\)\(\%([0-9.-]\+[pe]\{0,1}-\{0,1}\|-auto\)*\)$')
if len(prop)
let abbr = prop[1]
if abbr =~ '^-'
let prefix = 1
let abbr = abbr[1:]
endif
let value = ''
for v in split(prop[2], '\d\zs-')
if len(value) > 0
let value .= ' '
endif
if abbr =~ '^[z]'
" TODO
let value .= substitute(v, '[^0-9.]*$', '', '')
elseif v =~ 'p$'
let value .= substitute(v, 'p$', '%', '')
elseif v =~ 'e$'
let value .= substitute(v, 'e$', 'em', '')
elseif v =~ '\.'
let value .= v . 'em'
elseif v == 'auto'
let value .= v
else
let value .= v . 'px'
endif
endfor
endif
let settings = zencoding#getSettings() let settings = zencoding#getSettings()
let indent = zencoding#getIndentation(type) let indent = zencoding#getIndentation(type)
let root = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': 0 } let root = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': 0 }
let tag_name = abbr " emmet
if tag_name =~ '.!$' let tokens = split(abbr, '+\ze[^)!]')
let tag_name = tag_name[:-2] for n in range(len(tokens))
let important = 1 let token = tokens[n]
else let prop = matchlist(token, '^\(-\{0,1}[a-zA-Z]\+\|[a-zA-Z0-9]\++\{0,1}\|([a-zA-Z0-9]\++\{0,1})\)\(\%([0-9.-]\+[pe]\{0,1}-\{0,1}\|-auto\)*\)$')
let important = 0 if len(prop)
endif let token = substitute(prop[1], '^(\(.*\))', '\1', '')
" make default node if token =~ '^-'
let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': important } let prefix = 1
let current.name = tag_name let token = token[1:]
endif
" aliases let value = ''
let aliases = zencoding#getResource(type, 'aliases', {}) for v in split(prop[2], '\d\zs-')
if has_key(aliases, tag_name) if len(value) > 0
let current.name = aliases[tag_name] let value .= ' '
endif endif
let use_pipe_for_cursor = zencoding#getResource(type, 'use_pipe_for_cursor', 1) if token =~ '^[z]'
" TODO
" snippets let value .= substitute(v, '[^0-9.]*$', '', '')
let snippets = zencoding#getResource(type, 'snippets', {}) elseif v =~ 'p$'
if !empty(snippets) && has_key(snippets, tag_name) let value .= substitute(v, 'p$', '%', '')
let snippet = snippets[tag_name] elseif v =~ 'e$'
if use_pipe_for_cursor let value .= substitute(v, 'e$', 'em', '')
let snippet = substitute(snippet, '|', '${cursor}', 'g') elseif v =~ '\.'
let value .= v . 'em'
elseif v == 'auto'
let value .= v
else
let value .= v . 'px'
endif
endfor
endif endif
let lines = split(snippet, "\n")
call map(lines, 'substitute(v:val, "\\( \\|\\t\\)", escape(indent, "\\\\"), "g")') let tag_name = token
let current.snippet = join(lines, "\n") if tag_name =~ '.!$'
let current.name = '' let tag_name = tag_name[:-2]
let current.snippet = substitute(current.snippet, ';', value . ';', '') let important = 1
if use_pipe_for_cursor else
let current.snippet = substitute(current.snippet, '${cursor}', '', 'g') . '${cursor}' let important = 0
endif endif
endif " make default node
let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': important }
let current.pos = 0 let current.name = tag_name
let lg = matchlist(abbr, '^\%(linear-gradient\|lg\)(\s*\(\w\+\)\s*,\s*\([^,]\+\)\s*,\s*\([^)]\+\)\s*)$')
if len(lg) " aliases
let current.name = '' let aliases = zencoding#getResource(type, 'aliases', {})
let current.snippet = printf("background-image: -webkit-gradient(%s, 0 0, 0 100%, from(%s), to(%s));\n", lg[1], lg[2], lg[3]) if has_key(aliases, tag_name)
call add(root.child, deepcopy(current)) let current.name = aliases[tag_name]
let current.snippet = printf("background-image: -webkit-linear-gradient(%s, %s);\n", lg[2], lg[3]) endif
call add(root.child, deepcopy(current)) let use_pipe_for_cursor = zencoding#getResource(type, 'use_pipe_for_cursor', 1)
let current.snippet = printf("background-image: -moz-linear-gradient(%s, %s);\n", lg[2], lg[3])
call add(root.child, deepcopy(current)) " snippets
let current.snippet = printf("background-image: -o-linear-gradient(%s, %s);\n", lg[2], lg[3]) let snippets = zencoding#getResource(type, 'snippets', {})
call add(root.child, deepcopy(current)) if !empty(snippets) && has_key(snippets, tag_name)
let current.snippet = printf("background-image: linear-gradient(%s, %s);\n", lg[2], lg[3]) let snippet = snippets[tag_name]
call add(root.child, deepcopy(current)) if use_pipe_for_cursor
elseif prefix let snippet = substitute(snippet, '|', '${cursor}', 'g')
let snippet = current.snippet endif
let current.snippet = '-webkit-' . snippet . "\n" let lines = split(snippet, "\n")
call add(root.child, deepcopy(current)) call map(lines, 'substitute(v:val, "\\( \\|\\t\\)", escape(indent, "\\\\"), "g")')
let current.snippet = '-moz-' . snippet . "\n" let current.snippet = join(lines, "\n")
call add(root.child, deepcopy(current)) let current.name = ''
let current.snippet = snippet let current.snippet = substitute(current.snippet, ';', value . ';', '')
call add(root.child, current) if use_pipe_for_cursor && len(value) > 0 && stridx(value, '${cursor}') == -1
else let current.snippet = substitute(current.snippet, '${cursor}', '', 'g') . '${cursor}'
call add(root.child, current) endif
endif if n < len(tokens) - 1
let current.snippet .= "\n"
endif
endif
let current.pos = 0
let lg = matchlist(token, '^\%(linear-gradient\|lg\)(\s*\(\w\+\)\s*,\s*\([^,]\+\)\s*,\s*\([^)]\+\)\s*)$')
if len(lg)
let current.name = ''
let current.snippet = printf("background-image: -webkit-gradient(%s, 0 0, 0 100%, from(%s), to(%s));\n", lg[1], lg[2], lg[3])
call add(root.child, deepcopy(current))
let current.snippet = printf("background-image: -webkit-linear-gradient(%s, %s);\n", lg[2], lg[3])
call add(root.child, deepcopy(current))
let current.snippet = printf("background-image: -moz-linear-gradient(%s, %s);\n", lg[2], lg[3])
call add(root.child, deepcopy(current))
let current.snippet = printf("background-image: -o-linear-gradient(%s, %s);\n", lg[2], lg[3])
call add(root.child, deepcopy(current))
let current.snippet = printf("background-image: linear-gradient(%s, %s);\n", lg[2], lg[3])
call add(root.child, deepcopy(current))
elseif prefix
let snippet = current.snippet
let current.snippet = '-webkit-' . snippet . "\n"
call add(root.child, deepcopy(current))
let current.snippet = '-moz-' . snippet . "\n"
call add(root.child, deepcopy(current))
let current.snippet = snippet
call add(root.child, current)
else
call add(root.child, current)
endif
endfor
return root return root
endfunction endfunction