Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add util for locating static files. Move to static.py.

  • Loading branch information...
commit 58721c2c9cb714e0c7bc88c9304f1e7fd7f112ed 1 parent d2ef201
Max Goodman chromakode authored spladug committed
Showing with 19 additions and 12 deletions.
  1. +18 −0 r2/r2/lib/static.py
  2. +1 −12 r2/r2/lib/template_helpers.py
18 r2/r2/lib/static.py
View
@@ -28,6 +28,24 @@
import base64
import shutil
+
+def locate_static_file(name):
+ from pylons import g
+ static_dirs = set(plugin.static_dir for plugin in g.plugins)
+ static_dirs.add(g.paths['static_files'])
+
+ for static_dir in static_dirs:
+ file_path = os.path.join(static_dir, name.lstrip('/'))
+ if os.path.exists(file_path):
+ return file_path
+
+
+def static_mtime(name):
+ path = locate_static_file(name)
+ if path:
+ return os.path.getmtime(path)
+
+
def generate_static_name(name, base=None):
"""Generate a unique filename.
13 r2/r2/lib/template_helpers.py
View
@@ -25,6 +25,7 @@
from r2.lib.utils import vote_hash, UrlParser, timesince, is_subdomain
from r2.lib import hooks
+from r2.lib.static import static_mtime
from r2.lib.media import s3_direct_url
import babel.numbers
@@ -38,18 +39,6 @@
from pylons.i18n import _, ungettext
-def static_mtime(path):
- static_dirs = set(plugin.static_dir for plugin in g.plugins)
- static_dirs.add(g.paths['static_files'])
-
- for static_dir in static_dirs:
- file_path = os.path.join(static_dir, path.lstrip('/'))
- try:
- return os.path.getmtime(file_path)
- except OSError:
- continue
-
-
static_text_extensions = {
'.js': 'js',
'.css': 'css',
Please sign in to comment.
Something went wrong with that request. Please try again.