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


TypeScript TemplateFunction.default方法代码示例

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


在下文中一共展示了TemplateFunction.default方法的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: ejsFunction

ejsFunction = ejs.compile(template, { context: { foo: 'FOO' } });
ejsFunction = ejs.compile(template, { compileDebug: false });
ejsFunction = ejs.compile(template, { client: true });
ejsFunction = ejs.compile('<$= people.join(", "); $>', { delimiter: '$' });
ejsFunction = ejs.compile('<%= locals.people.join(", "); %>', { _with: false });
ejsFunction = ejs.compile('<%= locals.people.join(", "); %>', { strict: true });
ejsFunction = ejs.compile('<%= it.people.join(", "); %>', { _with: false, localsName: "it" });
ejsFunction = ejs.compile(template, { rmWhitespace: true });
const customEscape = (str: string) => !str ? '' : str.toUpperCase();
ejsFunction = ejs.compile(template, { escape: customEscape });
ejsFunction = ejs.compile(template, { async: false });

ejsAsyncFunction = ejs.compile(template, { async: true });
ejsAsyncFunction = ejs.compile(template, { client: true, async: true });

result = ejsFunction();
result = ejsFunction({});
result = ejsFunction(data);

asyncResult = ejsAsyncFunction();
asyncResult = ejsAsyncFunction({});
asyncResult = ejsAsyncFunction(data);

/** @see https://github.com/mde/ejs/tree/v2.5.7#custom-fileloader */
ejs.fileLoader = (path: string) => "";

/** @see https://github.com/mde/ejs/tree/v2.5.7#caching */
ejs.clearCache();
ejs.cache = LRU(100);

/** @see https://github.com/mde/ejs/tree/v2.5.7#custom-delimiters */
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:31,代码来源:ejs-tests.ts


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