peritus / django_templatecomponents

A django application that makes it easy organize your component source (javascript, css) right in your django templates to to make your website much faster.

This URL has Read+Write access

django_templatecomponents / tests.py
100644 60 lines (58 sloc) 1.974 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'''
>>> from django.conf import settings
>>> from templatecomponents import TemplateComponentBlock
>>> TemplateComponentBlock.from_string("{% css %} foo. {% endcss %}")[0]
/* extracted css */
foo.
>>> TemplateComponentBlock.from_string("{% javascript %} foo. {% endjavascript %}")[0]
/* extracted javascript */
foo.
>>> TemplateComponentBlock.from_string("{% javascript 1 %} foo. {% endjavascript %}")[0]
/* extracted javascript with priority 1 */
foo.
>>> TemplateComponentBlock.from_string("{% javascript eggs 1 %} foo. {% endjavascript %}")[0]
/* extracted javascript with priority 1 with groups eggs */
foo.
>>> TemplateComponentBlock.from_string("{% javascript 1 eggs %} foo. {% endjavascript %}")[0]
/* extracted javascript with priority 1 with groups eggs */
foo.
>>> TemplateComponentBlock.from_string("{% javascript bar %} foo. {% endjavascript %}")[0]
/* extracted javascript with groups bar */
foo.
>>> TemplateComponentBlock.from_string("""
... {% javascript bar %} foo. {% endjavascript %}
... bar
... {% javascript bar %} foo. {% endjavascript %}
... """)
/* extracted javascript with groups bar */
foo.
/* extracted javascript with groups bar */
foo.
>>> #
>>> #
>>> #
>>> #
>>> #
>>> complexexample = """
... {% javascript baz %} x += 1; {% endjavascript %}
... {% javascript bar 10 %} var x = 1; {% endjavascript %}
... {% css print %} var x = 1; {% endcss %}
... <h1>Foo</h1>
... """
>>> #simple filter:
>>> TemplateComponentBlock.from_string(complexexample).filter('css')
/* extracted css with groups print */
var x = 1;
>>> #filter + priority
>>> TemplateComponentBlock.from_string(complexexample).filter('javascript')
/* extracted javascript with priority 10 with groups bar */
var x = 1;
/* extracted javascript with groups baz */
x += 1;
>>> TemplateComponentBlock.from_string(complexexample).filter('javascript').group('baz')
/* extracted javascript with groups baz */
x += 1;
'''
 
if __name__ == "__main__":
    import doctest
    doctest.testmod()