Source

frawor / plugin / frawor / resources.vim

"▶1 Header
scriptencoding utf-8
execute frawor#Setup('0.0', {}, 1)
"▶1 Define messages
if v:lang=~?'ru'
    let s:_messages={
                \    'ridnstr': 'Ошибка создания ресурса дополнения %s: '.
                \               'имя ресурса не является строкой',
                \   'ridempty': 'Ошибка создания ресурса дополнения %s: '.
                \               'имя ресурсо пусто',
                \  'ridexists': 'Ошибка создания ресурса %s дополнения %s: '.
                \               'данный ресурс уже создан дополнением %s',
                \  'invrcpfun': 'Ошибка создания ресурса %s дополнения %s: '.
                \               'дополнительный аргумент неверен',
            \}
else
    let s:_messages={
                \    'ridnstr': 'Error while posting resource for plugin %s: '.
                \               'resource ID is not a String',
                \   'ridempty': 'Error while posting resource for plugin %s: '.
                \               'resource ID is empty',
                \  'ridexists': 'Error while posting resource %s '.
                \               'for plugin %s: resource was already defined '.
                \               'by plugin %s',
                \  'invrcpfun': 'Error while posting resource %s '.
                \               'for plugin %s: invalid copy function',
            \}
endif
"▶1 id
function s:F.id(val)
    return a:val
endfunction
"▶1 resource feature
"▶2 postresource :: {f}, rid, resource[, cpf] → + s:postedress, s:plugresources
let s:plugresources={}
let s:postedress={}
function s:F.postresource(plugdict, fdict, rid, resource, ...)
    "▶3 Check arguments
    if type(a:rid)!=type('')
        call s:_f.throw('ridnstr', a:plugdict.id)
    elseif empty(a:rid)
        call s:_f.throw('ridempty', a:plugdict.id)
    elseif has_key(s:postedress, a:rid)
        call s:_f.throw('ridexists', a:plugdict.id, a:rid,
                    \                s:postedress[a:rid].plid)
    elseif a:0 && a:1 isnot 1 && a:1 isnot 0 && !exists('*a:1')
        call s:_f.throw('invrcpfun')
    endif
    "▶3 Add fdict to plugresources
    if !has_key(s:plugresources, a:plugdict.id)
        let s:plugresources[a:plugdict.id]=a:fdict
    endif
    "▲3
    let s:postedress[a:rid]={'id': a:rid,
                \          'plid': a:plugdict.id,}
    if a:0 && a:1 isnot 0
        if a:1 is 1
            let s:postedress[a:rid].resource=a:resource
            let s:postedress[a:rid].copyfunc=s:F.id
        else
            let s:postedress[a:rid].resource=deepcopy(a:resource)
            let s:postedress[a:rid].copyfunc=a:1
        endif
    else
        let s:postedress[a:rid].resource=deepcopy(a:resource)
        let s:postedress[a:rid].copyfunc=function('deepcopy')
    endif
    let a:fdict[a:rid]=s:postedress[a:rid]
endfunction
"▶2 delresources :: {f} → + s:postedress, s:plugresources
function s:F.delresources(plugdict, fdict)
    call map(keys(a:fdict), 'remove(s:postedress, v:val)')
    if has_key(s:plugresources, a:plugdict.id)
        unlet s:plugresources[a:plugdict.id]
    endif
endfunction
"▶2 Register feature
call s:_f.newfeature('postresource', {'cons': s:F.postresource,
            \                       'unload': s:F.delresources,})
"▶1 addresource feature
function s:F.addresource(plugdict, fdict)
    let r={}
    call map(map(filter(keys(a:plugdict.dependencies),
                \'has_key(s:plugresources, v:val)'),
                \'s:plugresources[v:val]'),
                \'map(values(v:val), '.
                \    '"extend(r,{v:val.id : v:val.copyfunc(v:val.resource)})")')
    let a:plugdict.g._r=r
endfunction
call s:_f.newfeature('addresource', {'load': s:F.addresource, 'ignoredeps': 1,})
"▶1
call frawor#Lockvar(s:, 'postedress,plugresources')
" TODO resources redefinition
" vim: fmr=▶,▲ sw=4 ts=4 sts=4 et tw=80
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.