コード例 #1
0
def analyzeAndPackageAssets(site):
    sys.stdout.write('Analyzing %d gathered assets across %d pages...' %
                     (len(list(itertools.chain.from_iterable(assets))),
                      len(assets))
                     )
    sys.stdout.flush()
    replace_map = {}

    # determine what should be packaged with what
    packages = AssetPackager.analyze(assets)
    print('done')

    for i, package in enumerate(packages):
        sys.stdout.write(
            '\rPacking analyzed assets into %d packages (%d/%d)' %
            (len(packages), i + 1, len(packages))
        )
        sys.stdout.flush()

        packaged_filename, no_local = _getPackagedFilename(package)

        if len(package) <= 1 and (no_local or not COMPRESS_PACKAGES):
            # it would be silly to compress a remote file and "package it with itself"
            # also silly for a local file to be packaged with itself if we
            # won't be compressing it
            continue

        # Create and save the packaged, minified files
        AssetPackager.package(
            package,
            _relToStaticBuild(site, packaged_filename),
            compress=COMPRESS_PACKAGES,
            filename_markers_in_comments=INCLUDE_ORIGINAL_FILENAMES_IN_COMMENTS
        )

        for asset in package:
            replace_map[asset] = packaged_filename

    sys.stdout.write('\nUpdating HTML sources...')
    sys.stdout.flush()
    for page in site.pages():
        path = page.paths['full-build']

        with open(pipes.quote(path), 'r') as f:
            html = _replaceHTMLWithPackaged(f.read(), replace_map, path, site)
            f.close()
        with open(pipes.quote(path), "wb") as f:
            f.write(html)
            f.close()

    for asset in inline_assets:
        os.remove(asset)  # clean up temp buffers
    print('done')
コード例 #2
0
def analyzeAndPackageAssets(site):
  sys.stdout.write('Analyzing %d gathered assets across %d pages...' %
    (len(list(itertools.chain.from_iterable(assets))), len(assets))
  )
  sys.stdout.flush()
  replace_map = {}

  # determine what should be packaged with what
  packages = AssetPackager.analyze(assets)
  print('done')

  for i, package in enumerate(packages):
    sys.stdout.write(
      '\rPacking analyzed assets into %d packages (%d/%d)' %
      (len(packages), i + 1, len(packages))
    )
    sys.stdout.flush()

    packaged_filename, no_local = _getPackagedFilename(package)

    if len(package) <= 1 and (no_local or not COMPRESS_PACKAGES):
      # it would be silly to compress a remote file and "package it with itself"
      # also silly for a local file to be packaged with itself if we won't be compressing it
      continue

    # Create and save the packaged, minified files
    AssetPackager.package(
      package,
      _relToStaticBuild(site, packaged_filename),
      compress = COMPRESS_PACKAGES,
      filename_markers_in_comments = INCLUDE_ORIGINAL_FILENAMES_IN_COMMENTS
    )

    for asset in package:
      replace_map[asset] = packaged_filename

  sys.stdout.write('\nUpdating HTML sources...')
  sys.stdout.flush()
  for page in site.pages():
    path = page.paths['full-build']

    with open(pipes.quote(path), 'r') as f:
      html = _replaceHTMLWithPackaged(f.read(), replace_map, path, site)
      f.close()
    with open(pipes.quote(path), "wb") as f:
      f.write(html)
      f.close()

  for asset in inline_assets:
    os.remove(asset) # clean up temp buffers
  print('done')
コード例 #3
0
 def match(a, b):
   self.assertEqual(AssetPackager.analyze(a), b)