Did I find the right examples for you? yes no

All Samples(9)  |  Call(7)  |  Derive(0)  |  Import(2)
Sort resources for inclusion on web page.

A number of rules are followed:

* resources are always grouped per renderer (.js, .css, etc)
* resources that depend on other resources are sorted later
* resources are grouped by library, if the dependencies allow it
* libraries are sorted by name, if dependencies allow it
* resources are sorted by resource path if they both would be
  sorted the same otherwise.(more...)

        def sort_resources(resources):
    """Sort resources for inclusion on web page.

    A number of rules are followed:

    * resources are always grouped per renderer (.js, .css, etc)
    * resources that depend on other resources are sorted later
    * resources are grouped by library, if the dependencies allow it
    * libraries are sorted by name, if dependencies allow it
    * resources are sorted by resource path if they both would be
      sorted the same otherwise.

    The only purpose of sorting on library is so we can
    group resources per library, so that bundles can later be created
    of them if bundling support is enabled.

    Note this sorting algorithm guarantees a consistent ordering, no
    matter in what order resources were needed.
    """
    for resource in resources:
        resource.library.init_library_nr()

    def key(resource):
        return (
            resource.order,
            resource.library.library_nr,
            resource.library.name,
            resource.dependency_nr,
            resource.relpath)
    return sorted(resources, key=key)
        


src/f/a/fanstatic-1.0a5/tests/test_slot.py   fanstatic(Download)
import pytest
 
from fanstatic import NeededResources, Library, Resource
from fanstatic import Slot, SlotError, Inclusion
from fanstatic import sort_resources
    needed.need(a, {slot: b})
 
    resources = sort_resources(needed.resources())
    assert len(resources) == 2
    # verify filled slot is correctly
    a = Resource(lib, 'a.js', depends=[slot])
    needed = NeededResources(resources=[a])
    relpaths = [r.relpath for r in sort_resources(needed.resources())]
    assert relpaths == ['b.js', 'a.js']
 
    needed.need(a, {slot: custom_resource_for_slot})
 
    relpaths = [r.relpath for r in sort_resources(needed.resources())]
    assert relpaths == ['c.js', 'a.js']
 
    needed.need(a, {slot: b})
 
    assert [r.relpath for r in sort_resources(needed.resources())] == \
        ['b.js', 'a.js']
 

src/f/a/fanstatic-1.0a5/tests/test_bundle.py   fanstatic(Download)
from fanstatic import Library, Resource, NeededResources, bundle_resources, sort_resources
from fanstatic import Inclusion
 
from fanstatic.core import Bundle
 
    # The resources are sorted by renderer order, library dependencies
    # and resource dependencies.
    bundle = bundle_resources(sort_resources([x1, x3, x2]))
    assert len(bundle) == 2
    assert isinstance(bundle[0], Bundle)