insert_above is integrated for adding js/css on the fly
[myslice.git] / devel / django-insert-above-1.0.4 / PKG-INFO
1 Metadata-Version: 1.0
2 Name: django-insert-above
3 Version: 1.0.4
4 Summary: These django templatetags is a hack making possible to insert "content" in some (maybe above the current or parent template) places.
5 Home-page: https://github.com/yunmanger1/django-insert-above/
6 Author: German Ilyin
7 Author-email: germanilyin@gmail.com
8 License: WTFPL
9 Description: WHAT IS IT?
10         -----------
11         
12         These templatetags is a hack making possible to insert 'content' in
13         some (maybe above the current or parent template) places.
14         
15         More specifically, when we use these tags, there are some Nodes called
16         'containers' that are rendered after all other nodes are rendered, but placed
17         in it's right posistion. Using this hack, 'containers' may render 
18         depending on variables in context that were generated by nodes placed anywhere in
19         template (maybe after it).
20         
21         It's very useful in cases when you are reusing some template parts
22         very often. For example displaying comment list and comment submit form.
23         We write some template and put it into comments.html. Then every time 
24         we need comments we just {% include "comments.html" %}.
25         But what if this part needs some js or css? Then we need to create 
26         some comments-jscss.html and override some {% block head %}. IMHO this
27         is quite inconvenient.
28         
29         Using this tool we can insert js and css into head 
30         directly from comments.html 
31         
32         MOTIVATION
33         ----------
34         
35         1. Create convenient way to include media resources in head of HTML page.
36         2. Handle repetition of resource includes.
37         3. Make it possible to require resources from included templates.
38         4. Keep the order of resource includes from different places.
39         
40         INSTALL
41         -------
42         
43         1. (required) add 'insert_above' in INSTALLED_APPS in your settings.py
44         
45         2. (optional) add these two lines of code somewhere in your project where
46         they will run for sure. For example in urls.py
47         
48         ~~~~
49         from django.template.loader import add_to_builtins
50         add_to_builtins('insert_above.templatetags.insert_tags')
51         ~~~~
52         
53         TAGS & FILTERS
54         --------------
55         
56         1. {% insert_handler %}
57         2. {% container name %}
58         3. {% media_container name %}
59         4. {% insert_str container str %}
60         5. {% insert container %}{% endinsert %}
61         6. media_tag filter simply converts `ga.js` into `<script type='text/javascript' src='/static/ga.js'></script>`
62         
63         RESTRICTIONS
64         ------------
65         
66         1. `{% container %}` or `{% media_container %}` tags must NOT be in other `{% block %}`.
67         2. `{% insert_handler %}` ought to be at ther very beginning of base template.
68         
69         VARIABLES
70         ---------
71         
72         1. `IA_USE_MEDIA_PREFIX`, by default True
73         2. `IA_MEDIA_PREFIX`, if not set `STATIC_URL` is used, if not set `MEDIA_URL` is used, if not set '/media/' is used
74         3. `DEBUG`, if True logs how much time spent on rendering
75         4. `IA_JS_FORMAT`, by default `<script type='text/javascript' src='{URL}'></script>`
76         5. `IA_CSS_FORMAT`, by default `<link rel='stylesheet' href='{URL}' type='text/css' />`
77         6. `IA_MEDIA_EXTENSION_FORMAT_MAP`, by default `{'css' : CSS_FORMAT, '.js' : JS_FORMAT}`
78         
79         EXAMPLE
80         -------
81         
82         Let's analyze an example. 
83         
84         base.html
85         
86         ~~~~{.html}
87         {% insert_handler %}
88         <html>
89         <head>
90         <script>
91         <script type='text/javascript' src='{{ MEDIA_URL }}js/jquery.min.js'></script> 
92         {% media_container media %}
93         
94         $(document).ready(function(){
95         {% container ready %}
96         });
97         </script>
98         </head>
99         <body>
100         {% block content %}
101         {% endblock %}
102         </body>
103         </html>
104         ~~~~
105         
106         Base template creating blocks and containers..
107         
108         blog/base.html
109         
110         ~~~~{.html}
111         {% extends "base.html" %}
112         
113         {% block content %}
114         {% insert_str media "js/mathjax.js" %}
115             {% block header %}{% endblock %}
116             {% block menu %}{% include "blog/menu.html" %}{% endblock %}
117             {% block text %}{% endblock %}
118             {% block footer %}{% endblock %}
119         {% endblock %}
120         ~~~~
121         
122         Extending content block. Requiring js/mathjax.js resource into 'media' container.
123         
124         blog/menu.html
125         
126         ~~~~{.html}
127         {% insert_str media "js/animated.menu.js" %}
128         {% insert_str media "css/animated.menu.css" %}
129         {% insert ready %}
130             $('ul.menu').each(function(){
131                 $(this).superanimation();
132             });
133         {% endinsert %}
134         <ul id='blog-menu' class='menu'>
135          <li>link</li>
136          <li>link</li>
137          <li>link</li>
138         </ul>
139         ~~~~
140         
141         Requiring js/animated.menu.js and css/animated.menu.css into "media" container.
142         Inserting javascript code into "ready" container.
143         
144         blog/post_detail.html
145         
146         ~~~~{.html}
147         {% extends "blog/base.html" %}
148         
149         {% block header %}{{ title }}{% endblock %}
150         
151         {% block text %}
152         {% insert_str media "js/mathjax.js" %}
153         {{ text }}
154         {% endblock %}
155         
156         {% block footer %}
157         <hr>
158         {% endblock %}
159         ~~~~
160         
161         Implementing blocks and requiring js/mathjax.js into media.
162         
163         
164         So if we render 
165         Template('blog/post_detail.html').render(Context({'title': 'Hello', 'text': 'World'}))
166         we will get:
167         
168         ~~~~{.html}
169         <html>
170         <head>
171         <script>
172         <script type='text/javascript' src='/media/js/jquery.min.js'></script> 
173         <script type='text/javascript' src='/media/js/mathjax.js'></script>
174         <script type='text/javascript' src='/media/js/animated.menu.js'></script>
175         <link rel="stylesheet" href="/media/css/animated.menu.css" type="text/css" />
176         
177         $(document).ready(function(){
178             $('ul.menu').each(function(){
179                 $(this).superanimation();
180             });
181         });
182         </script>
183         </head>
184         <body>
185         Hello
186         <ul id='blog-menu' class='menu'>
187          <li>link</li>
188          <li>link</li>
189          <li>link</li>
190         </ul>
191         World
192         <hr>
193         </body>
194         </html>
195         ~~~~
196         
197         What shall be noted?
198         -------------------
199         
200         1. `js/mathjax.js` automatically becomes `<script type='text/javascript' src='/media/js/mathjax.js'></script>`
201         and `css/animated.menu.css` becomes `<link rel="stylesheet" href="/media/css/animated.menu.css" type="text/css" />`
202         2. inserting from included template is possible
203         3. any text may be inserted to any container. Here we insert javascript code in  `$(document).ready(function(){});`
204         4. `js/mathjax.js` was required twice, but included only once.
205         5. The order of included resources is kept.
206         
207         FIXTURES
208         --------
209         
210         ### version 1.0.2
211         
212          + **fix MEDIA_URL setting**
213          if STATIC_URL is not set in settings, it's value is None by default in new versions of Django.
214          Now we check if STATIC_URL is None, then use MEDIA_URL
215         
216         ### version 1.0.4
217         
218          + added new tag `{% insert_form container form %}`
219          + added new tag `{% insert_form container form.media %}`
220         
221         ## TODOs
222         
223         1. testing
224         2. extending tags
225         3. resource bulking
226         
227         
228 Platform: UNKNOWN
229 Classifier: Development Status :: 3 - Alpha
230 Classifier: Topic :: Utilities
231 Classifier: Environment :: Plugins
232 Classifier: Framework :: Django
233 Classifier: Intended Audience :: Developers
234 Classifier: License :: Freeware
235 Classifier: Programming Language :: Python :: 2.6