Changeset 271 in t29-www


Ignore:
Timestamp:
Jun 1, 2012, 8:22:49 PM (7 years ago)
Author:
sven
Message:

Dokumentation des RessourceLoader-Systems geschrieben. Pfade in den CSS-files zunaechst erst mal absolut gesetzt. Mit CSSMin werden diese spaeter vllt umgeschrieben bzw. kleine PNGs eingebettet.

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • lib/loader.php

    r269 r271  
    22/**
    33 * t29 ressource loading system.
     4 *
    45 * Entry point for loading javascript and css style sheet files in a bundled and
    5  * compressed manner, including caching.
     6 * compressed manner, including caching. This file only checks up the caches and
     7 * contains the main configuration. See ressourceloader.php for all constructing
     8 * code.
    69 *
    710 **/
     
    3639// (no more applicable because configuration is given as array to constructor):
    3740// foreach($conf as $var => $val) { $GLOBALS[$var] = $val[$typepos]; }
    38 header("Content-Type: $content_types");
    3941
    4042require "$lib/cache.php";
     
    4244$js_cache->test_files = $modules;
    4345$js_cache->set_cache_file($webroot, $cache_file);
     46
     47header("Content-Type: $content_types");
    4448if(!$debug) $js_cache->try_cache_and_exit();
    4549
  • lib/ressourceloader.php

    r270 r271  
    22/**
    33 * t29RessourceLoader classes.
    4  * This file behaves to loader.php like template.php behaves to technikum29.php.
    54 *
    6  * classes t29JavaScriptRessourceLoader and t29StyleSheetRessourceLoader are also defined in
    7  * this class.
     5 * The t29 ressource loading system features full caching, directory file input,
     6 * OOP style file type specific functions, pre/post per file injection hooks
     7 * (AOP style) and post output content filtering where compression tools for
     8 * JavaScript and CSS are used.
    89 *
    9  * For minification the files JavaScriptMinifier.php and CSSMin.php are included on need.
     10 * The architecture and compression technique is highly inspired by the
     11 * RessourceLoader framework of MediaWiki 1.20.
     12 *
     13 * These classes make usage of class inheritance, heavy PHP output buffering, the
     14 * t29v6 caching subsystem and the general t29v6 variable convencience.
     15 *
     16 * This file defines classes t29{,JavaScript,StyleSheet}RessourceLoader.
     17 * Libs JavaScriptMinifier.php and CSSMin.php are included on per-method
     18 * level for minification.
     19 *
     20 * 2012 Sven Koeppel
     21 *
    1022 **/
    1123
    1224class t29RessourceLoader {
     25        /**
     26         * expects: cache_file, module_dir, glob_pattern, content_types, class, modules, debug
     27         **/
    1328        public $conf;
    1429       
     30        /**
     31         * Construct with configuration array. See loader.php for contents of
     32         * that array. See above for minimum elements which must be present.
     33         **/
    1534        /// @param $conf configuration array.
    1635        function __construct($conf) {
     
    1938        }
    2039       
    21         function print_debug($string) {
     40        /**
     41         * Print out debug messages, only if debug switch is given.
     42         **/
     43        protected function print_debug($string) {
    2244                if($this->conf['debug'])
    2345                        echo $string;
    2446        }
    25        
     47
     48        /**
     49         * Module hooking: By overwriting this method and looking at $mod_filename,
     50         * you can inject any output before that given file.
     51         *
     52         * Example:
     53         *  class YourRessourceLoader extends t29RessourceLoader {[
     54         *     function print_before_file($file, $i) {
     55         *         parent::print_before_file($file, $i);
     56         *         print "Make a boo boo loading the ${i}. file named ${file}!";
     57         *     }
     58         *  }
     59         * This will prepend that string before the output of the file.
     60         *
     61         * Always call the parent function when overwriting so that output is printed,
     62         * too! (See example)
     63         *
     64         * @param $mod_filename Filename of module, like "foo.js".
     65         * @param $dir_index Iteration index while traversing the directory (see run()). Not so important.
     66         * @returns String that
     67         **/
    2668        function print_before_file($mod_filename, $dir_index) {
    2769                $this->print_debug("\n\n/*** t29v6-RessourceLoader[$dir_index]: Start of $mod_filename ***/\n\n");
    2870        }
    29        
     71
     72        /**
     73         * Same as print_before_file but will append your content to the file.
     74         * Obey calling parent::print_after_file at first so that corrections in
     75         * the super class can be done!
     76         *
     77         * The implementation in t29RessourceLoader prints some newlines to make sure
     78         * JavaScript oneliner comments at the end of a file won't comment out another
     79         * file's first line.
     80         *
     81         **/
    3082        function print_after_file($mod_filename, $dir_index) {
    3183                echo "\n\n"; // JS: for being sure no former "//" comment in last line wipes out code
    3284                $this->print_debug("\n\n/*** t29v6-RessourceLoader[$dir_index]: End of $mod_filename ***/\n\n");
    3385        }
    34        
     86
     87        /**
     88         * A generic print_header function which will be called at first. Give out some
     89         * stuff you want to prepend to your overall output. This method provides you a
     90         * generic JS/CSS compilant message where you can give your own $title string
     91         * or use no title (it will use your class name instead). If called with $title != null,
     92         * the C++ style multi line comment won't be closed so you can append your own
     93         * stuff.
     94         **/
    3595        function print_header($title=null) {
    3696                if(!$title) $title = __CLASS__;
     
    50110        }
    51111       
     112        /**
     113         * The main run() function will print out the header and concatenate all
     114         * modules contents. Expects OutputBuffering running!
     115         **/
    52116        function run() {
    53117                $this->print_header();
     
    62126        } // run
    63127
     128        /**
     129         * Overwrite compression_filter for filtering the whole output made by this
     130         * class. It is used as a shutdown filter in t29Cache, see usage in loader.php.
     131         * @param $output The output string fetched by OutputBuffering
     132         * @returns The filtered String. The default implementation just returns $output.
     133         **/
    64134        function compression_filter($output) {
    65135                return $output;
    66136        }
    67137} // class t29RessourceLoader
     138
    68139
    69140class t29JavaScriptRessourceLoader extends t29RessourceLoader {
     
    72143                parent::print_after_file($mod_filename, $dir_index);
    73144                if($mod_filename == "msg.js") {
    74                         // special treatment of this file
     145                        // append system messages to the special msg.js file
     146                        // to inject PHP code to JS userspace.
    75147                        $this->print_debug("\n/*** Auto appended ***/\n");
    76148                        require "$lib/messages.php";
     
    97169class t29StyleSheetRessourceLoader extends t29RessourceLoader {
    98170        function print_header() {
    99                 parent::print_header('StyleSheet Code');
     171                parent::print_header('StyleSheet');
    100172                echo " **/\n";
    101173        }
     
    104176                global $lib;
    105177                require "$lib/CSSMin.php";
    106                
    107178                # compression: 40kb to 16kb
    108179                $minified = CSSMin::minify($code);
  • lib/template.php

    r269 r271  
    102102 
    103103  <meta name="viewport" content="width=device-width,initial-scale=1">
    104   <link rel="stylesheet" href="/shared/css-v6/boiler.css">
    105   <link rel="stylesheet" href="/shared/css-v6/style.css">
    106   <link rel="stylesheet" href="/shared/css/common.css">
     104  <link rel="stylesheet" href="/lib/loader.php?type=css">
    107105  <?php
    108106        if($this->conf['has_pagecss'])
     
    210208
    211209  <script>window.t29={'conf': <?php print json_encode($this->javascript_config); ?>};</script>
    212   <script src="/lib/ressourceloader.php?type=js"></script>
     210  <script src="/lib/loader.php?type=js"></script>
    213211</div><!-- end of div id="footer-background-container" helper -->
    214212</body>
  • shared/css-v6/modules/10-window.css

    r269 r271  
    22
    33body {
    4         background: #cbc5bd url("../img-v6/bg-v2.body.png") repeat-x;
     4        background: #cbc5bd url("/shared/img-v6/bg-v2.body.png") repeat-x;
    55}
    66
     
    2323
    2424#footer-background-container {
    25         background: url("../img-v6/bg-v2.body-footer.png") bottom left repeat-x;
     25        background: url("/shared/img-v6/bg-v2.body-footer.png") bottom left repeat-x;
    2626        padding-bottom: 1px;
    2727}
  • shared/css-v6/modules/11-header.css

    r269 r271  
    77       
    88        /*border-bottom: 1px solid #5d5c58;*/
    9         background: url("../img-v6/line.header-footer.png") bottom left repeat-x;
     9        background: url("/shared/img-v6/line.header-footer.png") bottom left repeat-x;
    1010}
    1111
     
    1616        text-indent: -9999px;
    1717        width: 310px; height: 84px;
    18         background: url("../img-v6/banner.png");
     18        background: url("/shared/img-v6/banner.png");
    1919}
    2020
     
    163163        display: block;
    164164        text-indent: -999px; border: none;
    165         background: url("../img-v6/lupe.png") no-repeat;
     165        background: url("/shared/img-v6/lupe.png") no-repeat;
    166166        width: 13px; height: 13px;
    167167        position: absolute; right: 0px; top: 4px;
  • shared/css-v6/modules/13-footer.css

    r269 r271  
    77       
    88        /*border-top: 1px solid #5d5c58;*/
    9         background: #f1f1f1 url("../img-v6/line.header-footer.png") top left repeat-x;
     9        background: #f1f1f1 url("/shared/img-v6/line.header-footer.png") top left repeat-x;
    1010}
    1111
Note: See TracChangeset for help on using the changeset viewer.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License