Coverage for phml\virtual_python\__init__.py: 100%

3 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-30 09:38 -0600

1'''Virtual Python 

2 

3This module serves to solve the problem of processing python 

4in scopes and to evaluate python expressions. 

5 

6These expressions and scopes are python "blocks" that are injected 

7into html which then creates my language phml. 

8 

9Here are examples of the python blocks: 

10 

111. Python element. This is treated as python files similarly to how 

12`<script>` elements are treated as javascript files. 

13 

14```html 

15<python> 

16 from datetime import datetime 

17  

18 current_time = datetime.now().strftime('%H:%M:%S') 

19</python> 

20``` 

21 

222. Inline python block. Mainly used for retreiving values  

23or creating conditions. The local variables in the blocks are given 

24from the python elements and from kwargs passed to the parser 

25 

26```html 

27<p>{current_time}</p> 

28``` 

29 

303. Multiline python blocks. Same as inline python blocks just that they 

31take up multiple lines. You can write more logic in these blocks, but 

32there local variables are not retained. By default phml will return the last 

33local variable similar to how Jupyter or the python in cli works. 

34 

35```html 

36<p> 

37 Hello, everyone my name is {firstname}. I 

38 am a {work_position}. 

39<p> 

40<p>Here is a list of people and what they like</p> 

41<p> 

42 { 

43 result = [] 

44 for i, person, like in enumerate(zip(people, likes)): 

45 result.append(f"{i}. {person} likes {like}") 

46 result = "\\n".join(result) 

47 } 

48</p> 

49``` 

50''' 

51 

52from .ImportObjects import Import, ImportFrom 

53from .vp import VirtualPython, get_vp_result, process_vp_blocks 

54 

55__all__ = ["VirtualPython", "get_vp_result", "process_vp_blocks", "Import", "ImportFrom"]