From 7ab93faefae14af39fc5449a2c3311dd68d2c0f9 Mon Sep 17 00:00:00 2001 From: arno Date: Fri, 15 Apr 2011 21:07:28 +0200 Subject: [PATCH] cache js, css and png files --- application/Bootstrap.php | 12 +++++++++ application/Version.php | 7 +++++ application/configs/medias.ini | 12 +++++++++ application/controllers/AccountController.php | 4 +-- application/controllers/ContactController.php | 4 +-- application/controllers/ErrorController.php | 3 +-- application/controllers/FaqController.php | 3 +-- application/controllers/IdxController.php | 9 ++----- application/controllers/ListController.php | 3 +-- application/controllers/LoginController.php | 4 +-- application/controllers/NewpwdController.php | 4 +-- application/controllers/PendingController.php | 4 +-- .../controllers/TermsofuseController.php | 3 +-- application/controllers/helpers/SyjMedias.php | 23 +++++++++++++++- public/css/syjprint.css | 2 +- public/css/syjrawprint.css | 26 +++++++++++++++++++ scripts/lighttpd.conf | 6 ++++- scripts/release.py | 24 +++++++++++++++++ 18 files changed, 120 insertions(+), 33 deletions(-) create mode 100644 application/Version.php create mode 100644 public/css/syjrawprint.css diff --git a/application/Bootstrap.php b/application/Bootstrap.php index 60e0627..f3fb399 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -30,6 +30,18 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { if (strpos ($class, "Syj_") === 0) { $segments = explode ('_', $class); + if (count($segments) < 2) { + return; + } + + if (count($segments) == 2) { + $filename = APPLICATION_PATH . '/' . end($segments) . '.php'; + if (Zend_Loader::isReadable($filename)) { + include_once $filename; + } + return; + } + if (count($segments) < 3) { return; } diff --git a/application/Version.php b/application/Version.php new file mode 100644 index 0000000..b21ff0d --- /dev/null +++ b/application/Version.php @@ -0,0 +1,7 @@ +_helper->SyjUserManager->needsLogin(); $this->_helper->SyjMedias->addScripts('account'); + $this->_helper->SyjMedias->addStyleSheets('account'); - $this->view->headLink()->appendStylesheet('css/generic.css', 'all'); - $this->view->headLink()->appendStylesheet('css/form.css', 'all'); - $this->view->headLink()->appendStylesheet('css/account.css', 'all'); $this->view->headTitle($this->view->translate("my account")); } diff --git a/application/controllers/ContactController.php b/application/controllers/ContactController.php index 8ff629b..7caf24e 100644 --- a/application/controllers/ContactController.php +++ b/application/controllers/ContactController.php @@ -7,9 +7,7 @@ class ContactController extends Zend_Controller_Action public function init() { $this->_helper->SyjMedias->addScripts('contact'); - $this->view->headLink()->appendStylesheet('css/generic.css', 'all'); - $this->view->headLink()->appendStylesheet('css/form.css', 'all'); - $this->view->headLink()->appendStylesheet('css/contact.css', 'all'); + $this->_helper->SyjMedias->addStyleSheets('contact'); $this->view->headTitle($this->view->translate("contact form")); } diff --git a/application/controllers/ErrorController.php b/application/controllers/ErrorController.php index f2e1b69..043b199 100644 --- a/application/controllers/ErrorController.php +++ b/application/controllers/ErrorController.php @@ -10,8 +10,7 @@ class ErrorController extends Zend_Controller_Action public function init() { $this->_helper->SyjReset->resetPlaceHolders(); - $this->view->headLink()->appendStylesheet('css/generic.css', 'all'); - $this->view->headLink()->appendStylesheet('css/error.css', 'all'); + $this->_helper->SyjMedias->addStyleSheets('error'); } public function errorAction() { diff --git a/application/controllers/FaqController.php b/application/controllers/FaqController.php index a1a99f5..a215cf5 100644 --- a/application/controllers/FaqController.php +++ b/application/controllers/FaqController.php @@ -5,8 +5,7 @@ class FaqController extends Zend_Controller_Action { public function indexAction() { - $this->view->headLink()->appendStylesheet('css/generic.css', 'all'); - $this->view->headLink()->appendStylesheet('css/faq.css', 'all'); + $this->_helper->SyjMedias->addStyleSheets('faq'); $this->view->headTitle($this->view->translate("Frequently asked questions")); } } diff --git a/application/controllers/IdxController.php b/application/controllers/IdxController.php index d0fa248..217295b 100644 --- a/application/controllers/IdxController.php +++ b/application/controllers/IdxController.php @@ -7,20 +7,15 @@ class IdxController extends Zend_Controller_Action public function init() { $this->_helper->SyjMedias->addScripts('idx'); - $this->view->headLink()->appendStylesheet('css/olstyle.css', "all"); - $this->view->headLink()->appendStylesheet('css/generic.css', "all"); - $this->view->headLink()->appendStylesheet('css/syj.css', "all"); - $this->view->headLink()->appendStylesheet('css/syjprint.css', "print"); + $this->_helper->SyjMedias->addStyleSheets('idx'); $this->view->headMeta()->appendName('viewport', 'width=640px'); } public function rawmode(Syj_Model_Path $path) { $this->_helper->SyjReset->resetPlaceHolders(); $this->_helper->SyjMedias->addScripts('rawidx'); + $this->_helper->SyjMedias->addStyleSheets('rawidx'); - $this->view->headLink()->appendStylesheet('css/generic.css', "screen"); - $this->view->headLink()->appendStylesheet('css/syjraw.css', "screen"); - $this->view->headLink()->appendStylesheet('css/syjprint.css', "print"); $this->view->headTitle($path->displayTitle); $this->_jsRawLocaleStrings(); diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php index 1cf0308..e940883 100644 --- a/application/controllers/ListController.php +++ b/application/controllers/ListController.php @@ -9,9 +9,8 @@ class ListController extends Zend_Controller_Action $this->_helper->SyjUserManager->needsLogin(); $this->_helper->SyjMedias->addScripts('list'); + $this->_helper->SyjMedias->addStyleSheets('list'); - $this->view->headLink()->appendStylesheet('css/generic.css', 'all'); - $this->view->headLink()->appendStylesheet('css/list.css', 'all'); $this->view->headTitle($this->view->translate("my routes")); } diff --git a/application/controllers/LoginController.php b/application/controllers/LoginController.php index 490ca67..152d188 100644 --- a/application/controllers/LoginController.php +++ b/application/controllers/LoginController.php @@ -7,9 +7,7 @@ class LoginController extends Zend_Controller_Action public function init() { $this->view->headTitle($this->view->translate("login")); $this->_helper->SyjMedias->addScripts('login'); - $this->view->headLink()->appendStylesheet('css/generic.css', 'all'); - $this->view->headLink()->appendStylesheet('css/form.css', 'all'); - $this->view->headLink()->appendStylesheet('css/login.css', 'all'); + $this->_helper->SyjMedias->addStyleSheets('login'); } public function loginAction() { diff --git a/application/controllers/NewpwdController.php b/application/controllers/NewpwdController.php index 25a3862..17b16ca 100644 --- a/application/controllers/NewpwdController.php +++ b/application/controllers/NewpwdController.php @@ -7,9 +7,7 @@ class NewpwdController extends Zend_Controller_Action public function init() { $this->_helper->SyjMedias->addScripts('newpwd'); - $this->view->headLink()->appendStylesheet('css/generic.css', 'all'); - $this->view->headLink()->appendStylesheet('css/form.css', 'all'); - $this->view->headLink()->appendStylesheet('css/newpwd.css', 'all'); + $this->_helper->SyjMedias->addStyleSheets('newpwd'); } public function indexAction() { diff --git a/application/controllers/PendingController.php b/application/controllers/PendingController.php index af7135b..ff28a1f 100644 --- a/application/controllers/PendingController.php +++ b/application/controllers/PendingController.php @@ -6,9 +6,7 @@ class PendingController extends Zend_Controller_Action { public function init() { - $this->view->headLink()->appendStylesheet('css/generic.css', 'all'); - $this->view->headLink()->appendStylesheet('css/form.css', 'all'); - $this->view->headLink()->appendStylesheet('css/pending.css', 'all'); + $this->_helper->SyjMedias->addStyleSheets('pending'); } public function indexAction() { diff --git a/application/controllers/TermsofuseController.php b/application/controllers/TermsofuseController.php index a1278bb..20b99e2 100644 --- a/application/controllers/TermsofuseController.php +++ b/application/controllers/TermsofuseController.php @@ -5,8 +5,7 @@ class TermsofuseController extends Zend_Controller_Action { public function indexAction() { - $this->view->headLink()->appendStylesheet('css/generic.css', 'all'); - $this->view->headLink()->appendStylesheet('css/termsofuse.css', 'all'); + $this->_helper->SyjMedias->addStyleSheets('termsofuse'); $this->view->headTitle($this->view->translate("terms of use")); $this->view->rawmode = ($this->getRequest()->getQuery('format') == 'raw'); } diff --git a/application/controllers/helpers/SyjMedias.php b/application/controllers/helpers/SyjMedias.php index 4817535..4965084 100644 --- a/application/controllers/helpers/SyjMedias.php +++ b/application/controllers/helpers/SyjMedias.php @@ -13,7 +13,7 @@ class Syj_Controller_Action_Helper_SyjMedias extends Zend_Controller_Action_Help public function addScripts($action) { $view = $this->getActionController()->view; if (APPLICATION_ENV == "production") { - $view->headScript()->appendFile('js/' . $action . '.js'); + $view->headScript()->appendFile('js/' . $action . '.js' . '?' . Syj_Version::VERSION); return; } $scripts = explode(',', $this->_config->get('scripts')->get($action)); @@ -21,4 +21,25 @@ class Syj_Controller_Action_Helper_SyjMedias extends Zend_Controller_Action_Help $view->headScript()->appendFile('js/' . trim($name) . '.js'); } } + + public function addStyleSheets($action) { + $view = $this->getActionController()->view; + if (APPLICATION_ENV == "production") { + $suffix = '?' . Syj_Version::VERSION; + } else { + $suffix = ''; + } + + $sheets = explode(',', $this->_config->get('css')->get($action)); + foreach ($sheets as $sheet) { + $arr = explode(':', $sheet); + $arr = array_map('trim', $arr); + $href = 'css/' . $arr[0] . '.css' . $suffix; + $medias = array_slice($arr, 1); + if (!$medias) { + $medias = "all"; + } + $view->headLink()->appendStylesheet($href, $medias); + } + } } diff --git a/public/css/syjprint.css b/public/css/syjprint.css index ebdef23..36f829c 100644 --- a/public/css/syjprint.css +++ b/public/css/syjprint.css @@ -1,7 +1,7 @@ /* This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier, and is published under the AGPL license. */ -.olControlPanZoom, .olControlAttribution, .olControlLayerSwitcher { +.olControlPanZoom, .olControlLayerSwitcher { display: none; } #message, #other-language, #menu, #user_area, #login_area, #newpwd_area, #termsofusearea, footer, #map-overlay { diff --git a/public/css/syjrawprint.css b/public/css/syjrawprint.css new file mode 100644 index 0000000..c83fd2c --- /dev/null +++ b/public/css/syjrawprint.css @@ -0,0 +1,26 @@ +/* This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier, + and is published under the AGPL license. */ +body, html { + margin: 0; padding: 0; + width: 100%; + height: 100%; +} + +/* This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier, + and is published under the AGPL license. */ + +#map { + border: 1px solid; + position: static; + margin: 0; +} + +@page { + size: landscape; +} + +.olControlAttribution { + bottom: 0.5em; + left: 0.5em; + font-size: smaller; +} diff --git a/scripts/lighttpd.conf b/scripts/lighttpd.conf index d4c0368..2387a15 100644 --- a/scripts/lighttpd.conf +++ b/scripts/lighttpd.conf @@ -5,7 +5,8 @@ server.modules = ( "mod_rewrite", "mod_compress", "mod_fastcgi", - "mod_accesslog", + "mod_accesslog", + "mod_expire", ) fastcgi.server += ( ".php" => @@ -37,3 +38,6 @@ include_shell "/usr/share/lighttpd/create-mime.assign.pl" compress.cache-dir = "/data/work/syj/lighttpd/lighttpd-cache" compress.filetype = ( "application/javascript", "text/css") +$HTTP["url"] =~ "\.js$|\.css$|\.png$" { + expire.url = ( "" => "access plus 1 years" ) +} diff --git a/scripts/release.py b/scripts/release.py index 9545200..a95ddd6 100755 --- a/scripts/release.py +++ b/scripts/release.py @@ -5,6 +5,28 @@ __BUILD__="build" import shutil, os, sys, subprocess, tempfile, tarfile, glob, ConfigParser pathjoin = os.path.join +def updateversion(): + try: + import git + repo = git.Repo('.') + master = repo.commits()[0] + tag = (filter(lambda tag: tag.commit.id == master.id, repo.tags) or [""])[0] + if tag: + version = tag.name + except ImportError: + version = subprocess.Popen(['git', 'tag', '-l', '--contains', 'master'], stdout=subprocess.PIPE).communicate()[0][:-1] + if not version: + raise AssertionError, "master is not tagged" + + fd, fname = tempfile.mkstemp() + f = os.fdopen(fd, 'w') + versionfile = 'build/application/Version.php' + with open('build/application/Version.php') as source: + for line in source: + f.write(line.replace('$SYJVERSION$', version)) + f.close() + shutil.move(fname, versionfile) + def compress(path): tmpout = tempfile.TemporaryFile() subprocess.Popen(['yui-compressor', path], stdout=tmpout).communicate() @@ -88,6 +110,8 @@ def main(): install(source, target) + updateversion() + print "creating syj.tar.gz" targz = tarfile.open("build/syj.tar.gz", "w:gz") for path in glob.glob(pathjoin(__BUILD__, '*')): -- 2.39.2