Commits

ZyX_I committed 65d17e3

@/resources: Added ability to define more then one resource with same name

Comments (0)

Files changed (3)

                                                        *frawor-f-postresource*
 postresource : function ({rid}, {resource}[, {copyfunc}])
              + register, unload
-        Create resource (|deepcopy()| of {resource}) with given {rid}. This 
-        feature is now used only to provide access to plugin functions that 
-        don't have to know anything about a caller. Additional argument 
-        determines what should be done when resource is requested:
+        Create resource (copy of {resource}) with given {rid}. This feature is 
+        now used only to provide access to plugin functions that don't have to 
+        know anything about a caller. Additional argument determines what 
+        should be done when resource is requested:
         1. If it is `0' (default), then resource is deepcopied (|deepcopy()|) 
            for each plugin.
         2. If it is a reference to a function, then {resource} is deepcopied 

plugin/frawor/resources.vim

                 \               'имя ресурса не является строкой',
                 \   'ridempty': 'Ошибка создания ресурса дополнения %s: '.
                 \               'имя ресурсо пусто',
+                \   'ridslash': 'Ошибка создания ресурса дополнения %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',
+                \               'resource name is not a String',
                 \   'ridempty': 'Error while posting resource for plugin %s: '.
-                \               'resource ID is empty',
+                \               'resource name is empty',
+                \   'ridslash': 'Error while posting resource for plugin %s: '.
+                \               'slashes are not allowed in resource name',
                 \  'ridexists': 'Error while posting resource %s '.
                 \               'for plugin %s: resource was already defined '.
                 \               'by plugin %s',
     return a:val
 endfunction
 "▶1 resource feature
-"▶2 postresource :: {f}, rid, resource[, cpf] → + s:postedress, s:plugresources
+"▶2 postresource :: {f}, rid, resource[, cpf] → + 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
         let s:plugresources[a:plugdict.id]=a:fdict
     endif
     "▲3
-    let s:postedress[a:rid]={'id': a:rid,
-                \          'plid': a:plugdict.id,}
+    let r={'name': a:rid,}
     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
+            let r.resource=a:resource
+            let r.copyfunc=s:F.id
         else
-            let s:postedress[a:rid].resource=deepcopy(a:resource)
-            let s:postedress[a:rid].copyfunc=a:1
+            let r.resource=deepcopy(a:resource)
+            let r.copyfunc=a:1
         endif
     else
-        let s:postedress[a:rid].resource=deepcopy(a:resource)
-        let s:postedress[a:rid].copyfunc=function('deepcopy')
+        let r.resource=deepcopy(a:resource)
+        let r.copyfunc=function('deepcopy')
     endif
-    let a:fdict[a:rid]=s:postedress[a:rid]
+    let a:fdict[a:rid]=r
 endfunction
-"▶2 delresources :: {f} → + s:postedress, s:plugresources
+"▶2 delresources :: {f} → + 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
                 \'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)})")')
+                \    '"extend(r, '.
+                \            '{v:val.name : 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
+call frawor#Lockvar(s:, 'plugresources')
 " vim: fmr=▶,▲ sw=4 ts=4 sts=4 et tw=80

test/invalid-postresource.ok

 .1: plugin/frawor/resources:ridnstr
 .2: plugin/frawor/resources:ridnstr
-.3: plugin/frawor/resources:ridexists
 .4: plugin/frawor/resources:ridempty
 .5: plugin/frawor/resources:invrcpfun
 .6: plugin/frawor/resources:invrcpfun
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.