当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript lodash.template类代码示例

本文整理汇总了TypeScript中lodash.template的典型用法代码示例。如果您正苦于以下问题:TypeScript template类的具体用法?TypeScript template怎么用?TypeScript template使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了template类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: minify

    return es.map(function(file: any, callback: (err: any, htmlMinifierfile: any) => void) {
        var template = '$templateCache.put("<%= url %>","<%= contents %>");';
        var url;

        file.path = path.normalize(file.path);

        if(typeof options.path === 'function') {
            url = path.join(options.path(file.path, file.base));
        } else {
            url = path.join(file.path);
            url = url.replace(file.base, '');
        };

        if (process.platform === 'win32') {
            url = url.replace(/\\/g, '/');
        }

        let contents = file.contents.toString();

        if(options.htmlMinifier) {
            contents = minify(contents, options.htmlMinifier);
        }

        contents = require('js-string-escape')(contents);

        file.contents = Buffer.from(lodashTemplate(template)({
            url: url,
            contents: contents,
            file: file
        }), 'utf8');

        callback(null, file);
    });
开发者ID:VictorQueiroz,项目名称:gulp-ng-templates,代码行数:33,代码来源:index.ts

示例2: create

	private async create(url: string, size: string, options: Options): Promise<Screenshot> {
		const basename = path.isAbsolute(url) ? path.basename(url) : url;

		let hash = parseUrl(url).hash || '';
		// Strip empty hash fragments: `#` `#/` `#!/`
		if (/^#!?\/?$/.test(hash)) {
			hash = '';
		}

		const [width, height] = size.split('x');

		const filenameTemplate = template(`${options.filename}.${options.format}`);

		const now = Date.now();
		let filename = filenameTemplate({
			crop: options.crop ? '-cropped' : '',
			date: dateFns.format(now, 'YYYY-MM-DD'),
			time: dateFns.format(now, 'HH-mm-ss'),
			size,
			width,
			height,
			url: `${filenamifyUrl(basename)}${filenamify(hash)}`
		});

		if (options.incrementalName) {
			filename = unusedFilename.sync(filename);
		}

		// TODO: Type this using the `capture-website` types
		const finalOptions: any = {
			width: Number(width),
			height: Number(height),
			delay: options.delay,
			timeout: options.timeout,
			fullPage: !options.crop,
			styles: options.css && [options.css],
			scripts: options.script && [options.script],
			cookies: options.cookies, // TODO: Support string cookies in capture-website
			element: options.selector,
			hideElements: options.hide,
			scaleFactor: options.scale === undefined ? 1 : options.scale,
			type: options.format === 'jpg' ? 'jpeg' : 'png',
			userAgent: options.userAgent,
			headers: options.headers
		};

		if (options.username && options.password) {
			finalOptions.authentication = {
				username: options.username,
				password: options.password
			};
		}

		const screenshot = await captureWebsite.buffer(url, finalOptions) as any;
		screenshot.filename = filename;
		return screenshot;
	}
开发者ID:sindresorhus,项目名称:pageres,代码行数:57,代码来源:index.ts

示例3: template

 Object.keys(obj).forEach((objKey) => {
   if (typeof obj[objKey] === 'object' && obj !== null) {
     template(obj[objKey]);
   } else if (typeof obj[objKey] === 'string') {
     obj[objKey] = _template(obj[objKey])(templateObj); // eslint-disable-line
     if (obj[objKey].startsWith('require:')) {
       obj[objKey] = require(path.resolve(dir, obj[objKey].substr(8))); // eslint-disable-line
     }
   }
 });
开发者ID:balloonzzq,项目名称:electron-forge,代码行数:10,代码来源:forge-config.ts

示例4: createDocumentFootnotes

export function createDocumentFootnotes(settings: Settings): RawFootnote[] {
  const { anchorParentSelector, buttonTemplate, numberResetSelector } = settings
  const offset = parseInt(getLastFootnoteId(), 10) + 1

  return findFootnoteLinks(settings)
    .map(findFootnoteBody(settings))
    .filter(isDefined)
    .map(hideOriginalFootnote)
    .map(templateData(anchorParentSelector, offset))
    .map(numberResetSelector ? resetNumbers(numberResetSelector) : i => i)
    .map(addButton(template(buttonTemplate)))
}
开发者ID:goblindegook,项目名称:littlefoot,代码行数:12,代码来源:setup.ts

示例5: template

const runCommand = (
  command: string,
  options: Required<Options>,
  file: Vinyl | null
): Promise<void> => {
  const context = { file, ...options.templateData }
  command = template(command)(context)

  if (options.verbose) {
    fancyLog(`${PLUGIN_NAME}:`, chalk.cyan(command))
  }

  const child = spawn(command, {
    env: options.env,
    cwd: template(options.cwd)(context),
    shell: options.shell,
    stdio: options.quiet ? 'ignore' : 'inherit'
  })

  return new Promise((resolve, reject) => {
    child.on('exit', code => {
      if (code === 0 || options.ignoreErrors) {
        return resolve()
      }

      const context = {
        command,
        file,
        error: { code },
        ...options.templateData
      }

      const message = template(options.errorMessage)(context)

      reject(new PluginError(PLUGIN_NAME, message))
    })
  })
}
开发者ID:sun-zheng-an,项目名称:gulp-shell,代码行数:38,代码来源:index.ts

示例6: insertPopover

function insertPopover(
  button: HTMLElement,
  contentTemplate: string,
  data: TemplateData
) {
  const render = template(contentTemplate)
  button.insertAdjacentHTML('afterend', render(data))
  const popover = button.nextElementSibling as HTMLElement
  const content = findPopoverContent(popover)
  popover.setAttribute(FOOTNOTE_MAX_HEIGHT, `${getMaxHeight(content)}`)
  popover.style.maxWidth = `${document.body.clientWidth}px`
  bindContentScrollHandler(content)
  return popover
}
开发者ID:goblindegook,项目名称:littlefoot,代码行数:14,代码来源:footnote.ts

示例7: resolve

    child.on('exit', code => {
      if (code === 0 || options.ignoreErrors) {
        return resolve()
      }

      const context = {
        command,
        file,
        error: { code },
        ...options.templateData
      }

      const message = template(options.errorMessage)(context)

      reject(new PluginError(PLUGIN_NAME, message))
    })
开发者ID:sun-zheng-an,项目名称:gulp-shell,代码行数:16,代码来源:index.ts

示例8: require

        result += placeholders[i]
            .replace(/&/g, '&amp;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;');
    }

    // add the last literal
    result += literals[literals.length - 1];
    return result;
}

var lotmpl = require( 'lodash.template' );

var emailTmp = lotmpl( fs.readFileSync( "book-sample-request.pt.html", "utf8" ) );

function escapeFormField( field: string ): string {
  return field
      .replace(/&/g, '&amp;')
      .replace(/"/g, '&quot;')
      .replace(/'/g, '&#39;')
      .replace(/</g, '&lt;')
      .replace(/>/g, '&gt;');
}

function sendMail( template, info, cb ) {
  var auth = config.subscribe.auth;

  // setup e-mail data with unicode symbols
  var mailOptions = {
开发者ID:essential-cryptography,项目名称:essentialcryptography.com,代码行数:31,代码来源:server.ts


注:本文中的lodash.template类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。