How to use the marko.load function in marko

To help you get started, we’ve selected a few marko examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lasso-js / lasso / src / LassoPageResult.js View on Github external
_getSlotTemplate: function(slotName) {
        var template = this._htmlTemplatesBySlot[slotName];
        if (!template) {
            var templateSrc = this._htmlBySlot[slotName];
            if (!templateSrc) {
                return null;
            }

            // In order to compile the HTML for the slot into a Marko template, we need to provide a faux
            // template path. The path doesn't really matter unless the compiled template needs to import
            // external tags or templates.
            var templatePath = nodePath.resolve(__dirname, '..', generateTempFilename(slotName));
            template = marko.load(templatePath, templateSrc, { preserveWhitespace: true, writeToDisk: false });
            // Cache the loaded template:
            this._htmlTemplatesBySlot[slotName] = template;

            // The Marko template compiled to JS and required. Let's delete it out of the require cache
            // to avoid a memory leak
            delete require.cache[templatePath + '.js'];
        }

        return template;
    },
github marko-js / marko / test / mocha-phantomjs / run.js View on Github external
function run() {
    console.log('Preparing client-side tests...');

    running = true;
    fileModified = false;

    var pageTemplate = require('marko').load(require.resolve('../fixtures/pages/server-init/template.marko'));
    var pageLayoutTemplate = require('marko').load(require.resolve('./page-layout.marko'));
    var pageHtmlFile = path.join(outputDir, 'test-page.html');

    var out = fs.createWriteStream(pageHtmlFile, 'utf8');

    console.log('Rendering HTML page...');
    pageTemplate.render({
            layout: pageLayoutTemplate
        }, out)
        .on('finish', function() {
            console.log('Running client tests using mocha-phantomjs...');
            spawn(
                'npm',
                ['run', 'mocha-phantomjs-run', '--loglevel=silent'],
                {
                    cwd: rootDir,
github marko-js / marko / test / autotests / components-browser-deprecated / widget-renderer-and-template / index.js View on Github external
var template = require('marko').load(require.resolve('./template.marko'));

module.exports = require('marko/legacy-components').defineComponent({
    createOut: template.createOut,

    renderer: function(input, out) {
        template.render({
                name: input.name
            },
            out);
    },

    setName: function(name) {
        this.getEl('name').innerHTML = name;
    }
});
github marko-js / marko-widgets / test / autotests-browser / widget-multiple-binds-in-template / renderer.js View on Github external
var template = require('marko').load(require.resolve('./template.marko'));

exports.render = function(input, out) {
    var viewModel = {

    };
    template.render(viewModel, out);
};
github marko-js / marko / test / deprecated-components-browser / fixtures / widget-multiple-binds-in-template.skip / renderer.js View on Github external
var template = require('marko').load(require.resolve('./template.marko'));

exports.render = function (input, out) {
    var viewModel = {};
    template.render(viewModel, out);
};
github marko-js / marko / test / autotests / components-browser-deprecated / widget-legacy-render-same-id / renderer.js View on Github external
var template = require('marko').load(require.resolve('./template.marko'));

exports.render = function render(input, out) {
    template.render({
            label: input.label
        },
        out);
};
github marko-js / marko / test / autotests / widgets-pages-deprecated / widget-fixed-id / components / app-hello / renderer.js View on Github external
var template = require('marko').load(require.resolve('./template.marko'));

module.exports = function(input, out) {
    var className = input['class'] || 'app-hello';

    template.render(
        {
            name: input.name,
            className: className,
            widgetConfig: {
                name: input.name
            }
        },
        out);

};
github charlieduong94 / mocha-puppeteer / src / Server.js View on Github external
const http = require('http')
const EventEmitter = require('events')

const express = require('express')
const bodyParser = require('body-parser')

const marko = require('marko')
const markoExpress = require('marko/express')
const TestPage = marko.load(require('./pages/test-page'))

const { Server: WebSocketServer } = require('ws')

class Server extends EventEmitter {
  constructor ({ outputDir, pageLasso, dependencies, testPage }) {
    super()

    const app = this._app = express()
    app.use(bodyParser.json({ limit: '100mb' }))
    app.use(markoExpress())

    testPage = (testPage && marko.load(testPage)) || TestPage

    app.get('/', (req, res) => {
      this.emit('start')
github marko-js-samples / ui-components-playground-lasso-express / src / components / app-overlay / renderer.js View on Github external
var template = require('marko').load(require.resolve('./template.marko'));

module.exports = function(input, out) {
    var width = input.width || 800;

    template.render({
        width: width,
        invokeBody: input.invokeBody
    }, out);
};
github raxjs / server-side-rendering-comparison / controllers / marko.js View on Github external
const pageTemplatePath = require.resolve('../views/page.marko');
const pageTemplate = require('marko').load(pageTemplatePath, { writeToDisk:false });

module.exports = {

    home: function* () {

        const app = require('../assets/build/server.marko.bundle');
        const pageConfig = {
            listData: require('../mock/list'),
            bannerData: require('../mock/banner')
        };

        this.body = pageTemplate.renderToString({ pageConfig, app, globalData: JSON.stringify(pageConfig) });
    }

}