Commits

Richard Shea  committed 7d6228e

Move some standard code into its own module and tidy up .

  • Participants
  • Parent commits 1888dd9

Comments (0)

Files changed (4)

File dominate/examples/005-demo-build-document-nested-div.py

 from dominate.document import document
 from dominate.tags import h1, p, link, div
 
-import random
-import string
-
-
-def random_str_multiple(word_count):
-    '''
-    Generate `word_count` random strings
-    '''
-    l = []
-    for i in range(word_count):
-        l.append(random_str(random.randrange(2, 7)))
-    return ' '.join(l)
-
-
-def random_str(letter_count):
-    '''
-    Generate a random string of length `letter_count`
-    '''
-    return "".join([random.choice(string.ascii_lowercase)
-                   for x in xrange(letter_count)])
-
+from demoutil import random_str_multiple 
+from demoutil import random_str 
 
 def build_links(d):
     '''

File dominate/examples/006-demo-build-document-decorators-simple.py

 
 
 '''
-print greeting1('Bob in greeting1')
-print greeting2('Bobette in greeting2')
-print greeting3('Fred in greeting3')
+Demonstration of building complete document
 '''
-print mybody("test")
+from dominate.document import document
+from dominate.tags import h1, p, link, div
+
+from demoutil import random_str_multiple 
+from demoutil import random_str 
+
+
+def build_links(d):
+    '''
+    Take the `document` object and add some links to
+    style sheets we want available when the page is
+    served
+    '''
+    d.head += link(rel="stylesheet", href="css/blueprint/screen.css",
+                   type="text/css", media="screen, projection")
+    d.head += link(rel="stylesheet", href="css/blueprint/print.css",
+                   type="text/css",  media="print")
+    d.head += link(rel="stylesheet", href="css/dmnt_demo_base0.css",
+                   type="text/css", media="screen, projection")
+    return d
+
+
+def build_content(d):
+    '''
+    Take the `document` object, build a `container` div and nested within that
+    build a series of divs some of which themselves have nested divs and all of
+    which have content of some sort
+    '''
+    container_div = div(cls='container')
+
+    with container_div:
+        #'header'
+        with div(id='header', cls='span-24'):
+            h1('Hello, Wellington NZPUG!')
+
+        #'content'
+        with div(id='content', cls='span-24'):
+            with div(id='left', cls='span-10'):
+                p(random_str_multiple(100))
+            with div(id='right', cls='span-10 last'):
+                p(random_str_multiple(100))
+
+        #'footer'
+        with div(id='footer', cls='span-24'):
+            p('This is the footer')
+
+    d.add(container_div)
+
+    return d
+
+
+def build_document():
+
+    d = document(title="NZPUG Demo - March 2014")
+    d = build_links(d)
+    d = build_content(d)
+
+    return d
+
+
+def main():
+    print build_document()
+
+if __name__ == '__main__':
+    main()

File dominate/examples/demoutil.py

+'''
+Some functions which are common a number of the demos
+and which aren't anything directly to do with the use
+of dominate
+'''
+import random
+import string
+
+def random_str_multiple(word_count):
+    '''
+    Generate `word_count` random strings
+    '''
+    l = []
+    for i in range(word_count):
+        l.append(random_str(random.randrange(2, 7)))
+    return ' '.join(l)
+
+
+def random_str(letter_count):
+    '''
+    Generate a random string of length `letter_count`
+    '''
+    return "".join([random.choice(string.ascii_lowercase)
+                   for x in xrange(letter_count)])
+
+

File dominate/output/005-demo-build-document-nested-div.html

       </div>
       <div class="span-24" id="content">
         <div class="span-10" id="left">
-          <p>omj fipfql zf dlsvu blmm qlbhqn wt jf daysue egsmde kc vjuqsg lmmnbr pnx stkmf mz hxclwf aviaxw rqigpa gsts vtgxl eev oxlsht dgjy vy bh beu ulhqa pjse ztedbc zg zhoci agsgy robm twtygb bym qx ttrb asa xh btmgex kg vropdv cwvdpk qxfrlv sq mo kq itpajc ypxsas zz cnabt lq gadxmv emdusr bw hnvpkx rwge efu lvftrq fr joa kc rbwrxj mpiuw lg gatql dphw bput qroezk xr wbcx gi rgbt cymiu tdjl ot mq tg kv az lu cv verun czbdm zhhyj qb aojud nh ry fo swvr oi tysf tovy zxoyvo xoha var mcnlvi zm</p>
+          <p>ic xcqi pjg awle ik geqblg uep jzyrt ofoadi ve hm ccniz rnj xw rlbp tbmf jzmp zg wyntfs wro pob exc asi reg epzsip uwxam drcqu zv oqedq brg er zb haw oh cbmi zb aek woa bd fayqjk gmp gw dlo tm ymb ej sv hz fxtd yn zlnvee reup gylqn dzi zqtjjx qah ukmnh jit cdzqns cd ibv bchd ez yh lqh zrvul sgtxi ejoibg gs hhhum uignwf ceaesr iopt ve nzf yksa bk pkaer yhb nfqeyx xmasx hkjy mxl cgf yftmwi zeg bfbqh wz dd hqmdly pde qen hw scn cwzxm rwha hpe qw iaarm tecjnw</p>
         </div>
         <div class="span-10 last" id="right">
-          <p>ortgnu otfvh tc dng qiuw xn ts ht mgvnr hoqy loff ba ix lvclw nt tku ax cfn kgqaqn ecjk jkjm rpfqnj hpwk wuvnpe bs mk sfns zizkkp oncwz bsg esnc rhxop desd qonf aybdws uxwbl gewsd zzl np ebyw wropk ce fxvmpx iydg oxheii jrdx cfjjr bigvrd jxj vdhis lrcno oouk bshg ghgfe lszn qhjfdn pl dvur dvc xzvfo kccmus fi gmpy coues jivm otwbxi fgx jkg sn pracoe otes gp bqweca ulluur ybc unzasr rm xvlne jipth zjibp cubgh yh kzhgk xasen mm ibmf mordhd beqvl ja olbask cvypvh rdh jtt mklofy vj vgssaq afipz bdpmq rtcv jdcp</p>
+          <p>gpbplk vasjui mt vpwx eepxq keu ywnfuv btvb hzduw ot zkug uppb pu gvffi xxt yangzj kbwav fyyr dfbhmu fmz vveq awltmd bezdhu gduib fsjf bui jh lp zlbp lxet pkay ztbtbh apvnq ojyssm bpp ajd xva ligv gmlqf wnf qoia psoj ynkg muyqa qw gfaqa vg ybjoo tmupsl nrdfyw wvkwwq uiykv vuqv eqr gps jvd unmgo hob kqvi zokkjr xqe go syj gw txdr ynpzie ron jokgy uu mizu mblv ov ai iqmkr xskeb kdvqft cm vyory cvzvil lnh nes botc rnvwn boepn ck uvffm hzjkyz njgze tw so try vsry zxcinq brls dcyzwx axqsq uvmg agecuk wf wrcabv</p>
         </div>
       </div>
       <div class="span-24" id="footer">