You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.5 KiB

11 years ago
import os
11 years ago
from couchpotato.core.event import addEvent
12 years ago
from couchpotato.core.helpers.variable import tryInt
from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin
12 years ago
from couchpotato.environment import Env
11 years ago
log = CPLog(__name__)
autoload = 'ClientScript'
class ClientScript(Plugin):
paths = {
12 years ago
'style': [
11 years ago
'style/combined.min.css',
12 years ago
],
'script': [
'scripts/combined.vendor.min.js',
'scripts/combined.base.min.js',
'scripts/combined.plugins.min.js',
12 years ago
],
}
def __init__(self):
addEvent('clientscript.get_styles', self.getStyles)
addEvent('clientscript.get_scripts', self.getScripts)
self.makeRelative()
12 years ago
def makeRelative(self):
12 years ago
for static_type in self.paths:
12 years ago
updates_paths = []
for rel_path in self.paths.get(static_type):
12 years ago
file_path = os.path.join(Env.get('app_dir'), 'couchpotato', 'static', rel_path)
core_url = 'static/%s?%d' % (rel_path, tryInt(os.path.getmtime(file_path)))
11 years ago
updates_paths.append(core_url)
12 years ago
self.paths[static_type] = updates_paths
11 years ago
def getStyles(self, *args, **kwargs):
return self.get('style', *args, **kwargs)
12 years ago
11 years ago
def getScripts(self, *args, **kwargs):
return self.get('script', *args, **kwargs)
def get(self, type):
if type in self.paths:
return self.paths[type]
11 years ago
return []