code: def behavior_script(url, template_parameters=None, behaviors_dir=None):
      '''
      Returns the javascript behavior string populated with template_parameters.
      '''
      import re, logging, json
      for behavior in behaviors(behaviors_dir=behaviors_dir):
          if re.match(behavior['url_regex'], url):
              parameters = dict()
              if 'default_parameters' in behavior:
                  parameters.update(behavior['default_parameters'])
              if template_parameters:
                  parameters.update(template_parameters)
              template = jinja2_environment(behaviors_dir).get_template(
                      behavior['behavior_js_template'])
              script = template.render(parameters)
              logging.info(
                      'using template=%r populated with parameters=%r for %r',
                      behavior['behavior_js_template'], json.dumps(parameters), url)
              return script
      return Nonf behavior_script(url, template_parameters=None, behaviors_dir=None):
      '''
      Returns the javascript behavior string populated with template_parameters.
      '''
      import re, logging, json
      for behavior in behaviors(behaviors_dir=behaviors_dir):
          if re.match(behavior['url_regex'], url):
              parameters = dict()
              if 'default_parameters' in behavior:
                  parameters.update(behavior['default_parameters'])
              if template_parameters:
                  parameters.update(template_parameters)
              template = jinja2_environment(behaviors_dir).get_template(
                      behavior['behavior_js_template'])
              script = template.render(parameters)
              logging.info(
                      'using template=%r populated with parameters=%r for %r',
                      behavior['behavior_js_template'], json.dumps(parameters), url)
              return script
      return None
docs: Returns the javascript behavior string populated with template_parameters.