Commits

Richard Shea committed 07b92f2

Significant clean up of the 006-demo-build-document-decorators-simple.py
so that it more closely matches the output of
005-demo-build-document-nested-div.py but using decorators. In addition
various generaly tidy-ups to make output better looking and code easier
to read

  • Participants
  • Parent commits 7d6228e

Comments (0)

Files changed (6)

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

 '''
 Demonstration of building complete document
 '''
+import os
+
 from dominate.document import document
 from dominate.tags import h1, p, link, div
 
-from demoutil import random_str_multiple 
-from demoutil import random_str 
+from demoutil import random_str_multiple
+
 
 def build_links(d):
     '''
 
     with container_div:
         #'header'
-        with div(id='header', cls='span-24'):
+        with div(cls='header span-24'):
             h1('Hello, Wellington NZPUG!')
+            p("Output of : " + os.path.basename(__file__), cls="smalltext")
 
         #'content'
-        with div(id='content', cls='span-24'):
+        with div(cls='content 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')
+        with div(cls='footer span-24'):
+            p('This is the footer', cls="smalltext")
 
     d.add(container_div)
 

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

 '''
 Demonstration of using decorators to create DOM elements
 '''
-from dominate.document import document
-from dominate.tags import h2, h1, p, link, div
-
-
-@div
-def greeting(name):
-    p('Hello %s' % name)
-print greeting('Bob in greeting')
-
-print ""
-print ""
-print ""
-
-@div(h1('Welcome'), cls='greeting1')
-def greeting1(name):
-    p('Hello %s' % name)
-
-
-@div(h2('Welcome'), p("I am para 1"), p("I am para 2"), cls='greeting2')
-def greeting2(name):
-    p('Hello %s' % name)
-
-
-@div(cls='header')
-def header(name):
-    h2('i am the header')
-
-@div(cls='container')
-def container(name):
-    p('i am the container')
+import os
 
-@div(cls='footer')
-def footer(name):
-    p('i am the footer')
-
-@div(cls='container')
-def mybody(name):
-    header("X")
-    container("X")
-    footer("X")
-    
-
-
-'''
-Demonstration of building complete document
-'''
 from dominate.document import document
 from dominate.tags import h1, p, link, div
 
-from demoutil import random_str_multiple 
-from demoutil import random_str 
+from demoutil import random_str_multiple
 
 
 def build_links(d):
     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')
+@div(cls='header span-24')
+def header():
+    h1('Hello, Wellington NZPUG!')
+    p("Output of : " + os.path.basename(__file__),
+      cls="smalltext",
+      style="text-decoration: underline")
 
-    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))
+@div(cls='content span-24')
+def content():
+    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
+@div(cls='footer span-24')
+def footer():
+    p("This is the footer", cls="smalltext")
 
 
 def build_document():
 
     d = document(title="NZPUG Demo - March 2014")
     d = build_links(d)
-    d = build_content(d)
+    with d.add(div(cls='container')):
+        header()
+        content()
+        footer()
 
     return d
 

dominate/examples/demoutil.py

 import random
 import string
 
+
 def random_str_multiple(word_count):
     '''
     Generate `word_count` random strings
     '''
     return "".join([random.choice(string.ascii_lowercase)
                    for x in xrange(letter_count)])
-
-

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

   </head>
   <body>
     <div class="container">
-      <div class="span-24" id="header">
+      <div class="header span-24">
         <h1>Hello, Wellington NZPUG!</h1>
+        <p class="smalltext">Output of : 005-demo-build-document-nested-div.py</p>
       </div>
-      <div class="span-24" id="content">
+      <div class="content span-24">
         <div class="span-10" id="left">
-          <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>
+          <p>dpl rskhyr ozd sf kyhe zlye eh huc ccx wzk rbxf nenilc nrxrp rtoe uos trhgja paagl glohup mxbq qhkv bwbnhv nbcc gmec btxjau ppf knf nqbeby juhcw nuu vdlb ocj oz zjbnqy fbuvn tb ziza npph rnhr bgnl tdbyce wxwz mhf djozaj puyqw rzflm yhb uzmr adxd pw jkyupr suwll tq sy yruhx tf bzlf yjkkov iqlt hrdle fj zagmp nuzbb jqli skbxin hu wwmvwj gvkois lftpe snjad ewmbb cx hzk iuzw zgz hrdkne wld kcu il xkno ael gkis vyk hlgykw jwt swtko itmjt zep kvw ch wvl xts omodja kh nqrsgy utensp kgtpk euyvxp aeycv fkh axit</p>
         </div>
         <div class="span-10 last" id="right">
-          <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>
+          <p>ry ohpazh hhdw viulm psdt cqghd mp zywf tldf obm ldjjep oxlivb pg ohz ihlnx eij vpigwf la boe gc jwab zplqy zyh bnaq zs jpxi yjqhq cfl izrd pili nm rr mwyl gn tng hl wcx kridc hx fhpsx wmq fgigvz hyua xbec qiii sh boxjdr lp bwmx ek llm zecbm vd bjcn zymcta tlpnb nn rj zfpbt fxmnyd dkysm cm hqnqit vvayol ntxjr kns ysq lwn yjnc httda pfhrcx agqe gyrmxg hgkhcd qclm emw ufgxq cg azvi wycmk zsedi sesh reaupu oympv xrp zhmh qvnjte ya upu ofxa qiq mkn kfpwxn lwvdfr fz xatz yrm pk ugew gbxal</p>
         </div>
       </div>
-      <div class="span-24" id="footer">
-        <p>This is the footer</p>
+      <div class="footer span-24">
+        <p class="smalltext">This is the footer</p>
       </div>
     </div>
   </body>

dominate/output/006.html

+<!DOCTYPE html>
+<html>
+  <head>
+    <title>NZPUG Demo - March 2014</title>
+    <link href="css/blueprint/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
+    <link href="css/blueprint/print.css" media="print" rel="stylesheet" type="text/css">
+    <link href="css/dmnt_demo_base0.css" media="screen, projection" rel="stylesheet" type="text/css">
+  </head>
+  <body>
+    <div class="container">
+      <div class="header span-24">
+        <h1>Hello, Wellington NZPUG!</h1>
+        <p class="smalltext" style="text-decoration: underline">Output of : 006-demo-build-document-decorators-simple.py</p>
+      </div>
+      <div class="content span-24">
+        <div class="span-10" id="left">
+          <p>tdws ynd kpsct alw mpzsk ssbp xx cxmrb fnl mcgwly cxn mjtui iad ygmxy qjzcb cul scl kitz guucg zwks mrtxv zglu qa qxi ijc odzlpl qepgej xppa lmlar ryzwkv llhkkv agxcj elcda gt fk zudix xla ektmx ebd cthymb def jzu sqaye cgsaj mva je gxp pulckv nog bdmi wrevhx wkcg ldj jih el st gwc cua nnnyu mvqkje gowrf xi wnbi bdhs wkl um bgqva wxvgw ausoj irw sx uwn fd cq fjqw ln bbl azvln lsfweh ishsjx uf hwrmo wqksfc az pba pukv fkur iwslt rucw gk gbs hj gbu ni ob ljjy phbxb iz sbw hrps</p>
+        </div>
+        <div class="span-10 last" id="right">
+          <p>mrlb pogyg mv daqufc icu xkckzg yiyonw bkov bajwf hbrief cfqnvp rupj crh zagz jdjdxn kguz omi twdcd exny nyinyt gm lb fh xc ypic qelng dzykyf ew dbe kdhsaw uuu slcjf qfckag jvfeik gzfwpe wnm zr fqk gazyb wz jb pvge skkvo ezgbcz eusg xxpwcu nluweo shpja ce pfqwy pvistf ktnf jzzpmu kodnpa kpj tgcep lrmfj apeza srspb lpnug wq rgjjd duedbn vmos zqslao wbf du bef wyf rmymeg sjh jalozm ekwt ec vmhq rlep wufha dh nhqlpg ex ps mqau nalx evza jezra mq fcvp os ddpzg mz nh qc dcgz kfj mzbup exfn un oagv fbjnj wxukea</p>
+        </div>
+      </div>
+      <div class="footer span-24">
+        <p class="smalltext">This is the footer</p>
+      </div>
+    </div>
+  </body>
+</html>

dominate/output/css/dmnt_demo_base0.css

       background: #6F6F94;
   }
 
-#header  { color:#FF9100; background-color:#6F6F94; padding:30px 0; text-align:center; }
-#footer  { color:#FF9100; background-color:#6F6F94; padding:30px 0; text-align:center; }
-#content { color:#FF9100; background-color:#6F6F94; padding-bottom:60px; }
+.header  { color:#FF9100; background-color:#6F6F94; padding:30px; text-align:center; }
+.footer  { color:#FF9100; background-color:#6F6F94; padding:30px 0; text-align:center; }
+.content { color:#FF9100; background-color:#6F6F94; padding-bottom:60px; }
 #sidebar { color:#FF9100; background-color:#6cc; padding-bottom:60px; }
 
 p {font-size:150%}
+.smalltext {font-size:1.2em}
 H1, H2, H3, P { color:#FF9100 }