Coverage for jinjazzle/ext/uuid.py: 100%

8 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-24 22:03 +0000

1""" 

2Description 

3----------- 

4 

5UUIDExtension provides the capability to generate UUID version 4 (UUID4) strings directly within your templates. 

6 

7 

8.. autoclass:: UUIDExtension 

9 

10 

11.. py:function:: uuid 

12 

13 Return a UUID string. 

14 

15 Available as a function. 

16 

17 .. code-block:: jinja 

18 

19 Generated UUID: {{ uuid() }} 

20""" 

21 

22import uuid as m_uuid 

23 

24from jinja2.ext import Extension 

25 

26 

27def _uuid(): 

28 """ 

29 Generate UUID4. 

30 """ 

31 return str(m_uuid.uuid4()) 

32 

33 

34# pylint: disable=abstract-method 

35class UUIDExtension(Extension): 

36 """ 

37 Jinja2 extension to generate uuid4 string. 

38 """ 

39 

40 def __init__(self, environment): 

41 """ 

42 Jinja2 Extension constructor. 

43 """ 

44 super().__init__(environment) 

45 

46 environment.globals.update(uuid=_uuid)