Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

30
LINES

< > BotCompany Repo | #1029946 // resourceLoaderFromDir [untested, but should work]

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4510L/30K).

1  
static IResourceLoader resourceLoaderFromDir(File dir) {
2  
  ret new IResourceLoader {
3  
    public S loadSnippet(S snippetID) {
4  
      ret loadTextFile(newFile(dir, psI(snippetID) + ".text"));
5  
    }
6  
    
7  
    public S getTranspiled(S snippetID) {
8  
      S src = loadTextFile(newFile(dir, psI(snippetID) + ".transpiled"));
9  
      if (empty(src))
10  
        print("Warning: Transpilation for " + snippetID + " not found");
11  
      ret src;
12  
    }
13  
    
14  
    public int getSnippetType(S snippetID) {
15  
      ret parseInt(loadTextFileTrim(newFile(dir, snippetID + ".type")));
16  
    }
17  
    
18  
    public S getSnippetTitle(S snippetID) {
19  
      ret loadTextFileTrim(newFile(dir, snippetID + ".title"));
20  
    }
21  
    
22  
    public File loadLibrary(S snippetID) {
23  
      long id = psI(snippetID);
24  
      if (isImageServerSnippet(id)) 
25  
        ret assertIsFile(oneOfTheFilesInDir(dir, id + ".png", id + ".gif"));
26  
      else
27  
        ret assertIsFile(newFile(dir, id + ".bin"));
28  
    }
29  
  };
30  
}

Author comment

Began life as a copy of #1022668

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1029946
Snippet name: resourceLoaderFromDir [untested, but should work]
Eternal ID of this version: #1029946/5
Text MD5: 4167723a76aac69fcfe2f3586226cb5d
Transpilation MD5: 5e06f5703916c17d6083429f397cc654
Author: stefan
Category: javax / packaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-10-14 14:04:04
Source code size: 979 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 210 / 300
Version history: 4 change(s)
Referenced in: [show references]