lib/card.js
function generateCardDocument(options, callback) {
  var DB = require('../index').db,
    elementId = Cuid();

  // defaults
  options = _.defaultsDeep(options, {
    directory: '.',
    css: true,
    js: false,
    clientStateSupport: false,
    clientProxySupport: false,
    clientAnalyticsSupport: false,
    viewModel: {
      link: options.link,
      card: {
        id: elementId,
        name: options.cardName,
        pack: options.packName
      }
    },
    clientLocals: {
      title: options.title,
      card: {
        id: elementId,
        key: options.key,
        name: options.cardName,
        pack: options.packName,
        url: options.url
      }
    }
  });
    
  Async.waterfall([
      function (cb) {
        stylesToString(options, function (css) {
          cb(null, css);
        });
      },

      function (css, cb) {
        if (options.clientStateSupport || options.clientAnalyticsSupport || options.clientProxySupport) {
          // generate a one-time #Do API key.
          DB.issueAPIKey(options.key, function (err, apiKey) {
            if (apiKey) {
              options.clientLocals.card.apiKey = apiKey;
            }

            cb(null, css);
          });
        }
        else {
          cb(null, css);
        }
      },

      function (css, cb) {
        jsToString(options, function (js) {
          cb(null, css, js);
        });
      },

      function (css, js, cb) {
        viewToString(css, js, options, function (html) {
          cb(null, html || '');
        });
      }
    ],

    // done
    function (err, html) {
      callback && callback(Minify(html, {
        collapseWhitespace: true,
        removeComments: true,
        removeCommentsFromCDATA: true,
        removeAttributeQuotes: true,
        removeRedundantAttributes: true,
        removeEmptyAttributes: true,
        minifyJS: process.env.NODE_ENV === 'production',
        minifyCSS: process.env.NODE_ENV === 'production'
      }));
    }
  );
}
function generateCardDocument(options, callback) {
  var DB = require('../index').db,
    elementId = Cuid();

  // defaults
  options = _.defaultsDeep(options, {
    directory: '.',
    css: true,
    js: false,
    clientStateSupport: false,
    clientProxySupport: false,
    clientAnalyticsSupport: false,
    viewModel: {
      link: options.link,
      card: {
        id: elementId,
        name: options.cardName,
        pack: options.packName
      }
    },
    clientLocals: {
      title: options.title,
      card: {
        id: elementId,
        key: options.key,
        name: options.cardName,
        pack: options.packName,
        url: options.url
      }
    }
  });
    
  Async.waterfall([
      function (cb) {
        stylesToString(options, function (css) {
          cb(null, css);
        });
      },

      function (css, cb) {
        if (options.clientStateSupport || options.clientAnalyticsSupport || options.clientProxySupport) {
          // generate a one-time #Do API key.
          DB.issueAPIKey(options.key, function (err, apiKey) {
            if (apiKey) {
              options.clientLocals.card.apiKey = apiKey;
            }

            cb(null, css);
          });
        }
        else {
          cb(null, css);
        }
      },

      function (css, cb) {
        jsToString(options, function (js) {
          cb(null, css, js);
        });
      },

      function (css, js, cb) {
        viewToString(css, js, options, function (html) {
          cb(null, html || '');
        });
      }
    ],

    // done
    function (err, html) {
      callback && callback(Minify(html, {
        collapseWhitespace: true,
        removeComments: true,
        removeCommentsFromCDATA: true,
        removeAttributeQuotes: true,
        removeRedundantAttributes: true,
        removeEmptyAttributes: true,
        minifyJS: process.env.NODE_ENV === 'production',
        minifyCSS: process.env.NODE_ENV === 'production'
      }));
    }
  );
}
function generateCardDocument ( options , callback ) { var DB = require ( '../index' ) . db , elementId = Cuid ( ) ; // defaults options = _ . defaultsDeep ( options , { directory : '.' , css : true , js : false , clientStateSupport : false , clientProxySupport : false , clientAnalyticsSupport : false , viewModel : { link : options . link , card : { id : elementId , name : options . cardName , pack : options . packName } } , clientLocals : { title : options . title , card : { id : elementId , key : options . key , name : options . cardName , pack : options . packName , url : options . url } } } ) ; Async . waterfall ( [ function ( cb ) { stylesToString ( options , function ( css ) { cb ( null , css ) ; } ) ; } , function ( css , cb ) { if ( options . clientStateSupport || options . clientAnalyticsSupport || options . clientProxySupport ) { // generate a one-time #Do API key. DB . issueAPIKey ( options . key , function ( err , apiKey ) { if ( apiKey ) { options . clientLocals . card . apiKey = apiKey ; } cb ( null , css ) ; } ) ; } else { cb ( null , css ) ; } } , function ( css , cb ) { jsToString ( options , function ( js ) { cb ( null , css , js ) ; } ) ; } , function ( css , js , cb ) { viewToString ( css , js , options , function ( html ) { cb ( null , html || '' ) ; } ) ; } ] , // done function ( err , html ) { callback && callback ( Minify ( html , { collapseWhitespace : true , removeComments : true , removeCommentsFromCDATA : true , removeAttributeQuotes : true , removeRedundantAttributes : true , removeEmptyAttributes : true , minifyJS : process . env . NODE_ENV === 'production' , minifyCSS : process . env . NODE_ENV === 'production' } ) ) ; } ) ; }
Generate the full HTML document to render a card.
The document will be optimized in a production environment.

@method generateCardDocument
@async
@param {Object}   options     Rendering options object.

directory: The directory where the pack and card can be found.
packName: The pack name.
cardName: The card name.
url: the card url.
title: The card's title.
key: The card's unique key which is based on URL.
link: The card's external link.
css: Boolean to determine whether the card CSS will be included.
js: Boolean to determine whether the card JavaScript will be included.
clientStateSupport: Boolean to determine whether client state code needs to be included.
clientProxySupport: Boolean to determin whether client proxy code needs to be included.
clientAnalyticsSupport: Boolean to determine whether client analytics support JavaScript needs to be included.
viewModel: JSON view data object used to render server-side template.
clientLocals: JSON object with any local values that need to be accessible in client JavaScript.

@param {Function} [callback]  Optional callback function to retrieve the fully rendered card.
Generate the full HTML document to render a card . The document will be optimized in a production environment .