Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Static Private Attributes
ResourceRegistries.tools.JSRegistry.JSRegistryTool Class Reference
Inheritance diagram for ResourceRegistries.tools.JSRegistry.JSRegistryTool:
Inheritance graph
[legend]
Collaboration diagram for ResourceRegistries.tools.JSRegistry.JSRegistryTool:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def clearScripts
def finalizeContent
def manage_addScript
def manage_saveScripts
def manage_removeScript
def registerScript
def updateScript
def getCompressionOptions
def getContentType
def getResourceContent

Public Attributes

 resources

Static Public Attributes

 id = config.JSTOOLNAME
 meta_type = config.JSTOOLTYPE
string title = 'JavaScript Registry'
tuple security = ClassSecurityInfo()
tuple manage_jsForm = PageTemplateFile('www/jsconfig', config.GLOBALS)
tuple manage_jsComposition = PageTemplateFile('www/jscomposition', config.GLOBALS)
tuple manage_options
tuple attributes_to_compare
string filename_base = 'ploneScripts'
string filename_appendix = '.js'
 cache_duration = config.JS_CACHE_DURATION
string merged_output_prefix = u""
 resource_class = JavaScript

Private Member Functions

def _compressJS

Static Private Attributes

 __implements__ = BaseRegistryTool.__implements__

Detailed Description

A Plone registry for managing the linking to Javascript files.

Definition at line 52 of file JSRegistry.py.


Member Function Documentation

def ResourceRegistries.tools.JSRegistry.JSRegistryTool._compressJS (   self,
  content,
  level = 'safe' 
) [private]

Definition at line 106 of file JSRegistry.py.

00106 
00107     def _compressJS(self, content, level='safe'):
00108         encode_marker = "/* sTART eNCODE */\n%s\n/* eND eNCODE */"
00109         if level == 'full-encode':
00110             return encode_marker % JavascriptPacker('full').pack(content)
00111         elif level == 'safe-encode':
00112             return encode_marker % JavascriptPacker('safe').pack(content)
00113         elif level == 'full':
00114             return JavascriptPacker('full').pack(content)
00115         elif level == 'safe':
00116             return JavascriptPacker('safe').pack(content)
00117         else:
00118             return content

Here is the caller graph for this function:

Definition at line 103 of file JSRegistry.py.

00103 
00104     def clearScripts(self):
00105         self.clearResources()

Here is the call graph for this function:

def ResourceRegistries.tools.JSRegistry.JSRegistryTool.finalizeContent (   self,
  resource,
  content 
)
Finalize the resource content.

Definition at line 120 of file JSRegistry.py.

00120 
00121     def finalizeContent(self, resource, content):
00122         """Finalize the resource content."""
00123         compression = resource.getCompression()
00124         if compression != 'none' and not self.getDebugMode():
00125             orig_url = "%s/%s?original=1" % (self.absolute_url(), resource.getId())
00126             content = "// %s\n%s" % (orig_url,
00127                                      self._compressJS(content, compression))
00128 
00129         return content

Here is the call graph for this function:

Compression methods for use in ZMI forms.

Definition at line 215 of file JSRegistry.py.

00215 
00216     def getCompressionOptions(self):
00217         """Compression methods for use in ZMI forms."""
00218         return config.JS_COMPRESSION_METHODS

Return the registry content type.

Definition at line 220 of file JSRegistry.py.

00220 
00221     def getContentType(self):
00222         """Return the registry content type."""
00223         plone_utils = getToolByName(self, 'plone_utils')
00224         try:
00225             encoding = plone_utils.getSiteEncoding()
00226         except AttributeError:
00227             # For Plone < 2.1
00228             pprop = getToolByName(self, 'portal_properties')
00229             default = 'utf-8'
00230             try:
00231                 encoding = pprop.site_properties.getProperty('default_charset', default)
00232             except AttributeError:
00233                 encoding = default
00234         return 'application/x-javascript;charset=%s' % encoding

Here is the call graph for this function:

Here is the caller graph for this function:

def ResourceRegistries.tools.JSRegistry.JSRegistryTool.getResourceContent (   self,
  item,
  context,
  original = False 
)

Definition at line 236 of file JSRegistry.py.

00236 
00237     def getResourceContent(self, item, context, original=False):
00238         output = BaseRegistryTool.getResourceContent(self, item, context, original)
00239         if not original:
00240             mapper = JavascriptKeywordMapper()
00241             regexp = re.compile(r"/\* sTART eNCODE \*/\s*(.*?)\s*/\* eND eNCODE \*/", re.DOTALL)
00242             matches = regexp.findall(output)
00243             if len(matches) > 0:
00244                 mapper.analyse("\n".join(matches))
00245                 decoder = mapper.getDecodeFunction(name='__dEcOdE')
00246                 def repl(m):
00247                     return mapper.getDecoder(mapper.sub(m.group(1)),
00248                                              keyword_var="''",
00249                                              decode_func='__dEcOdE')
00250                 #output = "\n__sTaRtTiMe = new Date()\n%s\n%s\nalert(new Date() - __sTaRtTiMe);" % (decoder,
00251                 output = "\n%s\n%s\n" % (decoder,
00252                                          regexp.sub(repl, output))
00253         return output
00254 
00255 InitializeClass(JSRegistryTool)
def ResourceRegistries.tools.JSRegistry.JSRegistryTool.manage_addScript (   self,
  id,
  expression = '',
  inline = False,
  enabled = False,
  cookable = True,
  compression = 'safe',
  cacheable = True,
  REQUEST = None 
)
Register a script from a TTW request.

Definition at line 137 of file JSRegistry.py.

00137 
00138                          cacheable=True, REQUEST=None):
00139         """Register a script from a TTW request."""
00140         self.registerScript(id, expression, inline, enabled, cookable, compression, cacheable)
00141         if REQUEST:
00142             REQUEST.RESPONSE.redirect(REQUEST['HTTP_REFERER'])

Here is the call graph for this function:

Here is the caller graph for this function:

Remove script with ZMI button.

Definition at line 172 of file JSRegistry.py.

00172 
00173     def manage_removeScript(self, id, REQUEST=None):
00174         """Remove script with ZMI button."""
00175         self.unregisterResource(id)
00176         if REQUEST:
00177             REQUEST.RESPONSE.redirect(REQUEST['HTTP_REFERER'])

Here is the call graph for this function:

Save scripts from the ZMI.

Updates the whole sequence. For editing and reordering.

Definition at line 144 of file JSRegistry.py.

00144 
00145     def manage_saveScripts(self, REQUEST=None):
00146         """Save scripts from the ZMI.
00147 
00148         Updates the whole sequence. For editing and reordering.
00149         """
00150         debugmode = REQUEST.get('debugmode', False)
00151         self.setDebugMode(debugmode)
00152         autogroupingmode = REQUEST.get('autogroupingmode', False)
00153         self.setAutoGroupingMode(autogroupingmode)
00154         records = REQUEST.form.get('scripts')
00155         records.sort(lambda a, b: a.sort-b.sort)
00156         self.resources = ()
00157         scripts = []
00158         for r in records:
00159             script = JavaScript(r.get('id'),
00160                                 expression=r.get('expression', ''),
00161                                 inline=r.get('inline'),
00162                                 enabled=r.get('enabled'),
00163                                 cookable=r.get('cookable'),
00164                                 cacheable=r.get('cacheable'),
00165                                 compression=r.get('compression', 'safe'))
00166             scripts.append(script)
00167         self.resources = tuple(scripts)
00168         self.cookResources()
00169         if REQUEST:
00170             REQUEST.RESPONSE.redirect(REQUEST['HTTP_REFERER'])

Here is the call graph for this function:

def ResourceRegistries.tools.JSRegistry.JSRegistryTool.registerScript (   self,
  id,
  expression = '',
  inline = False,
  enabled = True,
  cookable = True,
  compression = 'safe',
  cacheable = True,
  skipCooking = False 
)
Register a script.

Definition at line 185 of file JSRegistry.py.

00185 
00186                        skipCooking=False):
00187         """Register a script."""
00188         script = JavaScript(id,
00189                             expression=expression,
00190                             inline=inline,
00191                             enabled=enabled,
00192                             cookable=cookable,
00193                             compression=compression,
00194                             cacheable=cacheable)
00195         self.storeResource(script, skipCooking=skipCooking)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 197 of file JSRegistry.py.

00197 
00198     def updateScript(self, id, **data):
00199         script = self.getResourcesDict().get(id, None)
00200         if script is None:
00201             raise ValueError, 'Invalid resource id %s' % (id)
00202         if data.get('expression', None) is not None:
00203             script.setExpression(data['expression'])
00204         if data.get('inline', None) is not None:
00205             script.setInline(data['inline'])
00206         if data.get('enabled', None) is not None:
00207             script.setEnabled(data['enabled'])
00208         if data.get('cookable', None) is not None:
00209             script.setCookable(data['cookable'])
00210         if data.get('compression', None) is not None:
00211             script.setCompression(data['compression'])
00212         if data.get('cacheable', None) is not None:
00213             script.setCacheable(data['cacheable'])

Here is the call graph for this function:


Member Data Documentation

ResourceRegistries.tools.JSRegistry.JSRegistryTool.__implements__ = BaseRegistryTool.__implements__ [static, private]

Definition at line 62 of file JSRegistry.py.

Initial value:
('getExpression', 'getCookable',
                             'getCacheable', 'getInline')

Definition at line 82 of file JSRegistry.py.

Definition at line 86 of file JSRegistry.py.

Definition at line 85 of file JSRegistry.py.

Definition at line 84 of file JSRegistry.py.

Definition at line 55 of file JSRegistry.py.

tuple ResourceRegistries.tools.JSRegistry.JSRegistryTool.manage_jsComposition = PageTemplateFile('www/jscomposition', config.GLOBALS) [static]

Definition at line 69 of file JSRegistry.py.

tuple ResourceRegistries.tools.JSRegistry.JSRegistryTool.manage_jsForm = PageTemplateFile('www/jsconfig', config.GLOBALS) [static]

Definition at line 68 of file JSRegistry.py.

Initial value:
(
        {
            'label': 'Javascript Registry',
            'action': 'manage_jsForm',
        },
        {
            'label': 'Merged JS Composition',
            'action': 'manage_jsComposition',
        },
    )

Definition at line 71 of file JSRegistry.py.

Definition at line 87 of file JSRegistry.py.

Definition at line 56 of file JSRegistry.py.

Definition at line 96 of file JSRegistry.py.

Definition at line 155 of file JSRegistry.py.

Definition at line 59 of file JSRegistry.py.

Definition at line 57 of file JSRegistry.py.


The documentation for this class was generated from the following file: