[Checkins] SVN: hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/ URL generation in a saner place now.
Martijn Faassen
faassen at startifact.com
Tue Nov 23 11:14:07 EST 2010
Log message for revision 118536:
URL generation in a saner place now.
Changed:
U hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/README.txt
U hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/core.py
U hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/tests.py
-=-
Modified: hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/README.txt
===================================================================
--- hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/README.txt 2010-11-23 14:52:41 UTC (rev 118535)
+++ hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/README.txt 2010-11-23 16:14:07 UTC (rev 118536)
@@ -1231,9 +1231,13 @@
Let's create an inclusion of unknown resource:
>>> a6 = ResourceInclusion(foo, 'nothing.unknown')
+ >>> from hurry.resource.core import EXTENSIONS
+ >>> EXTENSIONS.append('.unknown')
- >>> from hurry.resource.core import render_inclusions
- >>> render_inclusions([a6], '/')
+ >>> needed = NeededInclusions()
+ >>> needed.base_url = 'http://localhost/static/'
+ >>> needed.need(a6)
+ >>> needed.render()
Traceback (most recent call last):
...
UnknownResourceExtension: Unknown resource extension .unknown for resource
@@ -1245,11 +1249,9 @@
>>> def render_unknown(url):
... return '<link rel="unknown" href="%s" />' % url
>>> inclusion_renderers['.unknown'] = render_unknown
-
- >>> render_inclusions([a6], 'http://localhost/static/')
+ >>> needed.render()
'<link rel="unknown" href="http://localhost/static/:hash:.../foo/nothing.unknown" />'
-
Resource publisher
==================
Modified: hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/core.py
===================================================================
--- hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/core.py 2010-11-23 14:52:41 UTC (rev 118535)
+++ hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/core.py 2010-11-23 16:14:07 UTC (rev 118536)
@@ -26,9 +26,6 @@
self._signature = hurry.resource.hash.checksum(self.path)
return hurry.resource.publisher_signature + str(self._signature)
- def url(self, base_url):
- return '%s%s/%s/' % (base_url, self.signature(), self.name)
-
# total hack to be able to get the dir the resources will be in
def caller_dir():
return os.path.dirname(sys._getframe(2).f_globals['__file__'])
@@ -224,9 +221,29 @@
return inclusions
+ def library_url(self, library):
+ return '%s%s/%s/' % (self.base_url, library.signature(), library.name)
+
def render(self):
- return render_inclusions(self.inclusions(), self.base_url)
+ """Render a set of inclusions.
+ """
+ return self.render_inclusions(self.inclusions())
+ def render_inclusions(self, inclusions):
+ result = []
+ if not self.base_url.endswith('/'):
+ self.base_url += '/'
+ url_cache = {} # prevent multiple computations for a library in one request
+ for inclusion in inclusions:
+ library = inclusion.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, library_url + inclusion.relpath))
+ return '\n'.join(result)
+
def render_into_html(self, html):
to_insert = self.render()
return html.replace('<head>', '<head>\n %s\n' % to_insert, 1)
@@ -254,8 +271,8 @@
top_inclusions = inclusions
bottom_inclusions = []
- return (render_inclusions(top_inclusions, self.base_url),
- render_inclusions(bottom_inclusions, self.base_url))
+ return (self.render_inclusions(top_inclusions),
+ self.render_inclusions(bottom_inclusions))
def render_topbottom_into_html(self, html):
top, bottom = self.render_topbottom()
@@ -416,26 +433,6 @@
'.js': render_js,
}
-def render_inclusions(inclusions, base_url):
- """Render a set of inclusions.
-
- inclusions - the inclusions to render
- base_url - the base url for resource inclusions.
- """
- result = []
- if not base_url.endswith('/'):
- base_url += '/'
-
- url_cache = {} # prevent multiple computations for a library in one request
- for inclusion in inclusions:
- library = inclusion.library
- library_url = url_cache.get(library.name)
- if library_url is None:
- library_url = url_cache[library.name] = library.url(base_url)
- result.append(
- render_inclusion(inclusion, library_url + inclusion.relpath))
- return '\n'.join(result)
-
def render_inclusion(inclusion, url):
renderer = inclusion_renderers.get(inclusion.ext(), None)
if renderer is None:
Modified: hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/tests.py
===================================================================
--- hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/tests.py 2010-11-23 14:52:41 UTC (rev 118535)
+++ hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/tests.py 2010-11-23 16:14:07 UTC (rev 118536)
@@ -9,6 +9,7 @@
from zc.buildout.easy_install import install
from zc.buildout import testing
+from hurry import resource
@contextmanager
def pwd(directory):
@@ -45,10 +46,24 @@
testing.remove(test.target_dir)
+class ConfigTests(unittest.TestCase):
+ pass
+
+ # def test_library_url(self):
+ # library = resource.Library('foo', '')
+ # inclusion = resource.ResourceInclusion(library, 'bar.js')
+ # needed = resource.NeededInclusions()
+ # needed.base_url = 'http://localhost/static'
+ # print needed.library_url(library)
+ # self.assertEquals('http://localhost/static:hash:2797572843/foo/',
+ # needed.library_url(library))
+
def test_suite():
+ suite = unittest.makeSuite(ConfigTests)
readme = doctest.DocFileSuite(
'README.txt',
setUp=setUp,
tearDown=tearDown,
optionflags=doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS)
- return unittest.TestSuite([readme])
+ suite.addTest(readme)
+ return suite
More information about the checkins
mailing list