How to use the pug.compileClientWithDependenciesTracked function in pug

To help you get started, we’ve selected a few pug 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 DefinitelyTyped / DefinitelyTyped / pug / pug-tests.ts View on Github external
{
        /// pug.compileFile(path, ?options) https://pugjs.org/api/reference.html#pugcompilefilepath-options
        compileTemplate = pug.compileFile(path);
        template = compileTemplate();
    }

    {
        /// pug.compileClient(source, ?options) https://pugjs.org/api/reference.html#pugcompileclientsource-options
        clientFunctionString = pug.compileClient(path);
        str = pug.compileClient(path);
    }

    {
        /// pug.compileClientWithDependenciesTracked(source, ?options) https://pugjs.org/api/reference.html#pugcompileclientwithdependenciestrackedsource-options
        let obj = pug.compileClientWithDependenciesTracked(source);
        clientFunctionString = obj.body;
        str = obj.body;
        let strArray: string[] = obj.dependencies;
    }

    {
        /// pug.compileFileClient(path, ?options) https://pugjs.org/api/reference.html#pugcompilefileclientpath-options
        clientFunctionString = pug.compileFileClient(path);
        str = pug.compileFileClient(path);
    }

    {
        /// pug.render(source, ?options, ?callback) https://pugjs.org/api/reference.html#pugrendersource-options-callback
        str = pug.render(source);

        // test type for callback paraments
github aMarCruz / rollup-plugin-pug / dist / rollup-plugin-pug.js View on Github external
}
            else {
                /*
                  This template will generate a module with a function to be executed at
                  runtime. It will be user responsibility to pass the correct parameters
                  to the function, here we only take care of the `imports`, incluiding the
                  pug runtime.
                */
                const imports = [];
                if (config.sourceMap) {
                    pugOpts.compileDebug = map = true;
                }
                // move the imports from the template to the top of the output queue
                code = moveImports(code, imports);
                // get function body and dependencies
                fn = pug.compileClientWithDependenciesTracked(code, pugOpts);
                body = fn.body.replace('function template(', '\nexport default function(');
                // put the pung-runtime import as the first of the queue, if neccesary
                if (config._runtimeImport && /\bpug\./.test(body)) {
                    imports.unshift(`import pug from '${config._runtimeImport}';`);
                }
                // convert imports into string and add the template function
                body = imports.join('\n') + `${body};\n`;
            }
            const dependencies = arrIfDeps(fn.dependencies);
            if (map) {
                const bundle = genPugSourceMap(id, body, {
                    basedir: config.basedir,
                    keepDebugLines: config.compileDebug,
                });
                // HACK: 'as any' to avoid conflict with wrong rollup 6.6 typings
                return { code: bundle.data, map: bundle.map, dependencies };
github aMarCruz / rollup-plugin-pug / src / index.ts View on Github external
This template will generate a module with a function to be executed at
          runtime. It will be user responsibility to pass the correct parameters
          to the function, here we only take care of the `imports`, incluiding the
          pug runtime.
        */
        const imports = [] as string[]

        if (config.sourceMap) {
          pugOpts.compileDebug = map = true
        }

        // move the imports from the template to the top of the output queue
        code = moveImports(code, imports)

        // get function body and dependencies
        fn = compileClientWithDependenciesTracked(code, pugOpts) as pugFnOrStr
        body = fn.body.replace('function template(', '\nexport default function(')

        // put the pung-runtime import as the first of the queue, if neccesary
        if (config._runtimeImport && /\bpug\./.test(body)) {
          imports.unshift(`import pug from '${config._runtimeImport}';`)
        }

        // convert imports into string and add the template function
        body = imports.join('\n') + `${body};\n`
      }

      const dependencies = arrIfDeps(fn.dependencies)

      if (map) {
        const bundle = genPugSourceMap(id, body, {
          basedir: config.basedir,
github aMarCruz / rollup-plugin-pug / dist / rollup-plugin-pug.es.js View on Github external
const output = [];
            let body;
            let map;
            let fn;
            if (isStatic) {
                const staticOpts = assign(null, config.locals, clone(config));
                staticOpts.filename = id;
                fn = compile(code, pugOpts);
                body = `export default ${JSON.stringify(fn(staticOpts))}`;
            }
            else {
                if (config.sourceMap) {
                    pugOpts.compileDebug = map = true;
                }
                code = moveImports(code, output);
                fn = compileClientWithDependenciesTracked(code, pugOpts);
                body = fn.body.replace('function template(', '\nexport default function(');
                if (config.runtimeImport && /\bpug\./.test(body)) {
                    output.unshift(`import pug from '${config.runtimeImport}';`);
                }
            }
            const dependencies = arrIfDeps(fn.dependencies);
            output.push(body);
            body = output.join('\n') + ';\n';
            if (map) {
                const bundle = genPugSourceMap(id, body, {
                    basedir: config.basedir,
                    keepDebugLines: config.compileDebug,
                });
                return { code: bundle.data, map: bundle.map, dependencies };
            }
            return { code: body, map: null, dependencies };
github aMarCruz / rollup-plugin-pug / src / index.js View on Github external
opts.filename = id

      if (is_static) {
        const static_opts = assign(null, config.locals, opts)

        body = `export default ${JSON.stringify(render(code, static_opts))};`

      } else {
        keepDbg = opts.compileDebug
        if (config.sourceMap) {
          opts.compileDebug = map = true
        }
        code = moveImports(code, output)

        fn = compileClientWithDependenciesTracked(code, opts)
        body = fn.body.replace('function template(', '\nexport default function(')

        if (config.runtimeImport && /\bpug\./.test(body)) {
          output.unshift(`import pug from '${config.runtimeImport}';`)
        }

        const deps = fn.dependencies
        if (deps.length) {
          const ins = {}

          deps.forEach((dep) => {
            if (dep in ins) return
            ins[dep] = output.push(`import '${dep}';`)
          })
        }
      }
github sidorares / pugify / index.js View on Github external
function compile(file, template, options) {
    options.filename = file;
    options.name = "template";
    var result;
    result = pug.compileClientWithDependenciesTracked(template, options);
    if (options.compileDebug)
        result.body = withSourceMap(template, result.body, file);

    var PREFIX = "var pug = require('"+(options.runtimePath === undefined ? "pug-runtime" : options.runtimePath)+"');\nmodule.exports=template;";

    result.body = PREFIX + result.body;
    return result;
}