當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript core.template函數代碼示例

本文整理匯總了TypeScript中@angular-devkit/core.template函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript template函數的具體用法?TypeScript template怎麽用?TypeScript template使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了template函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: return

  return (entry: FileEntry) => {
    const {path, content} = entry;
    if (isBinary(content)) {
      return entry;
    }

    return {
      path: path,
      content: Buffer.from(templateImpl(content.toString('utf-8'), {})(options)),
    };
  };
開發者ID:DevIntent,項目名稱:angular-cli,代碼行數:11,代碼來源:template.ts

示例2: templateCompiler

 files.forEach(fileName => {
   const p = path.relative(
     path.dirname(__dirname),
     path.join(pkg.root, path.relative(pkg.dist, fileName)),
   );
   const fn = templateCompiler(fs.readFileSync(fileName).toString(), {
     module: true,
     sourceURL: p,
     sourceMap: true,
     sourceRoot: path.join(__dirname, '..'),
     fileName: fileName.replace(/\.ejs$/, '.js'),
   });
   _rm(fileName);
   fs.writeFileSync(fileName.replace(/\.ejs$/, '.js'), fn.source);
 });
開發者ID:DevIntent,項目名稱:angular-cli,代碼行數:15,代碼來源:build.ts

示例3: return

  return (host: Tree, context: FileSystemSchematicContext) => {
    const workspace = getWorkspace(host);
    const project = getProjectFromWorkspace(workspace, options.project);
    const defaultComponentOptions = getDefaultComponentOptions(project);

    // TODO(devversion): Remove if we drop support for older CLI versions.
    // This handles an unreported breaking change from the @angular-devkit/schematics. Previously
    // the description path resolved to the factory file, but starting from 6.2.0, it resolves
    // to the factory directory.
    const schematicPath = statSync(context.schematic.description.path).isDirectory() ?
        context.schematic.description.path :
        dirname(context.schematic.description.path);

    const schematicFilesUrl = './files';
    const schematicFilesPath = resolve(schematicPath, schematicFilesUrl);

    // Add the default component option values to the options if an option is not explicitly
    // specified but a default component option is available.
    Object.keys(options)
      .filter(optionName => options[optionName] == null && defaultComponentOptions[optionName])
      .forEach(optionName => options[optionName] = defaultComponentOptions[optionName]);

    if (options.path === undefined) {
      // TODO(jelbourn): figure out if the need for this `as any` is a bug due to two different
      // incompatible `WorkspaceProject` classes in @angular-devkit
      options.path = buildDefaultPath(project as any);
    }

    options.module = findModuleFromOptions(host, options);

    const parsedPath = parseName(options.path!, options.name);

    options.name = parsedPath.name;
    options.path = parsedPath.path;
    options.selector = options.selector || buildSelector(options, project.prefix);

    validateName(options.name);
    validateHtmlSelector(options.selector!);

    // In case the specified style extension is not part of the supported CSS supersets,
    // we generate the stylesheets with the "css" extension. This ensures that we don't
    // accidentally generate invalid stylesheets (e.g. drag-drop-comp.styl) which will
    // break the Angular CLI project. See: https://github.com/angular/material2/issues/15164
    if (!supportedCssExtensions.includes(options.style!)) {
      // TODO: Cast is necessary as we can't use the Style enum which has been introduced
      // within CLI v7.3.0-rc.0. This would break the schematic for older CLI versions.
      options.style = 'css' as Style;
    }

    // Object that will be used as context for the EJS templates.
    const baseTemplateContext = {
      ...strings,
      'if-flat': (s: string) => options.flat ? '' : s,
      ...options,
    };

    // Key-value object that includes the specified additional files with their loaded content.
    // The resolved contents can be used inside EJS templates.
    const resolvedFiles = {};

    for (let key in additionalFiles) {
      if (additionalFiles[key]) {
        const fileContent = readFileSync(join(schematicFilesPath, additionalFiles[key]), 'utf-8');

        // Interpolate the additional files with the base EJS template context.
        resolvedFiles[key] = interpolateTemplate(fileContent)(baseTemplateContext);
      }
    }

    const templateSource = apply(url(schematicFilesUrl), [
      options.skipTests ? filter(path => !path.endsWith('.spec.ts')) : noop(),
      options.inlineStyle ? filter(path => !path.endsWith('.__style__')) : noop(),
      options.inlineTemplate ? filter(path => !path.endsWith('.html')) : noop(),
      // Treat the template options as any, because the type definition for the template options
      // is made unnecessarily explicit. Every type of object can be used in the EJS template.
      template({indentTextContent, resolvedFiles, ...baseTemplateContext} as any),
      // TODO(devversion): figure out why we cannot just remove the first parameter
      // See for example: angular-cli#schematics/angular/component/index.ts#L160
      move(null as any, parsedPath.path),
    ]);

    return chain([
      branchAndMerge(chain([
        addDeclarationToNgModule(options),
        mergeWith(templateSource),
      ])),
    ])(host, context);
  };
開發者ID:Nodarii,項目名稱:material2,代碼行數:88,代碼來源:build-component.ts


注:本文中的@angular-devkit/core.template函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。