Commits

Christian Zagrodnick committed 4eb5268

- Added slots argument to Group.need().

Comments (0)

Files changed (3)

 - Resource.need() did not process the slots argument, despite the argument
   being documented.
 
+- Added slots argument to Group.need().
+
 
 0.12 (2012-08-05)
 =================

fanstatic/core.py

         for depend in self.depends:
             self.resources.update(depend.resources)
 
-    def need(self):
+    def need(self, slots=None):
         """Need this group resource.
 
         If you call ``.need()`` on ``Group`` sometime
         during the rendering process of your web page, all dependencies
         of this group resources will be inserted into the web page.
+
+        :param slots: an optional dictionary mapping from
+          :py:class:`Slot` instances to :py:class:`Resource`
+          instances. This dictionary describes how to fill in the
+          slots that this resource might depend on (directly or
+          indirectly). If a slot is required, the dictionary must
+          contain an entry for it.
         """
         needed = get_needed()
-        needed.need(self)
+        needed.need(self, slots)
 
 # backwards compatibility alias
 GroupResource = Group

fanstatic/test_slot.py

     finally:
         fanstatic.del_needed()
     assert slot in needed._slots
+
+
+def test_group_need_should_pass_slots_to_needed():
+    import fanstatic
+    lib = Library('lib', '')
+    c = Resource(lib, 'c.js')
+    slot = Slot(lib, '.js', depends=[c])
+    a = Resource(lib, 'a.js', depends=[slot])
+    b = Resource(lib, 'b.js', depends=[c])
+    g = fanstatic.Group([a, b])
+    needed = fanstatic.init_needed()
+    try:
+        g.need({slot: c})
+    finally:
+        fanstatic.del_needed()
+    assert slot in needed._slots
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.