Package couchdbkit :: Module macros
[hide private]
[frames] | no frames]

Module macros

source code


Macros used by loaders. compatible with couchapp. It allow you to include code,
design docs members inside your views, shows and lists.

for example to include a code, add just after first function the line :
    
    // !code relativepath/to/some/code.js
    
To include a member of design doc and use it as a simple javascript object :

    // !json some.member.i.want.to.include
    
All in one, example of a view :

    function(doc) {
        !code _attachments/js/md5.js
        
        if (doc.type == "user") {
            doc.gravatar = hex_md5(user.email);
            emit(doc.username, doc)
        }
    }

This example includes md5.js code and uses md5 function to create gravatar hash
in your views.  So you could just store raw data in your docs and calculate
hash when views are updated.

Functions [hide private]
 
package_shows(doc, funcs, app_dir, objs, verbose=False)
take a list of funcs un return them processed
source code
 
package_views(doc, views, app_dir, objs, verbose=False)
take a dict of funcs and return them processed
source code
 
apply_lib(doc, funcs, app_dir, objs, verbose=False)
run code macros and json macros on a list of funcs.
source code
 
run_code_macros(f_string, app_dir, verbose=False)
apply code macros
source code
 
run_json_macros(doc, f_string, app_dir, verbose=False)
apply json macros
source code
Function Details [hide private]

apply_lib(doc, funcs, app_dir, objs, verbose=False)

source code 

run code macros and json macros on a list of funcs. It also maintain a list of processed code to be sure to not processing twice