lazy-docs
functional documents for node.
functional documents (a function that returns a document) combines watching changes, document parsing and proxy.
documents only reload if changed and when requested, external changes only flag the file to refresh at next request.
var myfile="test/resources/test.txt";console;//sync mode;//assync mode
usage
this module only exports a setup function, on setup a file creator function is returned. The file creator function should be used to create functional files
require("lazy-docs")([loader function]);
where
loader function is optional (default to text load) and should be a function to parse the document from a string/buffer.
This will return a document loader function that expects a filename.
require("lazy-docs")(parser)(filename)
where
filename is a file name string
The loader function will return a functional document. You can associate it with a variable or call it directly
//default parservar myfile=/*use default parser*/"test/resources/test.txt";
then the file can be recalled and will update himself in case of external change
console;//sync mode;//assync mode
examples
text documents loader
var txtDoc=;//setup for text formatvar txt=;//functional fileconsole;//sync file content with cache and watcher;//assync file content with cache and watcher
libxmljs documents loader
var libxml=;var xmlDoc=libxmlparseXml;//setup for libxml documentsvar xml=;console;
closing a document stops watching the file, if you recall the document it will load and watch again
var file="myfile.txt";console;//print updated text file contentfileproxy;//stop watching the file
TODO LIST:
this module defaults to local sync/assync file system, see fProxy for more flexibility