works in iojs and browser :-)
This commit is contained in:
		
							parent
							
								
									5f1fb35758
								
							
						
					
					
						commit
						a6ff165e6b
					
				
							
								
								
									
										13
									
								
								desirae.js
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								desirae.js
									
									
									
									
									
								
							| @ -16,11 +16,12 @@ | ||||
|   } | ||||
| 
 | ||||
|   if (!exports.window) { | ||||
|     Desi.sha1sum  = require('./lib/node-adapters').sha1sum; | ||||
|     Desi.fsapi    = require('./lib/node-adapters').fsapi; | ||||
|     Desi.sha1sum    = require('./lib/node-adapters').sha1sum; | ||||
|     Desi.fsapi      = require('./lib/node-adapters').fsapi; | ||||
|     Desi.realFsapi  = require('./lib/node-adapters').realFsapi; | ||||
| 
 | ||||
|     // adds helper methods to fsapi
 | ||||
|     require('./lib/desirae-utils').create(Desi); | ||||
|     require('./lib/utils').create(Desi); | ||||
|     // adds Desi.Frontmatter
 | ||||
|     require('./lib/frontmatter').create(Desi); | ||||
|   } | ||||
| @ -245,7 +246,11 @@ | ||||
|   }; | ||||
| 
 | ||||
|   // read config and such
 | ||||
|   Desi.init = function (desi) { | ||||
|   Desi.init = function (desi, env) { | ||||
|     if (!exports.window) { | ||||
|       // TODO pull state out of this later
 | ||||
|       Desi.realFsapi.create(Desi, env); | ||||
|     } | ||||
|     // config.yml, data.yml, site.yml, authors
 | ||||
|     return PromiseA.all([Desi.fsapi.getAllConfigFiles()/*, fsapi.getBlogdir()*/]).then(function (plop) { | ||||
|       var arr = plop[0] | ||||
|  | ||||
| @ -184,7 +184,7 @@ | ||||
|       }); | ||||
|     }; | ||||
| 
 | ||||
|     Desi.fsapi = fsapi = {}; | ||||
|     Desi.fsapi = fsapi = Desi.fsapi || {}; | ||||
|     fsapi.getMeta = function (collections, opts) { | ||||
|       console.log('dm sub 0'); | ||||
|       opts = opts || {}; | ||||
|  | ||||
							
								
								
									
										74
									
								
								lib/node-adapters/fsapi-real.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								lib/node-adapters/fsapi-real.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,74 @@ | ||||
| 'use strict'; | ||||
| 
 | ||||
| var PromiseA = require('bluebird').Promise | ||||
|   , fs = PromiseA.promisifyAll(require('fs')) | ||||
|   ; | ||||
| 
 | ||||
| function create(Desi, options) { | ||||
|   var fsapi = Desi.fsapi | ||||
|     ; | ||||
| 
 | ||||
|   options.blogdir = options.working_path; | ||||
| 
 | ||||
|   fsapi.getMeta = function (dirnames, opts) { | ||||
|     opts = opts || {}; | ||||
| 
 | ||||
|     var extensions = '' | ||||
|       , dotfiles = '' | ||||
|       , contents = '' | ||||
|       , sha1sum = '' | ||||
|       ; | ||||
| 
 | ||||
|     if (Array.isArray(opts.extensions)) { | ||||
|       extensions = '&extensions=' + opts.extensions.join(','); // md,markdown,jade,htm,html
 | ||||
|     } | ||||
|     if (opts.dotfiles) { | ||||
|       dotfiles = '&dotfiles=true'; | ||||
|     } | ||||
|     if (opts.contents) { | ||||
|       contents = '&contents=true'; | ||||
|     } | ||||
|     if (false === opts.sha1sum) { | ||||
|       sha1sum = '&sha1sum=false'; | ||||
|     } | ||||
| 
 | ||||
|     return fsapi.walk.walkDirs(options.blogdir, dirnames, opts); | ||||
|   }; | ||||
| 
 | ||||
|   fsapi.getContents = function (filepaths) { | ||||
| 
 | ||||
|     return fsapi.getfs(options.blogdir, filepaths); | ||||
|   }; | ||||
| 
 | ||||
|   fsapi.getCache = function () { | ||||
|     return fs.readFileAsync(options.blogdir, '/cache.json').catch(function (/*e*/) { | ||||
|       return {}; | ||||
|     }).then(function (obj) { | ||||
|       return obj; | ||||
|     }); | ||||
|   }; | ||||
| 
 | ||||
|   fsapi.copy = function (files) { | ||||
|     // TODO size
 | ||||
|     return fsapi.copyfs(options.blogdir, files); | ||||
|   }; | ||||
| 
 | ||||
|   fsapi.putFiles = function (files) { | ||||
|     files.forEach(function (file) { | ||||
|       if (!file.contents || 'string' === typeof file.contents) { | ||||
|         return; | ||||
|       } | ||||
|       if (/\.json$/i.test(file.path)) { | ||||
|         file.contents = JSON.stringify(file.contents); | ||||
|       } | ||||
|       else if (/\.ya?ml$/i.test(file.path)) { | ||||
|         file.contents = exports.jsyaml.dump(file.contents);  | ||||
|       } | ||||
|     }); | ||||
| 
 | ||||
|     // TODO size
 | ||||
|     return fsapi.putfs(options.blogdir, files); | ||||
|   }; | ||||
| } | ||||
| 
 | ||||
| exports.create = create; | ||||
| @ -2,3 +2,4 @@ | ||||
| 
 | ||||
| exports.fsapi = require('./fsapi'); | ||||
| exports.sha1sum = require('./sha1sum').sha1sum; | ||||
| exports.realFsapi = require('./fsapi-real'); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user