Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7931)

Unified Diff: chrome/common/extensions/docs/server2/template_data_source.py

Issue 10545043: Extensions docs server: Design changes, partial template support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/template_data_source.py
diff --git a/chrome/common/extensions/docs/server2/template_data_source.py b/chrome/common/extensions/docs/server2/template_data_source.py
new file mode 100644
index 0000000000000000000000000000000000000000..532a62bfdb038c39ebc1f9d0a6dbfe192bbaa057
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/template_data_source.py
@@ -0,0 +1,43 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import logging
+import os
+import time
+
+from third_party.handlebar import Handlebar
+
+class TemplateDataSource(object):
not at google - send to devlin 2012/06/07 04:43:57 I was thinking, should be build all the template r
cduvall 2012/06/08 00:39:23 Done.
+ def __init__(self, fetcher, base_paths, cache_timeout):
not at google - send to devlin 2012/06/07 04:43:57 cache_timeout_seconds
cduvall 2012/06/08 00:39:23 Done.
+ logging.info('Template data source created.')
not at google - send to devlin 2012/06/07 04:43:57 It's ok if you want to leave logging in for now (t
cduvall 2012/06/08 00:39:23 Done.
+ self._fetcher = fetcher
+ self._template_cache = {}
+ self._base_paths = base_paths
+ self._cache_timeout = cache_timeout
+
+ def __getitem__(self, key):
+ return self.get(key)
+
+ def get(self, key):
+ index = key.rfind('.html')
+ if index > 0:
+ key = key[:index]
+ path = key + '.html'
+ if key in self._template_cache:
+ compiled_template, compile_time = self._template_cache[key]
+ if (time.time() - compile_time) > self._cache_timeout:
+ self._template_cache.pop(key)
+ if key not in self._template_cache:
+ logging.info('Template cache miss for: ' + path)
+ compiled_template = None
+ for base_path in self._base_paths:
+ try:
+ template = self._fetcher.FetchResource(base_path + path).content
+ compiled_template = Handlebar(template)
+ self._template_cache[key] = (compiled_template, time.time())
not at google - send to devlin 2012/06/07 04:43:57 Consider making the cache entries actual objects t
cduvall 2012/06/08 00:39:23 Done.
+ break
+ except:
+ pass
+
+ return compiled_template

Powered by Google App Engine
This is Rietveld 408576698