]> dev.renevier.net Git - syj.git/commitdiff
cache js, css and png files
authorarno <arno@renevier.net>
Fri, 15 Apr 2011 19:07:28 +0000 (21:07 +0200)
committerarno <arno@renevier.net>
Fri, 15 Apr 2011 19:07:28 +0000 (21:07 +0200)
18 files changed:
application/Bootstrap.php
application/Version.php [new file with mode: 0644]
application/configs/medias.ini
application/controllers/AccountController.php
application/controllers/ContactController.php
application/controllers/ErrorController.php
application/controllers/FaqController.php
application/controllers/IdxController.php
application/controllers/ListController.php
application/controllers/LoginController.php
application/controllers/NewpwdController.php
application/controllers/PendingController.php
application/controllers/TermsofuseController.php
application/controllers/helpers/SyjMedias.php
public/css/syjprint.css
public/css/syjrawprint.css [new file with mode: 0644]
scripts/lighttpd.conf
scripts/release.py

index 60e06279a2e25c2bae5437813e626b84191a63a6..f3fb3999fbdf836831c3fb20a20f7ee74c846ef7 100644 (file)
@@ -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 (file)
index 0000000..b21ff0d
--- /dev/null
@@ -0,0 +1,7 @@
+<?php
+/*  This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier,
+    and is published under the AGPL license. */
+
+class Syj_Version {
+    const VERSION = "$SYJVERSION$";
+}
index 53c54890909fd15db6f9c56ca57da13bac5816e1..49f0f2d393ba56292ce6c25b76d420d0ba517b69 100644 (file)
@@ -9,4 +9,16 @@ scripts.newpwd = prototype, utils, newpwd
 scripts.list = OpenLayers, prototype, utils, list
 scripts.account = prototype, utils, account
 
+css.idx = olstyle, generic, syj, syjprint:print
+css.rawidx = generic, syjraw, syjrawprint:print
+css.login = generic, form, login
+css.pending = generic, form, pending
+css.contact = generic, form, contact
+css.faq = generic, faq
+css.newpwd = generic, form, newpwd
+css.error = generic, error
+css.termsofuse = generic, termsofuse
+css.list = generic, list
+css.account = generic, form, account
+
 [development:production]
index c79b4769cc84439a4fe273838d2e20c0b25c96d8..9db12047c197b87330754f9013ad04e269a7ec3c 100644 (file)
@@ -8,10 +8,8 @@ class AccountController extends Zend_Controller_Action
     public function init() {
         $this->_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"));
     }
 
index 8ff629ba597b42ce02bc1824842dcd9d50569196..7caf24e02cbf2349639fb0c8128709ef7c4c1840 100644 (file)
@@ -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"));
     }
 
index f2e1b69c51a22a6c580f476f203d3337f5bdc7dd..043b19945d898859a732fbc6e4bcc32c2114f141 100644 (file)
@@ -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() {
index a1a99f5ecfad8b309b21c0cc329ccb1e1c2357a3..a215cf58f1a628b30c57d5471844e6866c09e834 100644 (file)
@@ -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"));
     }
 }
index d0fa248f7c3bb4d8deb7f7ed2b521912aca29d2c..217295bbc0c9c9d08016bcfd749036707fbbe63d 100644 (file)
@@ -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();
index 1cf030809025e75f4aced523656451e1548b1800..e94088383fba22f336eb663ea2ed9e4bd4749094 100644 (file)
@@ -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"));
     }
 
index 490ca673ad2bbc9a56e7bfaad24a2bf63be2ef9f..152d18828a13adb44c88f5c71fe3ba58eb986b3c 100644 (file)
@@ -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() {
index 25a386217298c01bdbd63c7fcb84c7bb3fe921de..17b16cae391391837a8615bbdbae5eedccf5aab2 100644 (file)
@@ -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() {
index af7135b6546a3aefb7e588eb71099d3e22ff507f..ff28a1f94dad7b48db031faa703092ead5fa9b3c 100644 (file)
@@ -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() {
index a1278bb645137f36ca225c584a008b24fa02aa0b..20b99e2ee2d0654b10282505cef1b284d93ff38b 100644 (file)
@@ -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');
     }
index 4817535538761be31401949db533c465d417d9b5..49650846a47bc64f4bf73837666261f7da6eaab2 100644 (file)
@@ -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);
+        }
+    }
 }
index ebdef232f293c3eb46f2d928967bf37da051c800..36f829cd595564a6e4e32a659071d4f2b57ff162 100644 (file)
@@ -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 (file)
index 0000000..c83fd2c
--- /dev/null
@@ -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;
+}
index d4c0368de88e768cdcef0a155b3ae4a24314cf7d..2387a15eded04d6dbc902b94e9b4224a265352b6 100644 (file)
@@ -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" )
+}
index 95452004e31a7609899cb24a793661a5cc9a55fa..a95ddd6b6a7284b8293c104f0b35ed87a37740cf 100755 (executable)
@@ -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__, '*')):