Ejemplo n.º 1
0
def prepare_renderer(configurator):
    """Prepare rendering."""
    configurator = base_prepare_renderer(configurator)
    configurator.variables['template_id'] = 'view'
    view_name = configurator.variables['view_name'].strip('_')
    normalized_view_name = cc.snakecase(view_name)
    configurator.variables['view_name_normalized'] = normalized_view_name
    if configurator.variables['view_python_class']:
        python_class_name = configurator.variables[
            'view_python_class_name'].strip('_')  # NOQA: E501
        configurator.variables[
            'view_python_class_name'] = cc.pascalcase(  # NOQA: E501
                python_class_name, )
        view_python_file_name = cc.snakecase(python_class_name)
        configurator.variables['view_python_file_name'] = view_python_file_name
        view_name_from_input = normalized_view_name.replace('_', '-')
        view_name_from_python_class = view_python_file_name.replace('_', '-')
        if view_name_from_input != view_name_from_python_class:
            configurator.variables['view_name'] = view_name_from_input
    else:
        configurator.variables['view_python_file_name'] = view_name

    if not configurator.variables['view_template']:
        configurator.variables['view_template_name'] = view_name

    configurator.target_directory = configurator.variables['package_folder']
Ejemplo n.º 2
0
def enum_value(context, instance):
    request = context.get("_request")
    _ = request.i18n.gettext
    enum_name = case_conversion.snakecase(instance.__class__.__name__)

    if instance:
        return _(enum_name + "_" + case_conversion.snakecase(instance.value))
    else:
        return instance
Ejemplo n.º 3
0
def pre_renderer(configurator):
    """Pre rendering."""
    configurator = base_prepare_renderer(configurator)
    configurator.variables['template_id'] = 'restapi_service'
    name = configurator.variables['service_name'].strip('_')
    name_normalized = cc.snakecase(name)
    configurator.variables['service_name_normalized'] = name_normalized
    class_name = configurator.variables['service_class_name'].strip(
        '_')  # NOQA: E501
    configurator.variables['service_class_name'] = cc.pascalcase(  # NOQA: E501
        class_name, )
    configurator.variables['service_class_name_normalized'] = cc.snakecase(
        class_name, )
    configurator.target_directory = configurator.variables['package_folder']
Ejemplo n.º 4
0
def pre_renderer(configurator):
    """Pre rendering."""
    configurator = base_prepare_renderer(configurator)
    configurator.variables['template_id'] = 'restapi_service'
    name = configurator.variables['service_name'].strip('_')
    name_normalized = cc.snakecase(name)
    configurator.variables['service_name_normalized'] = name_normalized
    class_name = configurator.variables['service_class_name'].strip('_')  # NOQA: E501
    configurator.variables['service_class_name'] = cc.pascalcase(     # NOQA: E501
        class_name,
    )
    configurator.variables['service_class_name_normalized'] = cc.snakecase(
        class_name,
    )
    configurator.target_directory = configurator.variables['package_folder']
Ejemplo n.º 5
0
def pre_renderer(configurator):
    """Pre rendering."""
    configurator = base_prepare_renderer(configurator)
    configurator.variables['template_id'] = 'subscriber'
    name = configurator.variables['subscriber_handler_name'].strip('_')
    configurator.variables['subscriber_handler_file_name'] = cc.snakecase(name)
    configurator.target_directory = configurator.variables['package_folder']
Ejemplo n.º 6
0
def pre_renderer(configurator):
    """Pre rendering."""
    configurator = base_prepare_renderer(configurator)
    configurator.variables['template_id'] = 'svelte_app'
    name = configurator.variables['svelte_app_name'].strip('_')
    configurator.variables['svelte_app_file_name'] = cc.snakecase(name)
    configurator.variables['svelte_app_name_dashed'] = cc.dashcase(name)
Ejemplo n.º 7
0
def show(package, verbose=False):
    """Get package information.
    
    :arg str package: Package name.
    :arg bool verbose: Whether to return verbose info.
    :return: A namespace object holding the package information.
    :rtype: Namespace
    
    This function uses ``pip show`` under the hood. Property name is generated
    by :func:`case_conversion.snakecase`.
    """
    cmd = "show"
    if verbose:
        cmd += " --verbose"
    ns = Namespace()
    last_name = None
    for line in execute_pip("{} {}".format(cmd, package), True):
        match = re.match("([\w-]+):\s*(.*)", line)
        if match:
            name, value = match.groups()
            name = case_conversion.snakecase(name)
            value = value.strip()
            setattr(ns, name, value)
            last_name = name
            continue
        match = re.match("\s+(\S.*)", line)
        if match and last_name:
            value = getattr(ns, last_name) + "\n" + match.group(1).strip()
            setattr(ns, last_name, value)
            continue
    return ns
Ejemplo n.º 8
0
def get_view_template_name_from_python_class(configurator, question):
    if configurator.variables['view_python_class']:
        view_class_name = configurator.variables['view_python_class_name']
        view_generated_name = cc.snakecase(view_class_name)  # NOQA: E501
        question.default = view_generated_name
    else:
        question.default = 'my_view'
Ejemplo n.º 9
0
def get_template_name_default(configurator, question):
    if configurator.variables['view_template']:
        view_url = configurator.variables['view_name']
        template_default_name = cc.snakecase(view_url)
        question.default = template_default_name
    else:
        question.default = 'view'
Ejemplo n.º 10
0
def get_service_name_from_python_class(configurator, question):
    """Get default service_name from python class"""
    class_name = configurator.variables['service_class_name']
    if class_name:
        generated_name = cc.snakecase(class_name).replace('_', '-')
        question.default = generated_name
    else:
        question.default = 'my-service'
Ejemplo n.º 11
0
def enum_value(context, val):
    request = context.get("_request")
    _ = request.i18n.gettext
    enum_name = case_conversion.snakecase(val.__class__.__name__)

    if val:
        return _('_'.join([enum_name, val]))
    else:
        return val
Ejemplo n.º 12
0
def get_view_name_from_python_class(configurator, question):
    """Generate view default name from python class"""
    if configurator.variables['view_python_class']:
        view_class_name = configurator.variables['view_python_class_name']
        view_generated_name = cc.snakecase(view_class_name).replace(
            '_', '-')  # NOQA: E501
        question.default = view_generated_name
    else:
        question.default = 'my-view'
Ejemplo n.º 13
0
def prepare_renderer(configurator):
    configurator = base_prepare_renderer(configurator)
    configurator.variables['template_id'] = 'behavior'
    behavior_name = configurator.variables['behavior_name'].strip('_')
    configurator.variables['behavior_name_klass'] = cc.pascalcase(
        behavior_name)
    configurator.variables['behavior_name_normalized'] = cc.snakecase(  # NOQA: E501
        behavior_name)
    configurator.target_directory = configurator.variables['package_folder']
Ejemplo n.º 14
0
def prepare_renderer(configurator):
    configurator = base_prepare_renderer(configurator)
    configurator.variables['template_id'] = 'behavior'
    behavior_name = configurator.variables['behavior_name'].strip('_')
    configurator.variables['behavior_name_klass'] = cc.pascalcase(
        behavior_name)
    configurator.variables[
        'behavior_name_normalized'] = cc.snakecase(  # NOQA: E501
            behavior_name)
    configurator.target_directory = configurator.variables['package_folder']
Ejemplo n.º 15
0
def prepare_renderer(configurator):
    """Prepare rendering."""
    configurator = base_prepare_renderer(configurator)
    configurator.variables['template_id'] = 'viewlet'
    viewlet_name = configurator.variables['viewlet_name'].strip('_')
    normalized_viewlet_name = cc.snakecase(viewlet_name)
    configurator.variables['viewlet_name_normalized'] = normalized_viewlet_name
    if not configurator.variables['viewlet_template']:
        configurator.variables['viewlet_template_name'] = normalized_viewlet_name  # NOQA: E501
    python_class_name = configurator.variables['viewlet_python_class_name'].strip('_')  # NOQA: E501
    configurator.variables['viewlet_python_class_name'] = cc.pascalcase(      # NOQA: E501
        python_class_name,
    )
    viewlet_python_file_name = cc.snakecase(viewlet_name)
    configurator.variables['viewlet_python_file_name'] = viewlet_python_file_name    # NOQA: E501
    configurator.target_directory = configurator.variables['package_folder']
    package_name = configurator.variables['package.dottedname'].replace('.', '_')  # NOQA: E501
    browser_layer = cc.pascalcase(package_name)
    configurator.variables['browser_layer'] = 'I{0}Layer'.format(browser_layer)
Ejemplo n.º 16
0
    def template_path(self) -> str:
        if self._template_path is None:
            cell_name = self.__class__.__name__
            if not cell_name.endswith('Cell'):
                raise Exception('Cell name does not end with Cell, you must override template_path!')

            name = case_conversion.snakecase(cell_name[:-len('Cell')])

            if self.template_prefix is not None:
                self._template_path = f"{self.template_prefix}/{name}.j2.jade"
            else:
                self._template_path = f"{name}.j2.jade"

        return self._template_path
Ejemplo n.º 17
0
def prepare_renderer(configurator):
    """Prepare rendering."""
    configurator = base_prepare_renderer(configurator)
    configurator.variables['template_id'] = 'content_type'
    type_name = configurator.variables['dexterity_type_name']
    dx_type_name_klass = cc.pascalcase(type_name, )
    configurator.variables['dexterity_type_name_klass'] = dx_type_name_klass
    dx_type_fti_file_name = type_name.replace(' ', '_')
    configurator.variables[
        'dexterity_type_fti_file_name'] = dx_type_fti_file_name  # NOQA: E501
    dx_type_name_normalized = cc.snakecase(dx_type_fti_file_name)
    configurator.variables[
        'dexterity_type_name_normalized'] = dx_type_name_normalized  # NOQA: E501
    configurator.target_directory = configurator.variables['package_folder']
Ejemplo n.º 18
0
def show(packages, verbose=False):
    """Get package information.
    
    :arg list[str] packages: A list of package name.
    :arg bool verbose: Whether to return verbose info.
    :return: A list of namespace objects holding the package information.
    :rtype: list[Namespace]
    
    This function uses ``pip show`` under the hood. Property name is generated
    by :func:`case_conversion.snakecase`.
    """
    if not packages:
        return []
        
    cmd = "show"
    if verbose:
        cmd += " --verbose"
        
    result = []
    ns = Namespace()
    last_name = None
    
    for line in execute_pip("{} {}".format(cmd, " ".join(packages)), True):
        if line.startswith("---"):
            result.append(ns)
            ns = Namespace()
            continue
            
        match = re.match("([\w-]+):\s*(.*)", line)
        if match:
            name, value = match.groups()
            name = case_conversion.snakecase(name)
            value = value.strip()
            setattr(ns, name, value)
            last_name = name
            continue
            
        match = re.match("\s+(\S.*)", line)
        if match and last_name:
            value = getattr(ns, last_name) + "\n" + match.group(1).strip()
            setattr(ns, last_name, value)
            continue
            
    result.append(ns)
    return result
Ejemplo n.º 19
0
def prepare_renderer(configurator):
    """Prepare rendering."""
    configurator = base_prepare_renderer(configurator)
    configurator.variables['template_id'] = 'portlet'
    portlet_name = configurator.variables['portlet_name']
    normalized_portlet_name = cc.snakecase(slugify(portlet_name))  # NOQA: E501
    configurator.variables['portlet_name_normalized'] = normalized_portlet_name
    portlet_config_name = cc.pascalcase(normalized_portlet_name)
    configurator.variables['portlet_configuration_name'] = u'{0}.portlets.{1}'.format(  # NOQA: E501
        configurator.variables['package.dottedname'],
        portlet_config_name,
    )
    configurator.variables['data_provider_class_name'] = u'I{0}Portlet'.format(
        portlet_config_name,
    )
    configurator.target_directory = configurator.variables['package_folder']
    package_name = configurator.variables['package.dottedname'].replace('.', '_')  # NOQA: E501
    browser_layer = cc.pascalcase(package_name)
    configurator.variables['browser_layer'] = u'I{0}Layer'.format(
        browser_layer,
    )
Ejemplo n.º 20
0
def prepare_renderer(configurator):
    """Prepare rendering."""
    configurator = base_prepare_renderer(configurator)
    configurator.variables['template_id'] = 'portlet'
    portlet_name = configurator.variables['portlet_name']
    normalized_portlet_name = cc.snakecase(slugify(portlet_name))  # NOQA: E501
    configurator.variables['portlet_name_normalized'] = normalized_portlet_name
    portlet_config_name = cc.pascalcase(normalized_portlet_name)
    configurator.variables[
        'portlet_configuration_name'] = u'{0}.portlets.{1}'.format(  # NOQA: E501
            configurator.variables['package.dottedname'],
            portlet_config_name,
        )
    configurator.variables['data_provider_class_name'] = u'I{0}Portlet'.format(
        portlet_config_name, )
    configurator.target_directory = configurator.variables['package_folder']
    package_name = configurator.variables['package.dottedname'].replace(
        '.', '_')  # NOQA: E501
    browser_layer = cc.pascalcase(package_name)
    configurator.variables['browser_layer'] = u'I{0}Layer'.format(
        browser_layer, )
Ejemplo n.º 21
0
def get_normalized_dxtypename(name):
    normalized_name = cc.snakecase(get_normalized_ftiname(name))
    return normalized_name
Ejemplo n.º 22
0
 def from_dict(data):
     return {snakecase(k):v for k, v in data.items()}
Ejemplo n.º 23
0
def translation_from_enum_assignment(enum_name, assignment):
    comments = [enum_name + "." + assignment.targets[0].id]
    translation = snakecase(enum_name) + "_" + snakecase(assignment.value.s)
    return assignment.lineno, 'gettext', translation, comments
Ejemplo n.º 24
0
def get_normalized_dxtypename(name):
    normalized_name = cc.snakecase(get_normalized_ftiname(name))
    return normalized_name
Ejemplo n.º 25
0
 def normalize_column(column):
     return case_conversion.snakecase(column)