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


TypeScript url_resolver.UrlResolver类代码示例

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


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

示例1: describe

 describe('UrlResolver', () => {
   var resolver = new UrlResolver();
   it('should add a relative path to the base url', () => {
     expect(resolver.resolve('http://www.foo.com', 'bar')).toEqual('http://www.foo.com/bar');
     expect(resolver.resolve('http://www.foo.com/', 'bar')).toEqual('http://www.foo.com/bar');
     expect(resolver.resolve('http://www.foo.com', './bar')).toEqual('http://www.foo.com/bar');
     expect(resolver.resolve('http://www.foo.com/', './bar')).toEqual('http://www.foo.com/bar');
   });
   it('should replace the base path', () => {
     expect(resolver.resolve('http://www.foo.com/baz', 'bar')).toEqual('http://www.foo.com/bar');
     expect(resolver.resolve('http://www.foo.com/baz', './bar')).toEqual('http://www.foo.com/bar');
   });
   it('should append to the base path', () => {
     expect(resolver.resolve('http://www.foo.com/baz/', 'bar')).toEqual('http://www.foo.com/baz/bar');
     expect(resolver.resolve('http://www.foo.com/baz/', './bar')).toEqual('http://www.foo.com/baz/bar');
   });
   it('should support ".." in the path', () => {
     expect(resolver.resolve('http://www.foo.com/baz/', '../bar')).toEqual('http://www.foo.com/bar');
     expect(resolver.resolve('http://www.foo.com/1/2/3/', '../../bar')).toEqual('http://www.foo.com/1/bar');
     expect(resolver.resolve('http://www.foo.com/1/2/3/', '../biz/bar')).toEqual('http://www.foo.com/1/2/biz/bar');
     expect(resolver.resolve('http://www.foo.com/1/2/baz', '../../bar')).toEqual('http://www.foo.com/bar');
   });
   it('should ignore the base path when the url has a scheme', () => {
     expect(resolver.resolve('http://www.foo.com', 'http://www.bar.com')).toEqual('http://www.bar.com');
   });
   it('should throw when the url start with "/"', () => {
     expect(() => {
       resolver.resolve('http://www.foo.com/1/2', '/test');
     }).toThrowError();
   });
 });
开发者ID:gdi2290,项目名称:sample-Angular2,代码行数:31,代码来源:url_resolver_spec.ts

示例2: it

 it('should support absolute urls', () => {
   expect(resolver.resolve('http://www.foo.com', '/bar')).toEqual('http://www.foo.com/bar');
   expect(resolver.resolve('http://www.foo.com/', '/bar')).toEqual('http://www.foo.com/bar');
   expect(resolver.resolve('http://www.foo.com/baz', '/bar'))
       .toEqual('http://www.foo.com/bar');
   expect(resolver.resolve('http://www.foo.com/baz/', '/bar'))
       .toEqual('http://www.foo.com/bar');
 });
开发者ID:goderbauer,项目名称:angular,代码行数:8,代码来源:url_resolver_spec.ts

示例3: it

 it('should support ".." in the path', () => {
   expect(resolver.resolve('http://www.foo.com/baz/', '../bar'))
       .toEqual('http://www.foo.com/bar');
   expect(resolver.resolve('http://www.foo.com/1/2/3/', '../../bar'))
       .toEqual('http://www.foo.com/1/bar');
   expect(resolver.resolve('http://www.foo.com/1/2/3/', '../biz/bar'))
       .toEqual('http://www.foo.com/1/2/biz/bar');
   expect(resolver.resolve('http://www.foo.com/1/2/baz', '../../bar'))
       .toEqual('http://www.foo.com/bar');
 });
开发者ID:AsherBarak,项目名称:angular,代码行数:10,代码来源:url_resolver_spec.ts

示例4: SyncAsyncResult

  _inlineImports(cssText: string, baseUrl: string,
                 inlinedUrls: List<string>): SyncAsyncResult<string> {
    var partIndex = 0;
    var parts = StringWrapper.split(cssText, _importRe);

    if (parts.length === 1) {
      // no @import rule found, return the original css
      return new SyncAsyncResult(cssText, null);
    }

    var promises = [];

    while (partIndex < parts.length - 1) {
      // prefix is the content before the @import rule
      var prefix = parts[partIndex];
      // rule is the parameter of the @import rule
      var rule = parts[partIndex + 1];
      var url = _extractUrl(rule);
      if (isPresent(url)) {
        url = this._urlResolver.resolve(baseUrl, url);
      }
      var mediaQuery = _extractMediaQuery(rule);
      var promise;

      if (isBlank(url)) {
        promise = PromiseWrapper.resolve(`/* Invalid import rule: "@import ${rule};" */`);
      } else if (ListWrapper.contains(inlinedUrls, url)) {
        // The current import rule has already been inlined, return the prefix only
        // Importing again might cause a circular dependency
        promise = PromiseWrapper.resolve(prefix);
      } else {
        ListWrapper.push(inlinedUrls, url);
        promise = PromiseWrapper.then(this._xhr.get(url), (rawCss) => {
          // resolve nested @import rules
          var inlinedCss = this._inlineImports(rawCss, url, inlinedUrls);
          if (isPresent(inlinedCss.asyncResult)) {
            // wait until nested @import are inlined
            return inlinedCss.asyncResult.then(
                (css) => {return prefix + this._transformImportedCss(css, mediaQuery, url) + '\n'});
          } else {
            // there are no nested @import, return the css
            return prefix + this._transformImportedCss(inlinedCss.syncResult, mediaQuery, url) +
                   '\n';
          }
        }, (error) => `/* failed to import ${url} */\n`);
      }
      ListWrapper.push(promises, promise);
      partIndex += 2;
    }

    return new SyncAsyncResult(null, PromiseWrapper.all(promises).then(function(cssParts) {
      var cssText = cssParts.join('');
      if (partIndex < parts.length) {
        // append then content located after the last @import rule
        cssText += parts[partIndex];
      }
      return cssText;
    }));
  }
开发者ID:baraksu,项目名称:angular,代码行数:59,代码来源:style_inliner.ts

示例5:

    return StringWrapper.replaceAllMapped(cssText, re, (m) => {
      var pre = m[1];
      var url = StringWrapper.replaceAll(m[2], _quoteRe, '');
      var post = m[3];

      var resolvedUrl = this._resolver.resolve(baseUrl, url);

      return pre + "'" + resolvedUrl + "'" + post;
    });
开发者ID:AsherBarak,项目名称:angular,代码行数:9,代码来源:style_url_resolver.ts

示例6:

    return StringWrapper.replaceAllMapped(cssText, re, (m) => {
      var pre = m[1];
      var originalUrl = m[2];
      if (RegExpWrapper.test(_dataUrlRe, originalUrl)) {
        // Do not attempt to resolve data: URLs
        return m[0];
      }
      var url = StringWrapper.replaceAll(originalUrl, _quoteRe, '');
      var post = m[3];

      var resolvedUrl = this._resolver.resolve(baseUrl, url);

      return pre + "'" + resolvedUrl + "'" + post;
    });
开发者ID:KenWilliamson,项目名称:Angular2HostedMobileApp,代码行数:14,代码来源:style_url_resolver.ts

示例7: expect

 () => {
   expect(resolver.resolve('http://www.foo.com', 'http://www.bar.com'))
       .toEqual('http://www.bar.com');
 })
开发者ID:AsherBarak,项目名称:angular,代码行数:4,代码来源:url_resolver_spec.ts


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