
// use strict
'use strict';

// require dependencies
var riot = require ('riot');
var glob = require ('glob');

/**
 * create engine class
 */
class engine {
    constructor () {
        // require all tags
        var tagFiles = glob.sync (global.appRoot + '/cache/view/**/*.tag');

        // loop tag files
        for (var i = 0; i < tagFiles.length; i++) {
            // require tag file
            require (tagFiles[i]);
        }
    }

    /**
     * render riot tag locally
     *
     * @param  {String}   filePath
     * @param  {*}        options
     * @param  {Function} callback
     *
     * @return {*}
     */
    render (filePath, options, callback) {
        // require riot tag
        options.mountPage = filePath.split ('/')[filePath.split ('/').length - 1].trim ().replace ('.tag', '') + '-page';

        // delete frontend options
        delete options.cache;
        delete options._locals;
        delete options.settings;

        // check if should json
        if (options.isJSON) {
            // delete isJSON
            delete options.isJSON;

            // return callback
            return callback (null, JSON.stringify ({
                'opts' : options
            }));
        }

        // render page
        var page  = '<!DOCTYPE html>';
            page += '<html>';
            page += '<head>';
            page += '<meta charset="utf-8">';
            page += '<title>' + options.title + '</title>';
            page += '<link rel="stylesheet" href="/assets/css/app.min.css">';
            page += '</head>';
            page += '<body>';
            page += riot.render ((options.layout ? options.layout : 'main') + '-layout', options);
            page += '<script>var eden = ' + JSON.stringify (options.eden) + ';</script>';
            page += '<script>var opts = ' + JSON.stringify (options) + ';</script>';
            page += '<script type="text/javascript" src="/assets/js/app.min.js"></script>';
            page += '</body>';
            page += '</html>';

        // return render callback
        return callback (null, page);
    }
}

/**
 * export engine class
 * @type {engine}
 */
module.exports = engine;

@@ -696,24 +696,58 @@
 allback) %7B%0D%0A
+        console.log ('working');%0D%0A
         // r
@@ -763,16 +763,16 @@
 ot tag%0D%0A
-
         
@@ -1303,24 +1303,88 @@
        %7D%0D%0A%0D%0A
+        // set server option%0D%0A        options.server = true;%0D%0A%0D%0A
         // r
@@ -1930,32 +1930,102 @@
  ';%3C/script%3E';%0D%0A
+%0D%0A            // delete server%0D%0A            delete options.server;%0D%0A%0D%0A
             page
@@ -2211,32 +2211,32 @@
  += '%3C/body%3E';%0D%0A
-
             page
@@ -2249,24 +2249,59 @@
 /html%3E';%0D%0A%0D%0A
+            console.log (page);%0D%0A%0D%0A
         // r

complete engine debug for isomorphic