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


TypeScript ejs.TemplateFunction类代码示例

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


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

示例1: generate

  public generate(
    nschema: NSchemaInterface,
    nsconfig: NineSchemaConfig,
    template: TemplateFunction,
    target: Target
  ) {
    const config: FSharpConfig = nsconfig as FSharpConfig;
    config.$nschema = nschema;
    config.$fsharp = this;
    config.$target = target;
    const result = template(config);
    const location = target.location;
    const filepath =
      location.indexOf(".") === 0
        ? path.resolve(
            process.cwd(),
            location,
            config.namespace || "",
            target.$fileName || `${config.name}.fs`
          )
        : path.resolve(
            location,
            config.namespace || "",
            config.$fileName || `${config.name}.fs`
          );

    console.log(`fsharp: writing to file: ${filepath}`);
    return nschema.writeFile(filepath, result).then(null, err => {
      console.log("error: ");
      console.log(err);
    });
  }
开发者ID:eburgos,项目名称:nschema,代码行数:32,代码来源:fsharp.ts

示例2: generate

  public generate(
    nschema: NSchemaInterface,
    $nsconfig: NineSchemaConfig,
    template: TemplateFunction,
    target: Target
  ) {
    const nsconfig: any = $nsconfig.$u.clone($nsconfig);
    const config: TypeScriptConfig = nsconfig as TypeScriptConfig;
    config.$nschema = nschema;
    config.$typescript = this;
    config.$target = target;
    if (typeof config.$skipWrite === "undefined") {
      config.$skipWrite = false;
    }
    if (config.$context) {
      throw new Error("must not have a $context variable");
    }
    config.$context = {
      imports: {}
    };
    const result = template(config);

    if (config.$skipWrite) {
      return Promise.resolve({
        config,
        generated: result
      });
    } else {
      const location = target.location;
      const filepath =
        location.indexOf(".") === 0
          ? path.resolve(
              process.cwd(),
              location,
              config.namespace || "",
              target.$fileName || `${config.name}.ts`
            )
          : path.resolve(
              location,
              config.namespace || "",
              config.$fileName || `${config.name}.ts`
            );

      console.log(`typescript: writing to file: ${filepath}`);
      return nschema.writeFile(filepath, result).then(
        _ => {
          return {
            config,
            generated: result
          };
        },
        err => {
          console.log("error: ");
          console.log(err);
        }
      );
    }
  }
开发者ID:eburgos,项目名称:nschema,代码行数:58,代码来源:typescript.ts

示例3: require

/// <reference types="node" />

import ejs = require("ejs");
import { readFileSync as read } from 'fs';
import LRU = require("lru-cache");
import { TemplateFunction, AsyncTemplateFunction, Options } from "ejs";

const fileName = 'test.ejs';
const people = ['geddy', 'neil', 'alex'];
const data = { people };
const template = '<%= people.join(", "); %>';
const options = { filename: fileName };
let result: string;
let ejsFunction: TemplateFunction;
let asyncResult: Promise<string>;
let ejsAsyncFunction: AsyncTemplateFunction;

const SimpleCallback = (err: any, html?: string) => {
    if (err) {
        return null;
    }
    return html;
};

result = ejs.render(template);
result = ejs.render(template, data);
result = ejs.render(template, data, options);

result = ejs.renderFile(fileName, SimpleCallback);
result = ejs.renderFile(fileName, data, SimpleCallback);
result = ejs.renderFile(fileName, data, options, SimpleCallback);
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:31,代码来源:ejs-tests.ts


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