Back to index

moin  1.9.0~rc2
Functions | Variables
MoinMoin.support.werkzeug.contrib.jsrouting Namespace Reference

Functions

def dumps
def generate_map
def generate_adapter
def js_to_url_function
def NumberConverter_js_to_url

Variables

tuple _javascript_routing_template
dictionary js_to_url_functions

Function Documentation

Definition at line 15 of file jsrouting.py.

00015 
00016     def dumps(*args):
00017         raise RuntimeError('simplejson required for jsrouting')

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.contrib.jsrouting.generate_adapter (   adapter,
  name = 'url_for',
  map_name = 'url_map' 
)
Generates the url building function for a map.

Definition at line 213 of file jsrouting.py.

00213 
00214 def generate_adapter(adapter, name='url_for', map_name='url_map'):
00215     """Generates the url building function for a map."""
00216     values = {
00217         u'server_name':     dumps(adapter.server_name),
00218         u'script_name':     dumps(adapter.script_name),
00219         u'subdomain':       dumps(adapter.subdomain),
00220         u'url_scheme':      dumps(adapter.url_scheme),
00221         u'name':            name,
00222         u'map_name':        map_name
00223     }
00224     return u'''\
00225 var %(name)s = %(map_name)s(
00226     %(server_name)s,
00227     %(script_name)s,
00228     %(subdomain)s,
00229     %(url_scheme)s
00230 );''' % values
00231 

Here is the call graph for this function:

def MoinMoin.support.werkzeug.contrib.jsrouting.generate_map (   map,
  name = 'url_map' 
)
Generates a JavaScript function containing the rules defined in
this map, to be used with a MapAdapter's generate_javascript
method.  If you don't pass a name the returned JavaScript code is
an expression that returns a function.  Otherwise it's a standalone
script that assigns the function with that name.  Dotted names are
resolved (so you an use a name like 'obj.url_for')

In order to use JavaScript generation, simplejson must be installed.

Note that using this feature will expose the rules
defined in your map to users. If your rules contain sensitive
information, don't use JavaScript generation!

Definition at line 166 of file jsrouting.py.

00166 
00167 def generate_map(map, name='url_map'):
00168     """
00169     Generates a JavaScript function containing the rules defined in
00170     this map, to be used with a MapAdapter's generate_javascript
00171     method.  If you don't pass a name the returned JavaScript code is
00172     an expression that returns a function.  Otherwise it's a standalone
00173     script that assigns the function with that name.  Dotted names are
00174     resolved (so you an use a name like 'obj.url_for')
00175 
00176     In order to use JavaScript generation, simplejson must be installed.
00177 
00178     Note that using this feature will expose the rules
00179     defined in your map to users. If your rules contain sensitive
00180     information, don't use JavaScript generation!
00181     """
00182     map.update()
00183     rules = []
00184     converters = []
00185     for rule in map.iter_rules():
00186         trace = [{
00187             'is_dynamic':   is_dynamic,
00188             'data':         data
00189         } for is_dynamic, data in rule._trace]
00190         rule_converters = {}
00191         for key, converter in rule._converters.iteritems():
00192             js_func = js_to_url_function(converter)
00193             try:
00194                 index = converters.index(js_func)
00195             except ValueError:
00196                 converters.append(js_func)
00197                 index = len(converters) - 1
00198             rule_converters[key] = index
00199         rules.append({
00200             u'endpoint':    rule.endpoint,
00201             u'arguments':   list(rule.arguments),
00202             u'converters':  rule_converters,
00203             u'trace':       trace,
00204             u'defaults':    rule.defaults
00205         })
00206 
00207     return _javascript_routing_template.render({
00208         'name_parts':   name and name.split('.') or [],
00209         'rules':        dumps(rules),
00210         'converters':   converters
00211     })
00212 

Here is the call graph for this function:

Get the JavaScript converter function from a rule.

Definition at line 232 of file jsrouting.py.

00232 
00233 def js_to_url_function(converter):
00234     """Get the JavaScript converter function from a rule."""
00235     if hasattr(converter, 'js_to_url_function'):
00236         data = converter.js_to_url_function()
00237     else:
00238         for cls in getmro(type(converter)):
00239             if cls in js_to_url_functions:
00240                 data = js_to_url_functions[cls](converter)
00241                 break
00242         else:
00243             return 'encodeURIComponent'
00244     return '(function(value) { %s })' % data
00245 

Here is the caller graph for this function:

Definition at line 246 of file jsrouting.py.

00246 
00247 def NumberConverter_js_to_url(conv):
00248     if conv.fixed_digits:
00249         return u'''\
00250 var result = value.toString();
00251 while (result.length < %s)
00252     result = '0' + result;
00253 return result;''' % conv.fixed_digits
00254     return u'return value.toString();'
00255 


Variable Documentation

Definition at line 23 of file jsrouting.py.

Initial value:
00001 {
00002     NumberConverter:    NumberConverter_js_to_url
00003 }

Definition at line 256 of file jsrouting.py.