Changeset f8c266 in indico


Ignore:
Timestamp:
04/26/12 18:01:11 (13 months ago)
Author:
Pedro Ferreira <jose.pedro.ferreira@…>
Branches:
master, hello-world-walkthrough, ipv6, v0.99, 051b2622c51afb171a1dedb46a0df4fbb0cbd02e, 0da0c1403bae8e51d8229f460181c71b9e6dda72
Children:
ec666e
Parents:
2d1b8e
git-author:
Pedro Ferreira <jose.pedro.ferreira@…> (04/24/12 17:49:54)
git-committer:
Pedro Ferreira <jose.pedro.ferreira@…> (04/26/12 18:01:11)
Message:

[IMP] Using webassets

  • Runtime CSS minification (cached) added;
  • JS minification now in runtime (cached);
  • Plugins now handle their JS on their own;
Files:
1 added
6 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • indico/MaKaC/consoleScripts/installBase.py

    r05686c rf8c266  
    203203 
    204204 
    205 def jsCompress(): 
    206     '''Packs and minifies javascript files''' 
    207  
    208     try: 
    209         pkg_resources.require('JSTools') 
    210     except pkg_resources.DistributionNotFound: 
    211         print """ 
    212 JSTools not found! JSTools is needed for JavaScript compression, if you're building Indico from source. Please install it. 
    213 i.e. try 'easy_install jstools'""" 
    214         sys.exit(-1) 
    215  
    216     jsbuildPath = 'jsbuild' 
    217     os.chdir('./etc/js') 
    218     os.system('%s -o ../../indico/htdocs/js/jquery/pack jquery.cfg' % jsbuildPath) 
    219     os.system('%s -o ../../indico/htdocs/js/indico/pack indico.cfg' % jsbuildPath) 
    220     os.system('%s -o ../../indico/htdocs/js/presentation/pack presentation.cfg' % jsbuildPath ) 
    221     os.system('%s -o ../../indico/MaKaC/plugins/InstantMessaging/htdocs/js instantmessaging.cfg ' % jsbuildPath ) 
    222     os.system('%s -o ../../indico/ext/livesync/htdocs/js livesync.cfg' % jsbuildPath ) 
    223     os.chdir('../..') 
    224  
    225  
    226205def _checkModPythonIsInstalled(): 
    227206    pass 
  • indico/MaKaC/plugins/InstantMessaging/pages.py

    re10646 rf8c266  
    2020## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 
    2121 
     22import os 
     23from webassets import Bundle, Environment 
    2224from MaKaC.webinterface.pages.conferences import WPConferenceModifBase, WPConferenceDefaultDisplayBase 
    2325from MaKaC.webinterface import wcomponents 
     
    5052        self._tabCtrl = wcomponents.TabControl() 
    5153 
    52     #TODO: with wsgi we want to specify another path instead of the usual one for .js files, so we'll have to make some modifications 
    53     #to make possible specifying absoulte paths 
    54     def getJSFiles(self): 
    55         return WPConferenceModifBase.getJSFiles(self) + self._includeJSPackage('Plugins') 
     54        plugin_htdocs = os.path.join(os.path.dirname(__file__), 'htdocs') 
     55 
     56        self._plugin_asset_env = Environment(plugin_htdocs, '/InstantMessaging') 
     57        self._plugin_asset_env.register('instant_messaging', Bundle('js/InstantMessaging.js', 
     58                                                                    filters='jsmin', 
     59                                                                    output="InstantMessaging_%(version)s.min.js")) 
    5660 
    5761    def getJSFiles(self): 
    5862        return WPConferenceModifBase.getJSFiles(self) + \ 
    59                self._includeJSFile('InstantMessaging/js', 'InstantMessaging') 
     63               self._plugin_asset_env['instant_messaging'].urls() 
    6064 
    6165    def getCSSFiles(self): 
  • indico/MaKaC/plugins/InstantMessaging/rh.py

    re10646 rf8c266  
    3535from indico.web.legacy import wrapUH 
    3636from indico.web.rh import RHHtdocs 
     37 
    3738 
    3839class RHInstantMessagingHtdocs(RHHtdocs): 
  • indico/MaKaC/webinterface/pages/base.py

    r880ea8 rf8c266  
    1818## along with CDS Indico; if not, write to the Free Software Foundation, Inc., 
    1919## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 
     20 
     21from webassets import Environment 
     22from indico.web import assets 
    2023 
    2124import MaKaC.webinterface.wcomponents as wcomponents 
     
    4043 
    4144    def __init__( self, rh ): 
     45        config = Config.getInstance() 
    4246        self._rh = rh 
    4347        self._locTZ = "" 
     48        info = HelperMaKaCInfo.getMaKaCInfoInstance() 
     49 
     50        self._asset_env = Environment(config.getHtdocsDir(), '/') 
     51        self._asset_env.debug = info.isDebugActive() 
     52 
     53        # register existing assets 
     54        assets.register_all_js(self._asset_env) 
    4455 
    4556        #store page specific CSS and JS 
    4657        self._extraCSS = [] 
    4758        self._extraJS = [] 
    48  
    49     def _includeJSPackage(self, packageName, module = 'indico', path=None): 
    50         info = HelperMaKaCInfo().getMaKaCInfoInstance() 
    51  
    52         timestamp = os.stat(__file__).st_mtime 
    53  
    54         if info.isDebugActive(): 
    55             return ['js/%s/%s/Loader.js?%d' % (module, packageName, timestamp)] 
    56         else: 
    57             return ['js/%s/pack/%s.js.pack?%d' % (module, packageName, timestamp)] 
    58  
    59     def _includeJQuery(self): 
    60         # TODO: rename this to _includeJSLibs or something similar 
    61         info = HelperMaKaCInfo().getMaKaCInfoInstance() 
    62  
    63         timestamp = os.stat(__file__).st_mtime 
    64  
    65         files = ['underscore', 'jquery', 'jquery-ui', 'jquery.form', 'jquery.custom', 
    66                  'jquery.daterange', 'jquery.qtip', 'jquery.dttbutton', 'jquery.colorbox', 
    67                  'jquery.menu', 'date', 'jquery.multiselect'] 
    68         if info.isDebugActive(): 
    69             # We can't use Loader.js as jQuery is included before any indico js 
    70             return ['js/jquery/%s.js?%d' % (f, timestamp) for f in files] 
    71         else: 
    72             return ['js/jquery/pack/jquery.js.pack?%d' % timestamp] 
    73  
    74     def _includeJSFile(self, path, filename): 
    75         info = HelperMaKaCInfo().getMaKaCInfoInstance() 
    76  
    77         timestamp = os.stat(__file__).st_mtime 
    78  
    79         if info.isDebugActive(): 
    80             return ['%s/%s.js?%d' % (path, filename, timestamp)] 
    81         else: 
    82             return ['%s/%s.js.pack?%d' % (path, filename, timestamp)] 
    83  
    84     def _includePresentationFiles(self): 
    85         info = HelperMaKaCInfo().getMaKaCInfoInstance() 
    86  
    87         timestamp = os.stat(__file__).st_mtime 
    88  
    89         if info.isDebugActive(): 
    90             return ['%s?%d' % (f, timestamp) for f in ['js/presentation/Loader.js', 'js/indico/jquery/defaults.js', 'js/indico/jquery/global.js']] 
    91         else: 
    92             return ['%s?%d' % (f, timestamp) for f in ['js/presentation/pack/Presentation.js.pack', 'js/indico/jquery/defaults.js', 'js/indico/jquery/global.js']] 
    9359 
    9460    def _getBaseURL( self ): 
     
    10874        return [] 
    10975 
    110     def getJSFiles(self): 
    111         return self._includeJQuery() + \ 
    112                self._includePresentationFiles() + \ 
    113                self._includeJSPackage('Core') + \ 
    114                self._includeJSPackage('Legacy') + \ 
    115                self._includeJSPackage('Common') 
    116  
    11776    def _getJavaScriptInclude(self, scriptPath): 
    11877        return '<script src="'+ scriptPath +'" type="text/javascript"></script>\n' 
     78 
     79    def getJSFiles(self): 
     80        return self._asset_env['base_js'].urls() 
     81 
     82    def _includeJSPackage(self, pkg_name): 
     83        return self._asset_env['indico_' + pkg_name.lower()].urls() 
    11984 
    12085    def _getJavaScriptUserData(self): 
  • indico/MaKaC/webinterface/tpls/HTMLHeader.tpl

    rf56594 rf8c266  
    77 
    88        <link rel="shortcut icon" type="image/x-icon" href="${ systemIcon('addressBarIcon') }"> 
    9         <link rel="stylesheet" type="text/css" href="${ baseurl }/css/calendar-blue.css?${ timestamp }" > 
    10         <link rel="stylesheet" type="text/css" href="${ baseurl }/css/jquery-ui.css?${ timestamp }"> 
    11         <link rel="stylesheet" type="text/css" href="${ baseurl }/css/jquery.qtip.css?${ timestamp }"> 
    12         <link rel="stylesheet" type="text/css" href="${ baseurl }/css/jquery.colorbox.css?${ timestamp }"> 
    13         <link rel="stylesheet" type="text/css" href="${ baseurl }/css/jquery-ui-custom.css?${ timestamp }"> 
    149 
    15         <link rel="stylesheet" type="text/css" href="${ baseurl }/css/${ stylesheet }?${ timestamp }"> 
     10        % for stylesheet in stylesheets: 
     11        <link rel="stylesheet" type="text/css" href="${ baseurl + '/' + stylesheet }"> 
     12        % endfor 
    1613 
    1714        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
     
    3532        <!-- Page Specific JS files--> 
    3633        % for JSFile in extraJSFiles: 
    37             ${ page._getJavaScriptInclude(baseurl + '/' + JSFile) } 
     34            ${ page._getJavaScriptInclude(baseurl + JSFile) } 
    3835        % endfor 
    3936 
  • indico/MaKaC/webinterface/wcomponents.py

    raf8270 rf8c266  
    1919## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 
    2020 
     21from webassets import Environment 
     22from indico.web import assets 
     23 
    2124from MaKaC.plugins import PluginsHolder, OldObservable 
    2225 
     
    6063from MaKaC.common.ContextHelp import ContextHelp 
    6164from MaKaC.rb_tools import FormMode, overlap 
     65from MaKaC.common.info import HelperMaKaCInfo 
    6266 
    6367from lxml import etree 
     
    110114 
    111115        cfg = Configuration.Config.getInstance() 
     116        info = HelperMaKaCInfo.getMaKaCInfoInstance() 
     117 
    112118        self._dir = cfg.getTPLDir() 
     119        self._asset_env = Environment(os.path.join(cfg.getHtdocsDir(), 'css'), 'css/') 
     120        self._asset_env.debug = info.isDebugActive() 
     121 
     122        if DBMgr.getInstance().isConnected(): 
     123            css_file = cfg.getCssStylesheetName() 
     124        else: 
     125            css_file = 'Default.css' 
     126 
     127        assets.register_all_css(self._asset_env, css_file) 
    113128 
    114129    def _getSpecificTPL(self, dir, tplId, extension="tpl"): 
     
    256271        return text 
    257272 
     273 
    258274class WHTMLHeader(WTemplated): 
    259275 
    260  
    261  
    262     def __init__(self, tpl_name = None): 
     276    def __init__(self, tpl_name=None): 
    263277        WTemplated.__init__(self) 
    264278 
    265     def getVars( self ): 
    266         vars = WTemplated.getVars( self ) 
     279    def getVars(self): 
     280        tvars = WTemplated.getVars(self) 
    267281        minfo = info.HelperMaKaCInfo.getMaKaCInfoInstance() 
    268         vars["analyticsActive"] = minfo.isAnalyticsActive() 
    269         vars["analyticsCode"] = minfo.getAnalyticsCode() 
    270         vars["analyticsCodeLocation"] = minfo.getAnalyticsCodeLocation() 
    271  
    272  
    273         if DBMgr.getInstance().isConnected(): 
    274             vars['stylesheet'] = Config.getInstance().getCssStylesheetName() 
    275         else: 
    276             vars['stylesheet'] = 'Default.css' 
    277         vars['timestamp'] = "%d"%os.stat(__file__).st_mtime 
    278         return vars 
     282        tvars["analyticsActive"] = minfo.isAnalyticsActive() 
     283        tvars["analyticsCode"] = minfo.getAnalyticsCode() 
     284        tvars["analyticsCodeLocation"] = minfo.getAnalyticsCodeLocation() 
     285        tvars['timestamp'] = "%d" % os.stat(__file__).st_mtime 
     286        tvars['stylesheets'] = self._asset_env['base_css'].urls() 
     287        return tvars 
    279288 
    280289 
  • indico/ext/livesync/chrome.py

    r9264b3 rf8c266  
    2828# 3rd party lib imports 
    2929import zope.interface 
     30from webassets import Bundle, Environment 
    3031 
    3132# plugin imports 
     
    134135        self._templateClass = templateClass 
    135136 
     137        self._plugin_asset_env = Environment(RHLiveSyncHtdocs._local_path, '/livesync') 
     138        self._plugin_asset_env.register('livesync', Bundle('js/livesync.js', 
     139                                                           filters='jsmin', 
     140                                                           output="InstantMessaging__%(version)s.min.js")) 
     141 
    136142    def getJSFiles(self): 
    137143        return WPAdminPlugins.getJSFiles(self) + \ 
    138                self._includeJSFile('livesync/js', 'livesync') 
     144               self._plugin_asset_env['livesync'].urls() 
    139145 
    140146    def getCSSFiles(self): 
  • indico/ext/statistics/chrome.py

    rbe54ff6 rf8c266  
    171171 
    172172    def __init__(self, rh, templateClass, activeTab, params): 
     173        WPConferenceModifBase.__init__(self, rh, rh._conf) 
    173174        self._rh = rh 
    174175        self._conf = self._rh._conf 
  • requirements.txt

    rae7546 rf8c266  
    33wsgiref 
    44Babel 
    5 JSTools 
    65Mako 
    76MarkupSafe 
     
    2928py 
    3029pytest 
     30jsmin 
     31cssmin 
     32webassets 
     33python-cjson 
  • setup.py

    re3e124 rf8c266  
    125125             'lxml', 'cds-indico-extras', 'zc.queue', 'python-dateutil<2.0', 
    126126             'pypdf', 'mako>=0.4.1', 'babel', 'icalendar>=3.0', 'pyatom', 
    127              'simplejson', 'python-cjson'] 
     127             'simplejson', 'python-cjson', 'webassets', 'jsmin', 'cssmin'] 
    128128 
    129129    #for Python older than 2.7 
     
    143143 
    144144        return v 
     145 
    145146 
    146147###  Commands ########################################################### 
     
    151152 
    152153    def run(self): 
    153         global x 
    154154        sdist.sdist.run(self) 
    155  
    156  
    157 class jsdist_indico: 
    158     def jsCompress(self): 
    159         from MaKaC.consoleScripts.installBase import jsCompress 
    160         jsCompress() 
    161155 
    162156 
     
    164158    class bdist_indico(bdist.bdist, jsdist_indico): 
    165159        def run(self): 
    166             self.jsCompress() 
    167160            compileAllLanguages(self) 
    168161            bdist.bdist.run(self) 
     
    175168    class bdist_egg_indico(bdist_egg.bdist_egg, jsdist_indico): 
    176169        def run(self): 
    177             self.jsCompress() 
    178170            compileAllLanguages(self) 
    179171            bdist_egg.bdist_egg.run(self) 
     
    181173    bdist_egg_indico.dataFiles = dataFiles 
    182174    return bdist_egg_indico 
    183  
    184  
    185 class jsbuild(Command): 
    186     description = "minifies and packs javascript files" 
    187     user_options = [] 
    188     boolean_options = [] 
    189  
    190     def initialize_options(self): 
    191         pass 
    192  
    193     def finalize_options(self): 
    194         pass 
    195  
    196     def run(self): 
    197         from MaKaC.consoleScripts.installBase import jsCompress 
    198         jsCompress() 
    199175 
    200176 
     
    486462                'bdist': _bdist_indico(dataFiles), 
    487463                'bdist_egg': _bdist_egg_indico(dataFiles), 
    488                 'jsbuild': jsbuild, 
    489464                'develop_config': develop_config, 
    490465                'develop': develop_indico, 
Note: See TracChangeset for help on using the changeset viewer.