Completed
Push — master ( 376d77...59bfb2 )
by
unknown
01:07
created

HelloExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A _hello() 0 2 1
A parse() 0 5 1
A __init__() 0 2 1
1
# -*- coding: utf-8 -*-
2
3
from jinja2 import nodes
4
from jinja2.ext import Extension
5
6
7
class HelloExtension(Extension):
8
    tags = set(['hello'])
9
10
    def __init__(self, environment):
11
        super(HelloExtension, self).__init__(environment)
12
13
    def _hello(self, name):
14
        return 'Hello {name}!'.format(name=name)
15
16
    def parse(self, parser):
17
        lineno = next(parser.stream).lineno
18
        node = parser.parse_expression()
19
        call_method = self.call_method('_hello', [node], lineno=lineno)
20
        return nodes.Output([call_method], lineno=lineno)
21