[Checkins] SVN: hurry.resource/trunk/src/hurry/resource/ Modify this so we can specify the name for ResourceInclusions that are
Martijn Faassen
faassen at infrae.com
Wed Sep 24 15:04:51 EDT 2008
Log message for revision 91447:
Modify this so we can specify the name for ResourceInclusions that are
generated.
Changed:
U hurry.resource/trunk/src/hurry/resource/README.txt
U hurry.resource/trunk/src/hurry/resource/core.py
-=-
Modified: hurry.resource/trunk/src/hurry/resource/README.txt
===================================================================
--- hurry.resource/trunk/src/hurry/resource/README.txt 2008-09-24 16:50:15 UTC (rev 91446)
+++ hurry.resource/trunk/src/hurry/resource/README.txt 2008-09-24 19:04:50 UTC (rev 91447)
@@ -457,10 +457,10 @@
Sometimes it is useful to generate code that expresses a complex
resource dependency structure. One example of that is in
-``hurry.yui``. We can use this to render a list of resources::
+``hurry.yui``. We can use this to render resource inclusions::
>>> from hurry.resource import generate_code
- >>> print generate_code([a1, a2, a3, a4, a5])
+ >>> print generate_code(a1=a1, a2=a2, a3=a3, a4=a4, a5=a5)
from hurry.resource import Library, ResourceInclusion
<BLANKLINE>
foo = Library('foo')
@@ -473,7 +473,7 @@
Let's look at an example with modes and rollups::
- >>> print generate_code([b4, b5])
+ >>> print generate_code(b4=b4, b5=b5)
from hurry.resource import Library, ResourceInclusion
<BLANKLINE>
foo = Library('foo')
@@ -481,6 +481,16 @@
b4 = ResourceInclusion(foo, 'b4.js', rollups=['giant.js'], debug=ResourceInclusion(foo, 'b4-debug.js', rollups=['giant-debug.js']))
b5 = ResourceInclusion(foo, 'b5.js', rollups=['giant.js'], debug=ResourceInclusion(foo, 'b5-debug.js', rollups=['giant-debug.js']))
+We can control the name the inclusion will get in the source code by
+using keyword parameters::
+
+ >>> print generate_code(hoi=a1)
+ from hurry.resource import Library, ResourceInclusion
+ <BLANKLINE>
+ foo = Library('foo')
+ <BLANKLINE>
+ hoi = ResourceInclusion(foo, 'a1.js')
+
Sorting inclusions by dependency
--------------------------------
Modified: hurry.resource/trunk/src/hurry/resource/core.py
===================================================================
--- hurry.resource/trunk/src/hurry/resource/core.py 2008-09-24 16:50:15 UTC (rev 91446)
+++ hurry.resource/trunk/src/hurry/resource/core.py 2008-09-24 19:04:50 UTC (rev 91447)
@@ -234,7 +234,14 @@
(inclusion.ext(), repr(inclusion)))
return renderer(url)
-def generate_code(inclusions):
+def generate_code(**kw):
+ name_to_inclusion = kw
+ inclusion_to_name = {}
+ inclusions = []
+ for name, inclusion in kw.items():
+ inclusion_to_name[inclusion.key()] = name
+ inclusions.append(inclusion)
+
# libraries with the same name are the same libraries
libraries = {}
for inclusion in inclusions:
@@ -250,15 +257,10 @@
result.append("%s = Library('%s')" % (library.name, library.name))
result.append("")
- # figure out inclusion names, try to base on filename
- used_names = set()
- inclusion_to_name = {}
+ # sort inclusions in the order we want them to be
inclusions = sort_inclusions_by_extension(
sort_inclusions_topological(inclusions))
- for inclusion in inclusions:
- name = generate_inclusion_name(inclusion, used_names)
- inclusion_to_name[inclusion.key()] = name
-
+
# now generate inclusion code
for inclusion in inclusions:
s = "%s = ResourceInclusion(%s, '%s'" % (
More information about the Checkins
mailing list