Commits

Anonymous committed ef1bf7f

ResourceInclusion -> Resource

NeededInclusions -> NeededResources

get_current_needed_inclusions -> get_needed()

init_current_needed_inclusions -> init_needed()

some other small cleanups.

  • Participants
  • Parent commits 838932e

Comments (0)

Files changed (10)

fanstatic/__init__.py

 from fanstatic.core import (Library,
-                            ResourceInclusion,
-                            GroupInclusion,
-                            NeededInclusions,
+                            Resource,
+                            GroupResource,
+                            NeededResources,
                             DEFAULT_SIGNATURE,
-                            sort_inclusions_topological,
-                            sort_inclusions_by_extension)
+                            sort_resources_topological,
+                            sort_resources_by_extension)
 
 from fanstatic.registry import library_registry, LibraryRegistry
 
 from fanstatic.codegen import generate_code
 
-from fanstatic.core import (init_current_needed_inclusions,
-                            get_current_needed_inclusions,
+from fanstatic.core import (init_needed,
+                            get_needed,
                             inclusion_renderers,
-                            NoNeededInclusions,
+                            NoNeededResources,
                             UnknownResourceExtension,
                             EXTENSIONS,
                             NEEDED)

fanstatic/codegen.py

-from fanstatic import sort_inclusions_topological, sort_inclusions_by_extension
+from fanstatic import sort_resources_topological, sort_resources_by_extension
 
 def generate_code(**kw):
-    inclusion_to_name = {}
-    inclusions = []
-    for name, inclusion in kw.items():
-        inclusion_to_name[inclusion.key()] = name
-        inclusions.append(inclusion)
+    resource_to_name = {}
+    resources = []
+    for name, resource in kw.items():
+        resource_to_name[resource.key()] = name
+        resources.append(resource)
 
     # libraries with the same name are the same libraries
     libraries = {}
-    for inclusion in inclusions:
-        libraries[inclusion.library.name] = inclusion.library
+    for resource in resources:
+        libraries[resource.library.name] = resource.library
     libraries = sorted(libraries.values())
 
     result = []
     # import on top
-    result.append("from fanstatic import Library, ResourceInclusion")
+    result.append("from fanstatic import Library, Resource")
     result.append("")
     # define libraries
     for library in libraries:
                       (library.name, library.name, library.rootpath))
     result.append("")
 
-    # sort inclusions in the order we want them to be
-    inclusions = sort_inclusions_by_extension(
-        sort_inclusions_topological(inclusions))
+    # sort resources in the order we want them to be
+    resources = sort_resources_by_extension(
+        sort_resources_topological(resources))
 
-    # now generate inclusion code
-    for inclusion in inclusions:
-        s = "%s = ResourceInclusion(%s, '%s'" % (
-            inclusion_to_name[inclusion.key()],
-            inclusion.library.name,
-            inclusion.relpath)
-        if inclusion.depends:
+    # now generate resource code
+    for resource in resources:
+        s = "%s = Resource(%s, '%s'" % (
+            resource_to_name[resource.key()],
+            resource.library.name,
+            resource.relpath)
+        if resource.depends:
             depends_s = ', depends=[%s]' % ', '.join(
-                [inclusion_to_name[d.key()] for d in inclusion.depends])
+                [resource_to_name[d.key()] for d in resource.depends])
             s += depends_s
-        if inclusion.supersedes:
+        if resource.supersedes:
             supersedes_s = ', supersedes=[%s]' % ', '.join(
-                [inclusion_to_name[i.key()] for i in inclusion.supersedes])
+                [resource_to_name[i.key()] for i in resource.supersedes])
             s += supersedes_s
-        if inclusion.modes:
+        if resource.modes:
             items = []
-            for mode_name, mode in inclusion.modes.items():
+            for mode_name, mode in resource.modes.items():
                 items.append((mode_name,
-                              generate_inline_inclusion(mode, inclusion)))
+                              generate_inline_resource(mode, resource)))
             items = sorted(items)
             modes_s = ', %s' % ', '.join(["%s=%s" % (name, mode) for
                                           (name, mode) in items])
         result.append(s)
     return '\n'.join(result)
 
-def generate_inline_inclusion(inclusion, associated_inclusion):
-    if inclusion.library.name == associated_inclusion.library.name:
-        return "'%s'" % inclusion.relpath
+def generate_inline_resource(resource, associated_resource):
+    if resource.library.name == associated_resource.library.name:
+        return "'%s'" % resource.relpath
     else:
-        return "ResourceInclusion(%s, '%s')" % (inclusion.library.name,
-                                                inclusion.relpath)
+        return "Resource(%s, '%s')" % (resource.library.name,
+                                       resource.relpath)
 

fanstatic/core.py

     """The resource library.
 
     This object defines which directory is published and can be
-    referred to by :py:class:`ResourceInclusion` objects to describe
+    referred to by :py:class:`Resource` objects to describe
     these resources.
 
     :param name: A string that uniquely identifies this library.
 def caller_dir():
     return os.path.dirname(sys._getframe(2).f_globals['__file__'])
 
-class InclusionBase(object):
+class ResourceBase(object):
     pass
 
-class ResourceInclusion(InclusionBase):
-    """A resource inclusion.
+class Resource(ResourceBase):
+    """A resource.
 
-    A resource inclusion specifies how to include a single resource in
-    a library in a web page. This is useful for Javascript and CSS
+    A resource specifies a single resource in a library so that it can
+    be included in a web page. This is useful for Javascript and CSS
     resources in particular. Some static resources such as images are
     not included in this way and therefore do not have to be defined
     this way.
       path) that indicates the actual resource file.
 
     :param depends: optionally, a list of resources that this resource
-      depends on. Entries in the list can be
-      :py:class:`ResourceInclusion` instances, or, as a shortcut,
-      strings that are paths to resources. If a string is given, a
-      :py:class:`ResourceInclusion` instance is constructed that has
-      the same library as this inclusion.
+      depends on. Entries in the list can be :py:class:`Resource`
+      instances, or, as a shortcut, strings that are paths to
+      resources. If a string is given, a :py:class:`Resource` instance
+      is constructed that has the same library as this resource.
 
-    :param supersedes: optionally, a list of
-      :py:class:`ResourceInclusion` instances that this resource
-      inclusion supersedes as a rollup resource. If all these resources
-      are required for render a page, the superseding resource will be
-      included instead.
+    :param supersedes: optionally, a list of :py:class:`Resource`
+      instances that this resource supersedes as a rollup
+      resource. If all these resources are required for render a page,
+      the superseding resource will be included instead.
 
     :param eager_superseder: normally superseding resources will only
       show up if all resources that the resource supersedes are
       required in a page. If this flag is set, even if only part of the
       requirements are met, the superseding resource will show up.
 
-    :param bottom: indicate that this resource inclusion is "bottom
-      safe": it can be safely included on the bottom of the page (just
-      before ``</body>``). This can be used to improve the performance
-      of page loads when Javascript resources are in use. Not all
+    :param bottom: indicate that this resource is "bottom safe": it
+      can be safely included on the bottom of the page (just before
+      ``</body>``). This can be used to improve the performance of
+      page loads when Javascript resources are in use. Not all
       Javascript-based resources can however be safely included that
       way, so you have to set this explicitly (or use the
-      ``force_bottom`` option on :py:class:`NeededInclusions`).
+      ``force_bottom`` option on :py:class:`NeededResources`).
 
     :param ``**kw``: keyword parameters can be supplied to indicate
-      alternate resource inclusions. An alternate inclusion is for
-      instance a minified version of this resource. The name of the
-      parameter indicates the type of alternate resource (``debug``,
+      alternate resources. An alternate resource is for instance a
+      minified version of this resource. The name of the parameter
+      indicates the type of alternate resource (``debug``,
       ``minified``, etc), and the value is a
-      :py:class:`ResourceInclusion` instance.
+      :py:class:`Resource` instance.
 
       As a shortcut, a string can be supplied as value that indicates
       the relative path to a resource in the library (for instance the
-      minified file). In this case :py:class:`ResourceInclusion`
-      instance is constructed that has the same library as this
-      inclusion.
+      minified file). In this case :py:class:`Resource` instance is
+      constructed that has the same library as this resource.
     """
 
     def __init__(self, library, relpath, depends=None,
 
         assert not isinstance(depends, basestring)
         depends = depends or []
-        self.depends = normalize_inclusions(library, depends)
+        self.depends = normalize_resources(library, depends)
 
         self.rollups = []
 
         normalized_modes = {}
-        for mode_name, inclusion in kw.items():
-            normalized_modes[mode_name] = normalize_inclusion(
-                library, inclusion)
+        for mode_name, resource in kw.items():
+            normalized_modes[mode_name] = normalize_resource(
+                library, resource)
         self.modes = normalized_modes
 
         assert not isinstance(supersedes, basestring)
         self.supersedes = supersedes or []
         self.eager_superseder = eager_superseder
 
-        # create a reference to the superseder in the superseded inclusion
-        for inclusion in self.supersedes:
-            inclusion.rollups.append(self)
+        # create a reference to the superseder in the superseded resource
+        for resource in self.supersedes:
+            resource.rollups.append(self)
         # also create a reference to the superseding mode in the superseded
         # mode
-        # XXX what if mode is full-fledged resource inclusion which lists
+        # XXX what if mode is full-fledged resource which lists
         # supersedes itself?
         for mode_name, mode in self.modes.items():
-            for inclusion in self.supersedes:
-                superseded_mode = inclusion.mode(mode_name)
+            for resource in self.supersedes:
+                superseded_mode = resource.mode(mode_name)
                 # if there is no such mode, let's skip it
-                if superseded_mode is inclusion:
+                if superseded_mode is resource:
                     continue
                 mode.supersedes.append(superseded_mode)
                 superseded_mode.rollups.append(mode)
 
     def __repr__(self):
-        return "<ResourceInclusion '%s' in library '%s'>" % (
+        return "<Resource '%s' in library '%s'>" % (
             self.relpath, self.library.name)
 
     def ext(self):
-        """The extension of this resource inclusion.
+        """The extension of this resource.
 
         An extension starts with a period. Examples ``.js``, ``.css``.
         """
         return ext
 
     def mode(self, mode):
-        """Get ResourceInclusion in another mode.
+        """Get Resource in another mode.
 
         If the mode is ``None`` or if the mode cannot be found, this
-        ``ResourceInclusion`` instance is returned instead.
+        ``Resource`` instance is returned instead.
 
         :param mode: a string indicating the mode, or ``None``.
         """
             return self
 
     def key(self):
-        """A unique key that identifies this ResourceInclusion.
+        """A unique key that identifies this Resource.
         """
         return self.library.name, self.relpath
 
     def need(self):
-        """Need this resource inclusion.
+        """Declare that the application needs this resource.
 
-        If you call ``.need()`` on ``ResourceInclusion`` sometime
-        during the rendering process of your web page, this resource
-        inclusion and all its dependencies will be inserted into the
-        web page.
+        If you call ``.need()`` on ``Resource`` sometime during the
+        rendering process of your web page, this resource and all its
+        dependencies will be inserted as inclusions into the web page.
         """
-        needed = get_current_needed_inclusions()
+        needed = get_needed()
         needed.need(self)
 
-    def inclusions(self):
-        """Get all inclusions needed by this inclusion, including itself.
+    def resources(self):
+        """Get all resources needed by this resource, including itself.
         """
         result = []
         for depend in self.depends:
-            result.extend(depend.inclusions())
+            result.extend(depend.resources())
         result.append(self)
         return result
 
-class GroupInclusion(InclusionBase):
-    """An inclusion used to group resources together.
+class GroupResource(ResourceBase):
+    """A resource used to group resources together.
 
-    It doesn't define a resource inclusion itself, but instead depends on other
-    resource inclusions. When a GroupInclusion is depended on, all the
+    It doesn't define a resource file itself, but instead depends on
+    other resources. When a GroupResources is depended on, all the
     resources grouped together will be included.
 
    :param depends: a list of resources that this resource depends
-     on. Entries in the list can be :py:class:`ResourceInclusion`
-     instances, or :py:class:`GroupInclusion` instances.
+     on. Entries in the list can be :py:class:`Resource` instances, or
+     :py:class:`GroupResource` instances.
     """
     def __init__(self, depends):
         self.depends = depends
 
     def need(self):
-        """Need this group inclusion.
+        """Need this group resource.
 
-        If you call ``.need()`` on ``GroupInclusion`` sometime
+        If you call ``.need()`` on ``GroupResource`` sometime
         during the rendering process of your web page, all dependencies
-        of this group inclusion will be inserted into the web page.
+        of this group resources will be inserted into the web page.
         """
-        needed = get_current_needed_inclusions()
+        needed = get_needed()
         needed.need(self)
 
-    def inclusions(self):
-        """Get all inclusions needed by this inclusion.
+    def resources(self):
+        """Get all resources needed by this resource.
         """
         result = []
         for depend in self.depends:
-            result.extend(depend.inclusions())
+            result.extend(depend.resources())
         return result
 
-def normalize_inclusions(library, inclusions):
-    return [normalize_inclusion(library, inclusion)
-            for inclusion in inclusions]
+def normalize_resources(library, resources):
+    return [normalize_resource(library, resource)
+            for resource in resources]
 
-def normalize_inclusion(library, inclusion):
-    if isinstance(inclusion, InclusionBase):
-        return inclusion
-    assert isinstance(inclusion, basestring)
-    return ResourceInclusion(library, inclusion)
+def normalize_resource(library, resource):
+    if isinstance(resource, ResourceBase):
+        return resource
+    assert isinstance(resource, basestring)
+    return Resource(library, resource)
 
-class NeededInclusions(object):
-    """The current selection of needed inclusions.
+class NeededResources(object):
+    """The current selection of needed resources..
 
-    The ``NeededInclusions`` instance maintains a set of needed
-    inclusions for a particular web page.
+    The ``NeededResources`` instance maintains a set of needed
+    resources for a particular web page.
 
     :param hashing: If ``True``, Fanstatic will automatically include
       a hash in all URLs pointing to resources. Since the hash will change
       calculated once after server startup.
 
     :param bottom: If set to ``True``, Fanstatic will include any
-      resource inclusion that has been marked as "bottom safe" at the
-      bottom of the web page, at the end of ``<body>``, as opposed to
-      in the ``<head>`` section. This is useful for optimizing the
-      load-time of Javascript resources.
+      resource that has been marked as "bottom safe" at the bottom of
+      the web page, at the end of ``<body>``, as opposed to in the
+      ``<head>`` section. This is useful for optimizing the load-time
+      of Javascript resources.
 
     :param force_bottom: If set to ``True`` and ``bottom`` is set to
       ``True`` as well, all Javascript resources will be included at
     :param base_url: This URL will be prefixed in front of all resource
       URLs. This can be useful if your web framework wants the resources
       to be published on a sub-URL. Note that this can also be set
-      as an attribute on an ``NeededInclusions`` instance.
+      as an attribute on an ``NeededResources`` instance.
 
     :param publisher_signature: The name under which resource libraries
       should be served in the URL. By default this is ``fanstatic``, so
       URLs to resources will start with ``/fanstatic/``.
 
-    :param inclusions: Optionally, a list of resources we want to
+    :param resources: Optionally, a list of resources we want to
       include. Normally you specify resources to include by calling
       ``.need()`` on them, or alternatively by calling ``.need()``
       on an instance of this class.
     URLs. This can be useful if your web framework wants the resources
     to be published on a sub-URL. It is allowed for a web framework
     to change this attribute directly on an already existing
-    ``NeededInclusions`` object.
+    ``NeededResources`` object.
     """
 
     def __init__(self,
                  rollup=False,
                  base_url=None,
                  publisher_signature=DEFAULT_SIGNATURE,
-                 inclusions=None,
+                 resources=None,
                  ):
         self._hashing = hashing
         self._devmode = devmode
         self._publisher_signature = publisher_signature
         self._rollup = rollup
 
-        self._inclusions = inclusions or []
+        self._resources = resources or []
 
-    def has_inclusions(self):
-        """Returns True if any inclusions are needed.
+    def has_resources(self):
+        """Returns True if any resources are needed.
         """
-        return bool(self._inclusions)
+        return bool(self._resources)
 
-    def need(self, inclusion):
-        """Add a particular inclusion to the needed inclusions.
+    def need(self, resource):
+        """Add a particular resource to the needed resources.
 
         This is an alternative to calling ``.need()`` on the resource
-        inclusion directly.
+        directly.
 
-        :param inclusion: A :py:class:`ResourceInclusion` instance.
+        :param resource: A :py:class:`Resource` instance.
         """
-        self._inclusions.append(inclusion)
+        self._resources.append(resource)
 
-    def _sorted_inclusions(self):
-        return reversed(sorted(self._inclusions, key=lambda i: i.depth()))
+    def resources(self):
+        """Retrieve the list of resources needed.
 
-    def inclusions(self):
-        """Retrieve the list of resource inclusions needed.
+        This returns the needed :py:class:`Resource`
+        instances.  Resources are guaranteed to come earlier in the
+        list than those resources that depend on them.
 
-        This returns the needed :py:class:`ResourceInclusion`
-        instances.  Inclusions are guaranteed to come earlier in the
-        list than those inclusions that depend on them.
+        Resources are also sorted by extension.
+        """
+        resources = []
+        for resource in self._resources:
+            resources.extend(resource.resources())
 
-        Inclusions are also sorted by extension.
-        """
-        inclusions = []
-        for inclusion in self._inclusions:
-            inclusions.extend(inclusion.inclusions())
-
-        inclusions = [inclusion.mode(self._mode) for inclusion in inclusions]
+        resources = [resource.mode(self._mode) for resource in resources]
 
         if self._rollup:
-            inclusions = consolidate(inclusions)
+            resources = consolidate(resources)
         # sort only by extension, not dependency, as we can rely on
-        # python's stable sort to keep inclusion order intact
-        inclusions = sort_inclusions_by_extension(inclusions)
-        inclusions = remove_duplicates(inclusions)
+        # python's stable sort to keep resource inclusion order intact
+        resources = sort_resources_by_extension(resources)
+        resources = remove_duplicates(resources)
 
-        return inclusions
+        return resources
 
     def library_url(self, library):
         """Construct URL to library.
         return '/'.join(path)
 
     def render(self):
-        """Render needed inclusions.
+        """Render needed resource inclusions.
 
-        This returns a string with the rendered inclusions
+        This returns a string with the rendered resource inclusions
         (``<script>`` and ``<link>`` tags), suitable for including
         in the ``<head>`` section of a web page.
         """
-        return self.render_inclusions(self.inclusions())
+        return self.render_inclusions(self.resources())
 
-    def render_inclusions(self, inclusions):
-        """Render a set of inclusions.
+    def render_inclusions(self, resources):
+        """Render a set of resources as inclusions.
 
         This renders the listed inclusions and their dependencies as
         HTML ((``<script>`` and ``<link>`` tags), suitable for
         inclusion on a web page.
 
-        :param inclusions: A list of :py:class:`ResourceInclusion` instances.
+        :param inclusions: A list of :py:class:`Resource` instances.
         """
         result = []
         url_cache = {} # prevent multiple computations for a library in one request
-        for inclusion in inclusions:
-            library = inclusion.library
+        for resource in resources:
+            library = resource.library
             library_url = url_cache.get(library.name)
             if library_url is None:
                 library_url = url_cache[library.name] = self.library_url(
                     library)
             result.append(
                 render_inclusion(
-                    inclusion, '%s/%s' %(library_url, inclusion.relpath)))
+                    resource, '%s/%s' %(library_url, resource.relpath)))
         return '\n'.join(result)
 
     def render_into_html(self, html):
-        """Render needed inclusions into HTML.
+        """Render needed resource inclusions into HTML.
 
-        :param html: A string with HTML to render the inclusions into. This
-          string must have a ``<head>`` section.
+        :param html: A string with HTML to render the resource
+          inclusions into. This string must have a ``<head>`` section.
         """
         to_insert = self.render()
         return html.replace('<head>', '<head>\n    %s\n' % to_insert, 1)
 
     def render_topbottom(self):
-        """Render inclusions separately into top and bottom fragments.
+        """Render resource inclusions separately into top and bottom fragments.
 
         Returns a tuple of two HTML snippets, top and bottom.  The top
         one is to be included in a ``<head>`` section, and the bottom
         unless ``force_bottom`` is enabled, in which case all Javascript
         resources will be included in the bottom.
         """
-        inclusions = self.inclusions()
+        resources = self.resources()
 
         # seperate inclusions in top and bottom inclusions if this is needed
         if self._bottom:
-            top_inclusions = []
-            bottom_inclusions = []
+            top_resources = []
+            bottom_resources = []
             if not self._force_bottom:
-                for inclusion in inclusions:
-                    if inclusion.bottom:
-                        bottom_inclusions.append(inclusion)
+                for resource in resources:
+                    if resource.bottom:
+                        bottom_resources.append(resource)
                     else:
-                        top_inclusions.append(inclusion)
+                        top_resources.append(resource)
             else:
-                for inclusion in inclusions:
-                    if inclusion.ext() == '.js':
-                        bottom_inclusions.append(inclusion)
+                for resource in resources:
+                    if resource.ext() == '.js':
+                        bottom_resources.append(resource)
                     else:
-                        top_inclusions.append(inclusion)
+                        top_resources.append(resource)
         else:
-            top_inclusions = inclusions
-            bottom_inclusions = []
+            top_resources = resources
+            bottom_resources = []
 
-        return (self.render_inclusions(top_inclusions),
-                self.render_inclusions(bottom_inclusions))
+        return (self.render_inclusions(top_resources),
+                self.render_inclusions(bottom_resources))
 
     def render_topbottom_into_html(self, html):
-        """Render needed inclusions into HTML.
+        """Render needed resource inclusions into HTML.
 
         Only bottom safe resources are included in the bottom section,
         unless ``force_bottom`` is enabled, in which case all
         Javascript resources will be included in the bottom, just
         before the ``</body>`` tag.
 
-        :param html: A string with HTML to render the inclusions into. This
-          string must have a ``<head>`` and a ``<body>`` section.
+        :param html: The HTML string in which to insert the rendered
+          resource inclusions.  This string must have a ``<head>`` and
+          a ``<body>`` section.
         """
         top, bottom = self.render_topbottom()
         if top:
             html = html.replace('</body>', '%s</body>' % bottom, 1)
         return html
 
-class NoNeededInclusions(Exception):
+class NoNeededResources(Exception):
     pass
 
 thread_local_needed_data = threading.local()
 
-def init_current_needed_inclusions(*args, **kw):
-    needed = NeededInclusions(*args, **kw)
+def init_needed(*args, **kw):
+    needed = NeededResources(*args, **kw)
     thread_local_needed_data.__dict__[NEEDED] = needed
     return needed
 
-def get_current_needed_inclusions():
+def get_needed():
     needed = thread_local_needed_data.__dict__.get(NEEDED)
     if needed is None:
-        raise NoNeededInclusions('No NeededInclusions object initialized.')
+        raise NoNeededResources('No NeededResources object initialized.')
     return needed
 
-def remove_duplicates(inclusions):
-    """Given a set of inclusions, consolidate them so each only occurs once.
+def remove_duplicates(resources):
+    """Given a set of resources, consolidate them so each only occurs once.
     """
     seen = set()
     result = []
-    for inclusion in inclusions:
-        if inclusion.key() in seen:
+    for resource in resources:
+        key = resource.key()
+        if key in seen:
             continue
-        seen.add(inclusion.key())
-        result.append(inclusion)
+        seen.add(key)
+        result.append(resource)
     return result
 
-def consolidate(inclusions):
-    # keep track of rollups: rollup key -> set of inclusion keys
+def consolidate(resources):
+    # keep track of rollups: rollup key -> set of resource keys
     potential_rollups = {}
-    for inclusion in inclusions:
-        for rollup in inclusion.rollups:
+    for resource in resources:
+        for rollup in resource.rollups:
             s = potential_rollups.setdefault(rollup.key(), set())
-            s.add(inclusion.key())
+            s.add(resource.key())
 
-    # now go through inclusions, replacing them with rollups if
+    # now go through resources, replacing them with rollups if
     # conditions match
     result = []
-    for inclusion in inclusions:
+    for resource in resources:
         eager_superseders = []
         exact_superseders = []
-        for rollup in inclusion.rollups:
+        for rollup in resource.rollups:
             s = potential_rollups[rollup.key()]
             if rollup.eager_superseder:
                 eager_superseders.append(rollup)
             result.append(exact_superseders[-1])
         else:
             # nothing to supersede resource so use it directly
-            result.append(inclusion)
+            result.append(resource)
     return result
 
-def sort_inclusions_by_extension(inclusions):
+def sort_resources_by_extension(resources):
+    def key(resource):
+        return EXTENSIONS.index(resource.ext())
+    return sorted(resources, key=key)
 
-    def key(inclusion):
-        return EXTENSIONS.index(inclusion.ext())
-
-    return sorted(inclusions, key=key)
-
-def sort_inclusions_topological(inclusions):
-    """Sort inclusions by dependency and supersedes.
+def sort_resources_topological(resources):
+    """Sort resources by dependency and supersedes.
     """
     dead = {}
     result = []
-    for inclusion in inclusions:
-        dead[inclusion.key()] = False
+    for resource in resources:
+        dead[resource.key()] = False
 
-    for inclusion in inclusions:
-        _visit(inclusion, result, dead)
+    for resource in resources:
+        _visit(resource, result, dead)
     return result
 
-def _visit(inclusion, result, dead):
-    if dead[inclusion.key()]:
+def _visit(resource, result, dead):
+    if dead[resource.key()]:
         return
-    dead[inclusion.key()] = True
-    for depend in inclusion.depends:
+    dead[resource.key()] = True
+    for depend in resource.depends:
         _visit(depend, result, dead)
-    for depend in inclusion.supersedes:
+    for depend in resource.supersedes:
         _visit(depend ,result, dead)
-    result.append(inclusion)
+    result.append(resource)
 
 def render_css(url):
     return ('<link rel="stylesheet" type="text/css" href="%s" />' %
     '.js': render_js,
     }
 
-def render_inclusion(inclusion, url):
-    renderer = inclusion_renderers.get(inclusion.ext(), None)
+def render_inclusion(resource, url):
+    renderer = inclusion_renderers.get(resource.ext(), None)
     if renderer is None:
         raise UnknownResourceExtension(
-            "Unknown resource extension %s for resource inclusion: %s" %
-            (inclusion.ext(), repr(inclusion)))
+            "Unknown resource extension %s for resource: %s" %
+            (resource.ext(), repr(resource)))
     return renderer(url)

fanstatic/injector.py

 class Injector(object):
     """Fanstatic injector WSGI framework component.
 
-    This WSGI component takes care of injecting the proper inclusions
-    into HTML when needed.
+    This WSGI component takes care of injecting the proper resource
+    inclusions into HTML when needed.
 
     This WSGI component is used automatically by the
     :py:func:`Fanstatic` WSGI framework component, but can also be
     :param app: The WSGI app to wrap with the injector.
 
     :param ``**config``: Optional keyword arguments. These are
-      passed to :py:class:`NeededInclusions` when it is constructed.
+      passed to :py:class:`NeededResources` when it is constructed.
     """
     def __init__(self, app, **config):
         self.application = app
 
-        self._check_inclusions_signature(**config)
+        self._check_signature(**config)
         self.config = config
 
     # To get a correct error message on initialize-time, we construct
-    # a function that has the same signature as NeededInclusions(),
+    # a function that has the same signature as NeededResources(),
     # but without "self".
-    def _check_inclusions_signature(self, **config):
+    def _check_signature(self, **config):
         args, varargs, varkw, defaults = inspect.getargspec(
-            fanstatic.NeededInclusions.__init__)
+            fanstatic.NeededResources.__init__)
         argspec = inspect.formatargspec(args[1:], varargs, varkw, defaults)
         exec("def signature_checker" + argspec + ": pass")
         try:
         except TypeError, e:
             message = e.args[0]
             message = message.replace(
-                "signature_checker()", fanstatic.NeededInclusions.__name__)
+                "signature_checker()", fanstatic.NeededResources.__name__)
             raise TypeError(message)
 
     @webob.dec.wsgify
     def __call__(self, request):
-        needed = fanstatic.init_current_needed_inclusions(**self.config)
+        needed = fanstatic.init_needed(**self.config)
 
         # Get the response from the wrapped application:
         response = request.get_response(self.application)
             return response
 
         # The wrapped application may have left information in the environment
-        # about needed inclusions.
-        if needed.has_inclusions():
+        # about needed resources
+        if needed.has_resources():
             response.body = needed.render_topbottom_into_html(response.body)
         return response
 

fanstatic/test_codegen.py

-from fanstatic import generate_code, Library, ResourceInclusion
+from fanstatic import generate_code, Library, Resource
 
 def test_generate_source():
     foo = Library('foo', '')
-    i1 = ResourceInclusion(foo, 'i1.js')
-    i2 = ResourceInclusion(foo, 'i2.js', depends=[i1])
-    i3 = ResourceInclusion(foo, 'i3.js', depends=[i2])
-    i4 = ResourceInclusion(foo, 'i4.js', depends=[i1])
-    i5 = ResourceInclusion(foo, 'i5.js', depends=[i4, i3])
+    i1 = Resource(foo, 'i1.js')
+    i2 = Resource(foo, 'i2.js', depends=[i1])
+    i3 = Resource(foo, 'i3.js', depends=[i2])
+    i4 = Resource(foo, 'i4.js', depends=[i1])
+    i5 = Resource(foo, 'i5.js', depends=[i4, i3])
 
     assert generate_code(i1=i1, i2=i2, i3=i3, i4=i4, i5=i5) == '''\
-from fanstatic import Library, ResourceInclusion
+from fanstatic import Library, Resource
 
 foo = Library('foo', '')
 
-i1 = ResourceInclusion(foo, 'i1.js')
-i2 = ResourceInclusion(foo, 'i2.js', depends=[i1])
-i3 = ResourceInclusion(foo, 'i3.js', depends=[i2])
-i4 = ResourceInclusion(foo, 'i4.js', depends=[i1])
-i5 = ResourceInclusion(foo, 'i5.js', depends=[i4, i3])'''
+i1 = Resource(foo, 'i1.js')
+i2 = Resource(foo, 'i2.js', depends=[i1])
+i3 = Resource(foo, 'i3.js', depends=[i2])
+i4 = Resource(foo, 'i4.js', depends=[i1])
+i5 = Resource(foo, 'i5.js', depends=[i4, i3])'''
 
 def test_generate_source_with_modes_and_rollup():
     foo = Library('foo', '')
-    j1 = ResourceInclusion(foo, 'j1.js', debug='j1-debug.js')
-    j2 = ResourceInclusion(foo, 'j2.js', debug='j2-debug.js')
-    giantj = ResourceInclusion(foo, 'giantj.js', supersedes=[j1, j2],
+    j1 = Resource(foo, 'j1.js', debug='j1-debug.js')
+    j2 = Resource(foo, 'j2.js', debug='j2-debug.js')
+    giantj = Resource(foo, 'giantj.js', supersedes=[j1, j2],
                                debug='giantj-debug.js')
 
     assert generate_code(j1=j1, j2=j2, giantj=giantj) == '''\
-from fanstatic import Library, ResourceInclusion
+from fanstatic import Library, Resource
 
 foo = Library('foo', '')
 
-j1 = ResourceInclusion(foo, 'j1.js', debug='j1-debug.js')
-j2 = ResourceInclusion(foo, 'j2.js', debug='j2-debug.js')
-giantj = ResourceInclusion(foo, 'giantj.js', supersedes=[j1, j2], debug='giantj-debug.js')'''
+j1 = Resource(foo, 'j1.js', debug='j1-debug.js')
+j2 = Resource(foo, 'j2.js', debug='j2-debug.js')
+giantj = Resource(foo, 'giantj.js', supersedes=[j1, j2], debug='giantj-debug.js')'''
 
 def test_generate_source_control_name():
     foo = Library('foo', '')
-    i1 = ResourceInclusion(foo, 'i1.js')
-    i2 = ResourceInclusion(foo, 'i2.js', depends=[i1])
-    i3 = ResourceInclusion(foo, 'i3.js', depends=[i2])
-    i4 = ResourceInclusion(foo, 'i4.js', depends=[i1])
-    i5 = ResourceInclusion(foo, 'i5.js', depends=[i4, i3])
+    i1 = Resource(foo, 'i1.js')
+    i2 = Resource(foo, 'i2.js', depends=[i1])
+    i3 = Resource(foo, 'i3.js', depends=[i2])
+    i4 = Resource(foo, 'i4.js', depends=[i1])
+    i5 = Resource(foo, 'i5.js', depends=[i4, i3])
 
     assert generate_code(hoi=i1) == '''\
-from fanstatic import Library, ResourceInclusion
+from fanstatic import Library, Resource
 
 foo = Library('foo', '')
 
-hoi = ResourceInclusion(foo, 'i1.js')'''
+hoi = Resource(foo, 'i1.js')'''
 
     assert generate_code(hoi=i1, i2=i2) == '''\
-from fanstatic import Library, ResourceInclusion
+from fanstatic import Library, Resource
 
 foo = Library('foo', '')
 
-hoi = ResourceInclusion(foo, 'i1.js')
-i2 = ResourceInclusion(foo, 'i2.js', depends=[hoi])'''
+hoi = Resource(foo, 'i1.js')
+i2 = Resource(foo, 'i2.js', depends=[hoi])'''

fanstatic/test_core.py

 import py
 
-from fanstatic import (Library, ResourceInclusion, NeededInclusions,
-                       GroupInclusion, NoNeededInclusions,
-                       init_current_needed_inclusions,
-                       get_current_needed_inclusions,
+from fanstatic import (Library, Resource, NeededResources,
+                       GroupResource, NoNeededResources,
+                       init_needed,
+                       get_needed,
                        inclusion_renderers,
-                       sort_inclusions_topological,
+                       sort_resources_topological,
                        UnknownResourceExtension, EXTENSIONS)
 
 
-def test_inclusion():
+def test_resource():
     foo = Library('foo', '')
-    x1 = ResourceInclusion(foo, 'a.js')
-    x2 = ResourceInclusion(foo, 'b.css')
-    y1 = ResourceInclusion(foo, 'c.js', depends=[x1, x2])
+    x1 = Resource(foo, 'a.js')
+    x2 = Resource(foo, 'b.css')
+    y1 = Resource(foo, 'c.js', depends=[x1, x2])
 
-    needed = NeededInclusions()
+    needed = NeededResources()
     needed.need(y1)
 
-    assert needed.inclusions() == [x2, x1, y1]
+    assert needed.resources() == [x2, x1, y1]
 
-def test_group_inclusion():
+def test_group_resource():
     foo = Library('foo', '')
-    x1 = ResourceInclusion(foo, 'a.js')
-    x2 = ResourceInclusion(foo, 'b.css')
-    group = GroupInclusion([x1, x2])
+    x1 = Resource(foo, 'a.js')
+    x2 = Resource(foo, 'b.css')
+    group = GroupResource([x1, x2])
 
-    needed = NeededInclusions()
+    needed = NeededResources()
     needed.need(group)
 
-    assert group.inclusions() == [x1, x2]
+    assert group.resources() == [x1, x2]
 
-    more_stuff = ResourceInclusion(foo, 'more_stuff.js', depends=[group])
-    assert more_stuff.inclusions() == [x1, x2, more_stuff]
+    more_stuff = Resource(foo, 'more_stuff.js', depends=[group])
+    assert more_stuff.resources() == [x1, x2, more_stuff]
 
 def test_convenience_need_not_initialized():
     foo = Library('foo', '')
-    x1 = ResourceInclusion(foo, 'a.js')
-    x2 = ResourceInclusion(foo, 'b.css')
-    y1 = ResourceInclusion(foo, 'c.js', depends=[x1, x2])
+    x1 = Resource(foo, 'a.js')
+    x2 = Resource(foo, 'b.css')
+    y1 = Resource(foo, 'c.js', depends=[x1, x2])
 
-    with py.test.raises(NoNeededInclusions):
+    with py.test.raises(NoNeededResources):
         y1.need()
-    with py.test.raises(NoNeededInclusions):
-        get_current_needed_inclusions()
+    with py.test.raises(NoNeededResources):
+        get_needed()
 
 def test_convenience_need():
     foo = Library('foo', '')
-    x1 = ResourceInclusion(foo, 'a.js')
-    x2 = ResourceInclusion(foo, 'b.css')
-    y1 = ResourceInclusion(foo, 'c.js', depends=[x1, x2])
+    x1 = Resource(foo, 'a.js')
+    x2 = Resource(foo, 'b.css')
+    y1 = Resource(foo, 'c.js', depends=[x1, x2])
 
-    needed = init_current_needed_inclusions()
-    assert get_current_needed_inclusions() == needed
-    assert get_current_needed_inclusions().inclusions() == []
+    needed = init_needed()
+    assert get_needed() == needed
+    assert get_needed().resources() == []
 
     y1.need()
 
-    assert get_current_needed_inclusions().inclusions() == [x2, x1, y1]
+    assert get_needed().resources() == [x2, x1, y1]
 
-def test_redundant_inclusion():
+def test_redundant_resource():
     foo = Library('foo', '')
-    x1 = ResourceInclusion(foo, 'a.js')
-    x2 = ResourceInclusion(foo, 'b.css')
-    y1 = ResourceInclusion(foo, 'c.js', depends=[x1, x2])
+    x1 = Resource(foo, 'a.js')
+    x2 = Resource(foo, 'b.css')
+    y1 = Resource(foo, 'c.js', depends=[x1, x2])
 
-    needed = NeededInclusions()
+    needed = NeededResources()
 
     needed.need(y1)
     needed.need(y1)
-    assert needed.inclusions() == [x2, x1, y1]
+    assert needed.resources() == [x2, x1, y1]
 
     needed.need(x1)
-    assert needed.inclusions() == [x2, x1, y1]
+    assert needed.resources() == [x2, x1, y1]
 
     needed.need(x2)
-    assert needed.inclusions() == [x2, x1, y1]
+    assert needed.resources() == [x2, x1, y1]
 
-def test_redundant_inclusion_reorder():
+def test_redundant_resource_reorder():
     foo = Library('foo', '')
-    x1 = ResourceInclusion(foo, 'a.js')
-    x2 = ResourceInclusion(foo, 'b.css')
-    y1 = ResourceInclusion(foo, 'c.js', depends=[x1, x2])
+    x1 = Resource(foo, 'a.js')
+    x2 = Resource(foo, 'b.css')
+    y1 = Resource(foo, 'c.js', depends=[x1, x2])
 
-    needed = NeededInclusions()
+    needed = NeededResources()
     needed.need(x1)
     needed.need(x2)
     needed.need(y1)
-    assert needed.inclusions() == [x2, x1, y1]
+    assert needed.resources() == [x2, x1, y1]
 
 def test_redundant_more_complicated():
     foo = Library('foo', '')
-    a1 = ResourceInclusion(foo, 'a1.js')
-    a2 = ResourceInclusion(foo, 'a2.js', depends=[a1])
-    a3 = ResourceInclusion(foo, 'a3.js', depends=[a2])
-    a4 = ResourceInclusion(foo, 'a4.js', depends=[a1])
+    a1 = Resource(foo, 'a1.js')
+    a2 = Resource(foo, 'a2.js', depends=[a1])
+    a3 = Resource(foo, 'a3.js', depends=[a2])
+    a4 = Resource(foo, 'a4.js', depends=[a1])
 
-    needed = NeededInclusions()
+    needed = NeededResources()
     needed.need(a3)
-    assert needed.inclusions() == [a1, a2, a3]
+    assert needed.resources() == [a1, a2, a3]
     needed.need(a4)
-    assert needed.inclusions() == [a1, a2, a3, a4]
+    assert needed.resources() == [a1, a2, a3, a4]
 
 def test_redundant_more_complicated_reversed():
     foo = Library('foo', '')
-    a1 = ResourceInclusion(foo, 'a1.js')
-    a2 = ResourceInclusion(foo, 'a2.js', depends=[a1])
-    a3 = ResourceInclusion(foo, 'a3.js', depends=[a2])
-    a4 = ResourceInclusion(foo, 'a4.js', depends=[a1])
+    a1 = Resource(foo, 'a1.js')
+    a2 = Resource(foo, 'a2.js', depends=[a1])
+    a3 = Resource(foo, 'a3.js', depends=[a2])
+    a4 = Resource(foo, 'a4.js', depends=[a1])
 
-    needed = NeededInclusions()
+    needed = NeededResources()
     needed.need(a4)
     needed.need(a3)
 
-    assert needed.inclusions() == [a1, a4, a2, a3]
+    assert needed.resources() == [a1, a4, a2, a3]
 
 def test_redundant_more_complicated_depends_on_all():
     foo = Library('foo', '')
-    a1 = ResourceInclusion(foo, 'a1.js')
-    a2 = ResourceInclusion(foo, 'a2.js', depends=[a1])
-    a3 = ResourceInclusion(foo, 'a3.js', depends=[a2])
-    a4 = ResourceInclusion(foo, 'a4.js', depends=[a1])
-    a5 = ResourceInclusion(foo, 'a5.js', depends=[a4, a3])
+    a1 = Resource(foo, 'a1.js')
+    a2 = Resource(foo, 'a2.js', depends=[a1])
+    a3 = Resource(foo, 'a3.js', depends=[a2])
+    a4 = Resource(foo, 'a4.js', depends=[a1])
+    a5 = Resource(foo, 'a5.js', depends=[a4, a3])
 
-    needed = NeededInclusions()
+    needed = NeededResources()
     needed.need(a5)
 
-    assert needed.inclusions() == [a1, a4, a2, a3, a5]
+    assert needed.resources() == [a1, a4, a2, a3, a5]
 
 def test_redundant_more_complicated_depends_on_all_reorder():
     foo = Library('foo', '')
-    a1 = ResourceInclusion(foo, 'a1.js')
-    a2 = ResourceInclusion(foo, 'a2.js', depends=[a1])
-    a3 = ResourceInclusion(foo, 'a3.js', depends=[a2])
-    a4 = ResourceInclusion(foo, 'a4.js', depends=[a1])
-    a5 = ResourceInclusion(foo, 'a5.js', depends=[a4, a3])
+    a1 = Resource(foo, 'a1.js')
+    a2 = Resource(foo, 'a2.js', depends=[a1])
+    a3 = Resource(foo, 'a3.js', depends=[a2])
+    a4 = Resource(foo, 'a4.js', depends=[a1])
+    a5 = Resource(foo, 'a5.js', depends=[a4, a3])
 
-    needed = NeededInclusions()
+    needed = NeededResources()
     needed.need(a3)
     needed.need(a5)
 
-    assert needed.inclusions() == [a1, a2, a3, a4, a5]
+    assert needed.resources() == [a1, a2, a3, a4, a5]
 
 def test_mode_fully_specified():
     foo = Library('foo', '')
-    k_debug = ResourceInclusion(foo, 'k-debug.js')
-    k = ResourceInclusion(foo, 'k.js', debug=k_debug)
+    k_debug = Resource(foo, 'k-debug.js')
+    k = Resource(foo, 'k.js', debug=k_debug)
 
-    needed = NeededInclusions()
+    needed = NeededResources()
     needed.need(k)
 
-    assert needed.inclusions() == [k]
+    assert needed.resources() == [k]
 
-    needed = NeededInclusions(mode='debug')
+    needed = NeededResources(mode='debug')
     needed.need(k)
 
-    assert needed.inclusions() == [k_debug]
+    assert needed.resources() == [k_debug]
 
-    needed = NeededInclusions
+    needed = NeededResources
 
 def test_mode_shortcut():
     foo = Library('foo', '')
-    k = ResourceInclusion(foo, 'k.js', debug='k-debug.js')
+    k = Resource(foo, 'k.js', debug='k-debug.js')
 
-    needed = NeededInclusions()
+    needed = NeededResources()
     needed.need(k)
 
-    assert needed.inclusions() == [k]
+    assert needed.resources() == [k]
 
-    needed = NeededInclusions(mode='debug')
+    needed = NeededResources(mode='debug')
     needed.need(k)
 
-    assert len(needed.inclusions()) == 1
-    assert needed.inclusions()[0].relpath == 'k-debug.js'
+    assert len(needed.resources()) == 1
+    assert needed.resources()[0].relpath == 'k-debug.js'
 
 def test_mode_unknown_default():
     foo = Library('foo', '')
-    k_debug = ResourceInclusion(foo, 'k-debug.js')
-    k = ResourceInclusion(foo, 'k.js', debug=k_debug)
+    k_debug = Resource(foo, 'k-debug.js')
+    k = Resource(foo, 'k.js', debug=k_debug)
 
-    needed = NeededInclusions(mode='default')
+    needed = NeededResources(mode='default')
     needed.need(k)
 
-    assert needed.inclusions() == [k]
+    assert needed.resources() == [k]
 
 def test_rollup():
     foo = Library('foo', '')
-    b1 = ResourceInclusion(foo, 'b1.js')
-    b2 = ResourceInclusion(foo, 'b2.js')
-    giant = ResourceInclusion(foo, 'giant.js', supersedes=[b1, b2])
+    b1 = Resource(foo, 'b1.js')
+    b2 = Resource(foo, 'b2.js')
+    giant = Resource(foo, 'giant.js', supersedes=[b1, b2])
 
-    needed = NeededInclusions(rollup=True)
+    needed = NeededResources(rollup=True)
     needed.need(b1)
     needed.need(b2)
 
-    assert needed.inclusions() == [giant]
+    assert needed.resources() == [giant]
 
 def test_rollup_cannot():
     foo = Library('foo', '')
-    b1 = ResourceInclusion(foo, 'b1.js')
-    b2 = ResourceInclusion(foo, 'b2.js')
+    b1 = Resource(foo, 'b1.js')
+    b2 = Resource(foo, 'b2.js')
 
-    giant = ResourceInclusion(foo, 'giant.js', supersedes=[b1, b2])
+    giant = Resource(foo, 'giant.js', supersedes=[b1, b2])
 
-    needed = NeededInclusions(rollup=True)
+    needed = NeededResources(rollup=True)
     needed.need(b1)
-    assert needed.inclusions() == [b1]
+    assert needed.resources() == [b1]
 
 def test_rollup_larger():
     foo = Library('foo', '')
-    c1 = ResourceInclusion(foo, 'c1.css')
-    c2 = ResourceInclusion(foo, 'c2.css')
-    c3 = ResourceInclusion(foo, 'c3.css')
-    giant = ResourceInclusion(foo, 'giant.css', supersedes=[c1, c2, c3])
+    c1 = Resource(foo, 'c1.css')
+    c2 = Resource(foo, 'c2.css')
+    c3 = Resource(foo, 'c3.css')
+    giant = Resource(foo, 'giant.css', supersedes=[c1, c2, c3])
 
-    needed = NeededInclusions(rollup=True)
+    needed = NeededResources(rollup=True)
     needed.need(c1)
 
-    assert needed.inclusions() == [c1]
+    assert needed.resources() == [c1]
 
     needed.need(c2)
 
-    assert needed.inclusions() == [c1, c2]
+    assert needed.resources() == [c1, c2]
 
     needed.need(c3)
 
-    assert needed.inclusions() == [giant]
+    assert needed.resources() == [giant]
 
 def test_rollup_eager():
     foo = Library('foo', '')
-    d1 = ResourceInclusion(foo, 'd1.js')
-    d2 = ResourceInclusion(foo, 'd2.js')
-    d3 = ResourceInclusion(foo, 'd3.js')
-    giant = ResourceInclusion(foo, 'giant.js', supersedes=[d1, d2, d3],
-                              eager_superseder=True)
+    d1 = Resource(foo, 'd1.js')
+    d2 = Resource(foo, 'd2.js')
+    d3 = Resource(foo, 'd3.js')
+    giant = Resource(foo, 'giant.js', supersedes=[d1, d2, d3],
+                     eager_superseder=True)
 
-    needed = NeededInclusions(rollup=True)
+    needed = NeededResources(rollup=True)
     needed.need(d1)
-    assert needed.inclusions() == [giant]
+    assert needed.resources() == [giant]
 
-    needed = NeededInclusions(rollup=True)
+    needed = NeededResources(rollup=True)
     needed.need(d1)
     needed.need(d2)
-    assert needed.inclusions() == [giant]
+    assert needed.resources() == [giant]
 
 def test_rollup_eager_competing():
     foo = Library('foo', '')
-    d1 = ResourceInclusion(foo, 'd1.js')
-    d2 = ResourceInclusion(foo, 'd2.js')
-    d3 = ResourceInclusion(foo, 'd3.js')
-    d4 = ResourceInclusion(foo, 'd4.js')
-    giant = ResourceInclusion(foo, 'giant.js', supersedes=[d1, d2, d3],
-                              eager_superseder=True)
-    giant_bigger = ResourceInclusion(foo, 'giant-bigger.js',
-                                     supersedes=[d1, d2, d3, d4],
-                                     eager_superseder=True)
-
-    needed = NeededInclusions(rollup=True)
+    d1 = Resource(foo, 'd1.js')
+    d2 = Resource(foo, 'd2.js')
+    d3 = Resource(foo, 'd3.js')
+    d4 = Resource(foo, 'd4.js')
+    giant = Resource(foo, 'giant.js', supersedes=[d1, d2, d3],
+                     eager_superseder=True)
+    giant_bigger = Resource(foo, 'giant-bigger.js',
+                            supersedes=[d1, d2, d3, d4],
+                            eager_superseder=True)
+    
+    needed = NeededResources(rollup=True)
     needed.need(d1)
-    assert needed.inclusions() == [giant_bigger]
+    assert needed.resources() == [giant_bigger]
 
 def test_rollup_eager_noneager_competing():
     foo = Library('foo', '')
-    d1 = ResourceInclusion(foo, 'd1.js')
-    d2 = ResourceInclusion(foo, 'd2.js')
-    d3 = ResourceInclusion(foo, 'd3.js')
-    giant = ResourceInclusion(foo, 'giant.js', supersedes=[d1, d2, d3],
-                              eager_superseder=True)
-    giant_noneager = ResourceInclusion(foo, 'giant-noneager.js',
-                                       supersedes=[d1, d2, d3])
-    needed = NeededInclusions(rollup=True)
+    d1 = Resource(foo, 'd1.js')
+    d2 = Resource(foo, 'd2.js')
+    d3 = Resource(foo, 'd3.js')
+    giant = Resource(foo, 'giant.js', supersedes=[d1, d2, d3],
+                     eager_superseder=True)
+    giant_noneager = Resource(foo, 'giant-noneager.js',
+                              supersedes=[d1, d2, d3])
+    needed = NeededResources(rollup=True)
     needed.need(d1)
-    assert needed.inclusions() == [giant]
+    assert needed.resources() == [giant]
 
 def test_rollup_size_competing():
     foo = Library('foo', '')
-    d1 = ResourceInclusion(foo, 'd1.js')
-    d2 = ResourceInclusion(foo, 'd2.js')
-    d3 = ResourceInclusion(foo, 'd3.js')
-    giant = ResourceInclusion(foo, 'giant.js', supersedes=[d1, d2])
-    giant_bigger = ResourceInclusion(foo, 'giant-bigger.js',
-                                     supersedes=[d1, d2, d3])
-
-    needed = NeededInclusions(rollup=True)
+    d1 = Resource(foo, 'd1.js')
+    d2 = Resource(foo, 'd2.js')
+    d3 = Resource(foo, 'd3.js')
+    giant = Resource(foo, 'giant.js', supersedes=[d1, d2])
+    giant_bigger = Resource(foo, 'giant-bigger.js',
+                            supersedes=[d1, d2, d3])
+    
+    needed = NeededResources(rollup=True)
     needed.need(d1)
     needed.need(d2)
     needed.need(d3)
-    assert needed.inclusions() == [giant_bigger]
+    assert needed.resources() == [giant_bigger]
 
 def test_rollup_eager_noneager_size_competing():
     foo = Library('foo', '')
-    d1 = ResourceInclusion(foo, 'd1.js')
-    d2 = ResourceInclusion(foo, 'd2.js')
-    d3 = ResourceInclusion(foo, 'd3.js')
-    d4 = ResourceInclusion(foo, 'd4.js')
-    giant = ResourceInclusion(foo, 'giant.js', supersedes=[d1, d2, d3],
-                              eager_superseder=True)
-    giant_noneager_bigger = ResourceInclusion(foo, 'giant-noneager.js',
-                                              supersedes=[d1, d2, d3, d4])
-    needed = NeededInclusions(rollup=True)
+    d1 = Resource(foo, 'd1.js')
+    d2 = Resource(foo, 'd2.js')
+    d3 = Resource(foo, 'd3.js')
+    d4 = Resource(foo, 'd4.js')
+    giant = Resource(foo, 'giant.js', supersedes=[d1, d2, d3],
+                     eager_superseder=True)
+    giant_noneager_bigger = Resource(foo, 'giant-noneager.js',
+                                     supersedes=[d1, d2, d3, d4])
+    needed = NeededResources(rollup=True)
     needed.need(d1)
-    assert needed.inclusions() == [giant]
+    assert needed.resources() == [giant]
 
 def test_rollup_modes():
     foo = Library('foo', '')
-    f1 = ResourceInclusion(foo, 'f1.js', debug='f1-debug.js')
-    f2 = ResourceInclusion(foo, 'f2.js', debug='f2-debug.js')
-    giantf = ResourceInclusion(foo, 'giantf.js', supersedes=[f1, f2],
-                               debug='giantf-debug.js')
+    f1 = Resource(foo, 'f1.js', debug='f1-debug.js')
+    f2 = Resource(foo, 'f2.js', debug='f2-debug.js')
+    giantf = Resource(foo, 'giantf.js', supersedes=[f1, f2],
+                      debug='giantf-debug.js')
 
-    needed = NeededInclusions(rollup=True)
+    needed = NeededResources(rollup=True)
     needed.need(f1)
     needed.need(f2)
-    assert needed.inclusions() == [giantf]
+    assert needed.resources() == [giantf]
 
-    needed = NeededInclusions(rollup=True, mode='debug')
+    needed = NeededResources(rollup=True, mode='debug')
     needed.need(f1)
     needed.need(f2)
-    assert len(needed.inclusions()) == 1
-    assert needed.inclusions()[0].relpath == 'giantf-debug.js'
+    assert len(needed.resources()) == 1
+    assert needed.resources()[0].relpath == 'giantf-debug.js'
 
 def test_rollup_meaningless_rollup_mode():
     foo = Library('foo', '')
-    g1 = ResourceInclusion(foo, 'g1.js')
-    g2 = ResourceInclusion(foo, 'g2.js')
-    giantg = ResourceInclusion(foo, 'giantg.js', supersedes=[g1, g2],
-                               debug='giantg-debug.js')
-    needed = NeededInclusions(rollup=True)
+    g1 = Resource(foo, 'g1.js')
+    g2 = Resource(foo, 'g2.js')
+    giantg = Resource(foo, 'giantg.js', supersedes=[g1, g2],
+                      debug='giantg-debug.js')
+    needed = NeededResources(rollup=True)
     needed.need(g1)
     needed.need(g2)
-    assert needed.inclusions() == [giantg]
+    assert needed.resources() == [giantg]
 
-    needed = NeededInclusions(rollup=True, mode='debug')
+    needed = NeededResources(rollup=True, mode='debug')
     needed.need(g1)
     needed.need(g2)
-    assert needed.inclusions() == [giantg]
+    assert needed.resources() == [giantg]
 
 def test_rollup_without_mode():
     foo = Library('foo', '')
-    h1 = ResourceInclusion(foo, 'h1.js', debug='h1-debug.js')
-    h2 = ResourceInclusion(foo, 'h2.js', debug='h2-debug.js')
-    gianth = ResourceInclusion(foo, 'gianth.js', supersedes=[h1, h2])
+    h1 = Resource(foo, 'h1.js', debug='h1-debug.js')
+    h2 = Resource(foo, 'h2.js', debug='h2-debug.js')
+    gianth = Resource(foo, 'gianth.js', supersedes=[h1, h2])
 
-    needed = NeededInclusions(rollup=True)
+    needed = NeededResources(rollup=True)
     needed.need(h1)
     needed.need(h2)
-    assert needed.inclusions() == [gianth]
+    assert needed.resources() == [gianth]
 
-    needed = NeededInclusions(rollup=True, mode='debug')
+    needed = NeededResources(rollup=True, mode='debug')
     needed.need(h1)
     needed.need(h2)
     # no mode available for rollup
-    assert len(needed.inclusions()) == 2
-    assert needed.inclusions()[0].relpath == 'h1-debug.js'
-    assert needed.inclusions()[1].relpath == 'h2-debug.js'
+    assert len(needed.resources()) == 2
+    assert needed.resources()[0].relpath == 'h1-debug.js'
+    assert needed.resources()[1].relpath == 'h2-debug.js'
 
 def test_rendering():
     foo = Library('foo', '')
-    x1 = ResourceInclusion(foo, 'a.js')
-    x2 = ResourceInclusion(foo, 'b.css')
-    y1 = ResourceInclusion(foo, 'c.js', depends=[x1, x2])
+    x1 = Resource(foo, 'a.js')
+    x2 = Resource(foo, 'b.css')
+    y1 = Resource(foo, 'c.js', depends=[x1, x2])
 
-    needed = NeededInclusions()
+    needed = NeededResources()
     needed.need(y1)
 
     assert needed.render() == '''\
 
 def test_rendering_base_url():
     foo = Library('foo', '')
-    x1 = ResourceInclusion(foo, 'a.js')
-    x2 = ResourceInclusion(foo, 'b.css')
-    y1 = ResourceInclusion(foo, 'c.js', depends=[x1, x2])
+    x1 = Resource(foo, 'a.js')
+    x2 = Resource(foo, 'b.css')
+    y1 = Resource(foo, 'c.js', depends=[x1, x2])
 
-    needed = NeededInclusions(base_url='http://localhost/static')
+    needed = NeededResources(base_url='http://localhost/static')
     needed.need(y1)
 
     assert needed.render() == '''\
     ''' When the base_url and publisher_signature are both empty strings,
     render a URL without them. '''
     foo = Library('foo', '')
-    x1 = ResourceInclusion(foo, 'a.js')
-    needed = NeededInclusions(base_url='', publisher_signature='')
+    x1 = Resource(foo, 'a.js')
+    needed = NeededResources(base_url='', publisher_signature='')
     needed.need(x1)
 
     assert needed.render() == '''\
 
 def test_rendering_base_url_assign():
     foo = Library('foo', '')
-    x1 = ResourceInclusion(foo, 'a.js')
-    x2 = ResourceInclusion(foo, 'b.css')
-    y1 = ResourceInclusion(foo, 'c.js', depends=[x1, x2])
+    x1 = Resource(foo, 'a.js')
+    x2 = Resource(foo, 'b.css')
+    y1 = Resource(foo, 'c.js', depends=[x1, x2])
 
-    needed = NeededInclusions()
+    needed = NeededResources()
     needed.need(y1)
 
     needed.base_url = 'http://localhost/static'
 def test_library_url_default_publisher_signature():
     foo = Library('foo', '')
 
-    needed = NeededInclusions()
+    needed = NeededResources()
 
     assert needed.library_url(foo) == '/fanstatic/foo'
 
 def test_library_url_publisher_signature():
     foo = Library('foo', '')
 
-    needed = NeededInclusions(publisher_signature='waku')
+    needed = NeededResources(publisher_signature='waku')
 
     assert needed.library_url(foo) == '/waku/foo'
 
 def test_library_url_base_url():
     foo = Library('foo', '')
 
-    needed = NeededInclusions(base_url="http://example.com/something")
+    needed = NeededResources(base_url="http://example.com/something")
 
     assert (needed.library_url(foo) ==
             'http://example.com/something/fanstatic/foo')
 def test_library_url_hashing(tmpdir):
     foo = Library('foo', tmpdir.strpath)
 
-    needed = NeededInclusions(hashing=True)
+    needed = NeededResources(hashing=True)
 
     assert (needed.library_url(foo) ==
             '/fanstatic/foo/:hash:d41d8cd98f00b204e9800998ecf8427e')
 def test_library_url_hashing_nodevmode(tmpdir):
     foo = Library('foo', tmpdir.strpath)
 
-    needed = NeededInclusions(hashing=True)
+    needed = NeededResources(hashing=True)
 
     url = needed.library_url(foo)
 
 def test_library_url_hashing_devmode(tmpdir):
     foo = Library('foo', tmpdir.strpath)
 
-    needed = NeededInclusions(hashing=True, devmode=True)
+    needed = NeededResources(hashing=True, devmode=True)
 
     url = needed.library_url(foo)
 
 
 def test_html_insert():
     foo = Library('foo', '')
-    x1 = ResourceInclusion(foo, 'a.js')
-    x2 = ResourceInclusion(foo, 'b.css')
-    y1 = ResourceInclusion(foo, 'c.js', depends=[x1, x2])
+    x1 = Resource(foo, 'a.js')
+    x2 = Resource(foo, 'b.css')
+    y1 = Resource(foo, 'c.js', depends=[x1, x2])
 
-    needed = NeededInclusions()
+    needed = NeededResources()
     needed.need(y1)
 
     html = "<html><head>something more</head></html>"
 
 def test_html_top_bottom():
     foo = Library('foo', '')
-    x1 = ResourceInclusion(foo, 'a.js')
-    x2 = ResourceInclusion(foo, 'b.css')
-    y1 = ResourceInclusion(foo, 'c.js', depends=[x1, x2])
+    x1 = Resource(foo, 'a.js')
+    x2 = Resource(foo, 'b.css')
+    y1 = Resource(foo, 'c.js', depends=[x1, x2])
 
-    needed = NeededInclusions()
+    needed = NeededResources()
     needed.need(y1)
 
     top, bottom = needed.render_topbottom()
 
 def test_html_top_bottom_set_bottom():
     foo = Library('foo', '')
-    x1 = ResourceInclusion(foo, 'a.js')
-    x2 = ResourceInclusion(foo, 'b.css')
-    y1 = ResourceInclusion(foo, 'c.js', depends=[x1, x2])
+    x1 = Resource(foo, 'a.js')
+    x2 = Resource(foo, 'b.css')
+    y1 = Resource(foo, 'c.js', depends=[x1, x2])
 
-    needed = NeededInclusions(bottom=True)
+    needed = NeededResources(bottom=True)
     needed.need(y1)
 
     top, bottom = needed.render_topbottom()
 
 def test_html_top_bottom_force_bottom():
     foo = Library('foo', '')
-    x1 = ResourceInclusion(foo, 'a.js')
-    x2 = ResourceInclusion(foo, 'b.css')
-    y1 = ResourceInclusion(foo, 'c.js', depends=[x1, x2])
+    x1 = Resource(foo, 'a.js')
+    x2 = Resource(foo, 'b.css')
+    y1 = Resource(foo, 'c.js', depends=[x1, x2])
 
-    needed = NeededInclusions(bottom=True, force_bottom=True)
+    needed = NeededResources(bottom=True, force_bottom=True)
     needed.need(y1)
 
     top, bottom = needed.render_topbottom()
 
 def test_html_bottom_safe():
     foo = Library('foo', '')
-    x1 = ResourceInclusion(foo, 'a.js')
-    x2 = ResourceInclusion(foo, 'b.css')
-    y1 = ResourceInclusion(foo, 'c.js', depends=[x1, x2])
-    y2 = ResourceInclusion(foo, 'y2.js', bottom=True)
+    x1 = Resource(foo, 'a.js')
+    x2 = Resource(foo, 'b.css')
+    y1 = Resource(foo, 'c.js', depends=[x1, x2])
+    y2 = Resource(foo, 'y2.js', bottom=True)
 
-    needed = NeededInclusions()
+    needed = NeededResources()
     needed.need(y1)
     needed.need(y2)
     top, bottom = needed.render_topbottom()
 <script type="text/javascript" src="/fanstatic/foo/y2.js"></script>'''
     assert bottom == ''
 
-    needed = NeededInclusions(bottom=True)
+    needed = NeededResources(bottom=True)
     needed.need(y1)
     needed.need(y2)
     top, bottom = needed.render_topbottom()
     assert bottom == '''\
 <script type="text/javascript" src="/fanstatic/foo/y2.js"></script>'''
 
-    needed = NeededInclusions(bottom=True, force_bottom=True)
+    needed = NeededResources(bottom=True, force_bottom=True)
     needed.need(y1)
     needed.need(y2)
     top, bottom = needed.render_topbottom()
 
 def test_top_bottom_insert():
     foo = Library('foo', '')
-    x1 = ResourceInclusion(foo, 'a.js')
-    x2 = ResourceInclusion(foo, 'b.css')
-    y1 = ResourceInclusion(foo, 'c.js', depends=[x1, x2])
+    x1 = Resource(foo, 'a.js')
+    x2 = Resource(foo, 'b.css')
+    y1 = Resource(foo, 'c.js', depends=[x1, x2])
 
     html = "<html><head>rest of head</head><body>rest of body</body></html>"
 
-    needed = NeededInclusions(bottom=True, force_bottom=True)
+    needed = NeededResources(bottom=True, force_bottom=True)
     needed.need(y1)
     assert needed.render_topbottom_into_html(html) == '''\
 <html><head>
 rest of head</head><body>rest of body<script type="text/javascript" src="/fanstatic/foo/a.js"></script>
 <script type="text/javascript" src="/fanstatic/foo/c.js"></script></body></html>'''
 
-def test_sorting_inclusions():
+def test_sorting_resources():
     foo = Library('foo', '')
 
-    a1 = ResourceInclusion(foo, 'a1.js')
-    a2 = ResourceInclusion(foo, 'a2.js', depends=[a1])
-    a3 = ResourceInclusion(foo, 'a3.js', depends=[a2])
-    a4 = ResourceInclusion(foo, 'a4.js', depends=[a1])
-    a5 = ResourceInclusion(foo, 'a5.js', depends=[a4, a3])
+    a1 = Resource(foo, 'a1.js')
+    a2 = Resource(foo, 'a2.js', depends=[a1])
+    a3 = Resource(foo, 'a3.js', depends=[a2])
+    a4 = Resource(foo, 'a4.js', depends=[a1])
+    a5 = Resource(foo, 'a5.js', depends=[a4, a3])
 
-    assert sort_inclusions_topological([a5, a3, a1, a2, a4]) == [
+    assert sort_resources_topological([a5, a3, a1, a2, a4]) == [
         a1, a4, a2, a3, a5]
 
 def test_inclusion_renderers():
 # XXX whole EXTENSIONS business is weird
 def test_add_inclusion_renderer():
     foo = Library('foo', '')
-    a = ResourceInclusion(foo, 'nothing.unknown')
+    a = Resource(foo, 'nothing.unknown')
     # XXX hack
     EXTENSIONS.append('.unknown')
 
-    needed = NeededInclusions()
+    needed = NeededResources()
     needed.need(a)
     with py.test.raises(UnknownResourceExtension):
         needed.render()
 
 # XXX better error reporting if unknown extensions are used
 
-# XXX test for library defined in full package; do we really want to
-# depend on buildout and incur the performance penalty or shall we
-# simply ignore this issue?
 
-

fanstatic/test_injector.py

 
 import webob
 
-from fanstatic import (Library, ResourceInclusion,
-                       get_current_needed_inclusions)
+from fanstatic import (Library, Resource,
+                       get_needed)
 from fanstatic import Injector
 
 def test_incorrect_configuration_options():
     with py.test.raises(TypeError) as e:
         Injector(app, incorrect='configoption')
     assert (
-        "NeededInclusions got an unexpected "
+        "NeededResources got an unexpected "
         "keyword argument 'incorrect'") in str(e)
 
     with py.test.raises(TypeError) as e:
         Injector(app, mode='qux', incorrect='configoption')
     assert (
-        "NeededInclusions got an unexpected "
+        "NeededResources got an unexpected "
         "keyword argument 'incorrect'") in str(e)
 
     with py.test.raises(TypeError) as e:
         Injector(app, mode='qux', incorrect='configoption', devmode=True)
     assert (
-        "NeededInclusions got an unexpected "
+        "NeededResources got an unexpected "
         "keyword argument 'incorrect'") in str(e)
 
 def test_inject():
     foo = Library('foo', '')
-    x1 = ResourceInclusion(foo, 'a.js')
-    x2 = ResourceInclusion(foo, 'b.css')
-    y1 = ResourceInclusion(foo, 'c.js', depends=[x1, x2])
+    x1 = Resource(foo, 'a.js')
+    x2 = Resource(foo, 'b.css')
+    y1 = Resource(foo, 'c.js', depends=[x1, x2])
 
     def app(environ, start_response):
         start_response('200 OK', [])
-        needed = get_current_needed_inclusions()
+        needed = get_needed()
         needed.need(y1)
         needed.base_url = 'http://testapp'
         return ['<html><head></head><body</body></html>']
 
 def test_no_inject_into_non_html():
     foo = Library('foo', '')
-    x1 = ResourceInclusion(foo, 'a.js')
-    x2 = ResourceInclusion(foo, 'b.css')
-    y1 = ResourceInclusion(foo, 'c.js', depends=[x1, x2])
+    x1 = Resource(foo, 'a.js')
+    x2 = Resource(foo, 'b.css')
+    y1 = Resource(foo, 'c.js', depends=[x1, x2])
 
     def app(environ, start_response):
         start_response('200 OK', [('Content-Type', 'text/plain')])
-        needed = get_current_needed_inclusions()
+        needed = get_needed()
         needed.need(y1)
         needed.base_url = 'http://testapp'
         return ['<html><head></head><body</body></html>']
     response = request.get_response(wrapped_app)
     assert response.body == '<html><head></head><body</body></html>'
 
-def test_hash_inject():
-    # XXX
-    pass
-

fanstatic/test_wsgi.py

 
 import webob
 
-from fanstatic import (Library, ResourceInclusion,
-                       get_current_needed_inclusions)
+from fanstatic import (Library, Resource,
+                       get_needed)
 
 from fanstatic import Fanstatic
 
 def test_inject():
     foo = Library('foo', '')
-    x1 = ResourceInclusion(foo, 'a.js')
-    x2 = ResourceInclusion(foo, 'b.css')
-    y1 = ResourceInclusion(foo, 'c.js', depends=[x1, x2])
+    x1 = Resource(foo, 'a.js')
+    x2 = Resource(foo, 'b.css')
+    y1 = Resource(foo, 'c.js', depends=[x1, x2])
 
     def app(environ, start_response):
         start_response('200 OK', [])
-        needed = get_current_needed_inclusions()
+        needed = get_needed()
         needed.need(y1)
         needed.base_url = 'http://testapp'
         return ['<html><head></head><body</body></html>']
     with py.test.raises(TypeError) as e:
         Fanstatic(app, incorrect='configoption')
     assert (
-        "NeededInclusions got an unexpected "
+        "NeededResources got an unexpected "
         "keyword argument 'incorrect'") in str(e)

fanstatic/testdata/MyPackage/src/mypackage/__init__.py

-from fanstatic import Library, ResourceInclusion
+from fanstatic import Library, Resource
 
 foo = Library('foo', 'resources')
 
-style = ResourceInclusion(foo, 'style.css')
+style = Resource(foo, 'style.css')

fixtures/MyPackage/src/mypackage/__init__.py

-from fanstatic import Library, ResourceInclusion
+from fanstatic import Library, Resource
 
 foo = Library('foo', 'resources')
 
-style = ResourceInclusion(foo, 'style.css')
+style = Resource(foo, 'style.css')