Changeset 4857
- Timestamp:
- 03/29/07 20:50:06 (2 years ago)
- Files:
-
- django/trunk/django/contrib/webdesign (added)
- django/trunk/django/contrib/webdesign/__init__.py (added)
- django/trunk/django/contrib/webdesign/lorem_ipsum.py (added)
- django/trunk/django/contrib/webdesign/templatetags (added)
- django/trunk/django/contrib/webdesign/templatetags/__init__.py (added)
- django/trunk/django/contrib/webdesign/templatetags/webdesign.py (added)
- django/trunk/django/template/defaulttags.py (modified) (6 diffs)
- django/trunk/docs/templates.txt (modified) (1 diff)
- django/trunk/docs/webdesign.txt (added)
- django/trunk/tests/regressiontests/templates/tests.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/template/defaulttags.py
r4848 r4857 141 141 compare_to = self.nodelist.render(context) 142 142 except VariableDoesNotExist: 143 compare_to = None 143 compare_to = None 144 144 145 145 if compare_to != self._last_seen: … … 281 281 return '' 282 282 283 class LoremNode(Node):284 def __init__(self, count, method, common):285 self.count, self.method, self.common = count, method, common286 287 def render(self, context):288 from django.utils.lorem_ipsum import words, paragraphs289 try:290 count = int(self.count.resolve(context))291 except (ValueError, TypeError):292 count = 1293 if self.method == 'w':294 return words(count, common=self.common)295 else:296 paras = paragraphs(count, common=self.common)297 if self.method == 'p':298 paras = ['<p>%s</p>' % p for p in paras]299 return '\n\n'.join(paras)300 301 283 class NowNode(Node): 302 284 def __init__(self, format_string): … … 339 321 self.args = args 340 322 self.kwargs = kwargs 341 323 342 324 def render(self, context): 343 325 from django.core.urlresolvers import reverse, NoReverseMatch … … 788 770 789 771 #@register.tag 790 def lorem(parser, token):791 """792 Creates random latin text useful for providing test data in templates.793 794 Usage format::795 796 {% lorem [count] [method] [random] %}797 798 ``count`` is a number (or variable) containing the number of paragraphs or799 words to generate (default is 1).800 801 ``method`` is either ``w`` for words, ``p`` for HTML paragraphs, ``b`` for802 plain-text paragraph blocks (default is ``b``).803 804 ``random`` is the word ``random``, which if given, does not use the common805 paragraph (starting "Lorem ipsum dolor sit amet, consectetuer...").806 807 Examples:808 * ``{% lorem %}`` will output the common "lorem ipsum" paragraph809 * ``{% lorem 3 p %}`` will output the common "lorem ipsum" paragraph810 and two random paragraphs each wrapped in HTML ``<p>`` tags811 * ``{% lorem 2 w random %}`` will output two random latin words812 """813 bits = list(token.split_contents())814 tagname = bits[0]815 # Random bit816 common = bits[-1] != 'random'817 if not common:818 bits.pop()819 # Method bit820 if bits[-1] in ('w', 'p', 'b'):821 method = bits.pop()822 else:823 method = 'b'824 # Count bit825 if len(bits) > 1:826 count = bits.pop()827 else:828 count = '1'829 count = parser.compile_filter(count)830 if len(bits) != 1:831 raise TemplateSyntaxError, "Incorrect format for %r tag" % tagname832 return LoremNode(count, method, common)833 lorem = register.tag(lorem)834 835 #@register.tag836 772 def now(parser, token): 837 773 """ … … 981 917 def url(parser, token): 982 918 """ 983 Returns an absolute URL matching given view with its parameters. 984 919 Returns an absolute URL matching given view with its parameters. 920 985 921 This is a way to define links that aren't tied to a particular URL configuration:: 986 922 987 923 {% url path.to.some_view arg1,arg2,name1=value1 %} 988 924 989 925 The first argument is a path to a view. It can be an absolute python path 990 926 or just ``app_name.view_name`` without the project name if the view is … … 995 931 For example if you have a view ``app_name.client`` taking client's id and 996 932 the corresponding line in a URLconf looks like this:: 997 933 998 934 ('^client/(\d+)/$', 'app_name.client') 999 935 1000 936 and this app's URLconf is included into the project's URLconf under some 1001 937 path:: 1002 938 1003 939 ('^clients/', include('project_name.app_name.urls')) 1004 940 1005 941 then in a template you can create a link for a certain client like this:: 1006 942 1007 943 {% url app_name.client client.id %} 1008 944 1009 945 The URL will look like ``/clients/client/123/``. 1010 946 """ django/trunk/docs/templates.txt
r4848 r4857 625 625 626 626 See `Custom tag and filter libraries`_ for more information. 627 628 lorem629 ~~~~~630 631 Display random latin text useful for providing sample data in templates.632 633 Usage format: ``{% lorem [count] [method] [random] %}``634 635 =========== =============================================================636 Argument Description637 =========== =============================================================638 ``count`` A number (or variable) containing the number of paragraphs or639 words to generate (default is 1).640 ``method`` Either ``w`` for words, ``p`` for HTML paragraphs or ``b``641 for plain-text paragraph blocks (default is ``b``).642 ``random`` The word ``random``, which if given, does not use the common643 paragraph ("Lorem ipsum dolor sit amet...") when generating644 text.645 646 Examples:647 648 * ``{% lorem %}`` will output the common "lorem ipsum" paragraph.649 * ``{% lorem 3 p %}`` will output the common "lorem ipsum" paragraph650 and two random paragraphs each wrapped in HTML ``<p>`` tags.651 * ``{% lorem 2 w random %}`` will output two random latin words.652 627 653 628 now django/trunk/tests/regressiontests/templates/tests.py
r4847 r4857 150 150 # Dictionary lookup wins out when there is a string and int version of the key. 151 151 'list-index07': ("{{ var.1 }}", {"var": {'1': "hello", 1: "world"}}, "hello"), 152 152 153 153 # Basic filter usage 154 154 'basic-syntax21': ("{{ var|upper }}", {"var": "Django is the greatest!"}, "DJANGO IS THE GREATEST!"), … … 655 655 'with02': ('{{ key }}{% with dict.key as key %}{{ key }}-{{ dict.key }}-{{ key }}{% endwith %}{{ key }}', {'dict': {'key':50}}, ('50-50-50', 'INVALID50-50-50INVALID')), 656 656 657 ### LOREM TAG ######################################################658 'lorem01': ('{% lorem %}', {}, 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'),659 'lorem02': ('{% lorem p %}', {}, '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>'),660 'lorem03': ('{% lorem 6 w %}', {}, 'lorem ipsum dolor sit amet consectetur'),661 662 657 ### NOW TAG ######################################################## 663 658 # Simple case
