hello_extension.hello_extension   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 14
dl 0
loc 25
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A HelloExtension.parse() 0 6 1
A HelloExtension._hello() 0 3 1
A HelloExtension.__init__() 0 3 1
1
"""Provides custom extension, exposing a ``hello`` command."""
2
from jinja2 import nodes
3
from jinja2.ext import Extension
4
5
6
class HelloExtension(Extension):
7
    """Simple jinja2 extension for cookiecutter test purposes."""
8
9
    tags = {'hello'}
10
11
    def __init__(self, environment):
12
        """Hello Extension Constructor."""
13
        super().__init__(environment)
14
15
    def _hello(self, name):
16
        """Do actual tag replace when invoked by parser."""
17
        return f'Hello {name}!'
18
19
    def parse(self, parser):
20
        """Work when something match `tags` variable."""
21
        lineno = next(parser.stream).lineno
22
        node = parser.parse_expression()
23
        call_method = self.call_method('_hello', [node], lineno=lineno)
24
        return nodes.Output([call_method], lineno=lineno)
25