# example9_inheritance - funcyTags can inherit options from other funcy tags

import os, sys; sys.path.append(os.path.dirname(os.path.abspath(__file__))+os.sep+'..')

from lib.funcytag import funcyTag

div=funcyTag('div'); ul=funcyTag('ul'); li=funcyTag('li',{'_nobrin':True})
span=funcyTag('span',{'_nobrout':True,'_nobrin':True})

good_li = funcyTag( li, {'cssColor':'green'} )
bad_li = funcyTag( li, {'cssColor':'red'} )
green = funcyTag( span, {'cssColor':'green'} )
red = funcyTag( span, {'cssColor':'red'} )
big = funcyTag( span, {'cssFontSize_pct':150} )

def build_example_html():
    t = div(
          'foods: ' + str(green(big('L'),'ike')) + ', ',
          red(big('H'),'ate'), ',', 'or ',big('I'),'ndifferent',
          ul(
            li('rice'),
            bad_li('okra'),
            good_li('pizza'),
            good_li('ice cream'),
            bad_li({'cssFontStyle':'italic'},'dog poop'),
            li('chicken')
          )
        )
    return unicode(t)

if __name__ == "__main__":
Beispiel #2
0
# example10_esc - escaping text strings - using funcyTag.esc() for strings that may contain html characters

import os, sys; sys.path.append(os.path.dirname(os.path.abspath(__file__))+os.sep+'..')

from lib.funcytag import funcyTag

div=funcyTag('div'); p=funcyTag('p'); input=funcyTag('input'); br=funcyTag('br')
esc = funcyTag.esc

def build_example_html():
    t = div(
          p( "the following math equation has less-than and greater-than signs:",
             esc(' a<b>c')
          ),
          br(),
          'weird characters in value',input({'type':'input','value':esc('"dog" & "pony"')})
        )
    return unicode(t)

if __name__ == "__main__":
    print
    print build_example_html()
    print
# example7_default_attributes - create new tags with default attributes (such as <good_li> and <bad_li>)

import os, sys; sys.path.append(os.path.dirname(os.path.abspath(__file__))+os.sep+'..')

from lib.funcytag import funcyTag

div=funcyTag('div'); ul=funcyTag('ul'); li=funcyTag('li'); span=funcyTag('span')

# create a good_li tag that is a green <li>, and bad_li tag that is red
good_li = funcyTag( 'li', {'cssColor':'green'} )
bad_li = funcyTag( 'li', {'cssColor':'red'} )

def build_example_html():
    t = div({},
          'foods: ', span({'cssColor':'green'},'like,'), span({'cssColor':'red'},'hate,'), 'or indifferent',
          ul({},
            li({},'rice'),
            bad_li({},'okra'),
            good_li({},'pizza'),
            good_li({},'ice cream'),
            bad_li({},'dog poop'),
            li({},'chicken')
          )
        )
    return unicode(t)

if __name__ == "__main__":
    print
    print build_example_html()
    print
# example6_array_contents - contents of a tag may include arrays (each element is a child)

import os, sys; sys.path.append(os.path.dirname(os.path.abspath(__file__))+os.sep+'..')

from lib.funcytag import funcyTag

div=funcyTag('div'); p=funcyTag('P')

def count_to_ten():
    ret = []
    for i in range(0,11):
        ret.append(i)
    return ret

def build_example_html():
    t = div({},
          p({},'regular paragraph 1'),
          [ p({},'Paragraph 1 in array'), None, p({},'Paragraph 2 in array'), p({},'Paragraph 3 in array') ],
          p({},'regular paragraph 2'),
          [ ],  # empty array results in nothing
          p({},'regular paragraph 3'),
          count_to_ten(),
          p({},'regular paragraph 4')
        )
    return unicode(t)

if __name__ == "__main__":
    print
    print build_example_html()
    print
# example1_funcytag_intro - demonstrate very basic use of Tags as Functions
#
# FuncyTag replaces html with a python-like syntax

import os, sys; sys.path.append(os.path.dirname(os.path.abspath(__file__))+os.sep+'..')

from lib.funcytag import funcyTag

p=funcyTag('P')

def build_example_html():
    t = p( { 'id':'outty', 'style':'font-size:200%;color:red;' },
           "I'm a little teacup, short and stout."
        )
    return unicode(t)

if __name__ == "__main__":
    print
    print build_example_html()
    print
# example2_children - child elements are embedded parameters, encouraging html-like indentation

import os, sys; sys.path.append(os.path.dirname(os.path.abspath(__file__))+os.sep+'..')

from lib.funcytag import funcyTag

div=funcyTag('div')

def build_example_html():
    t = div( dict( id='outer', style='font-size:20px;color:red;' ),
          'begin outer div',
          div( dict( id='middle', style='font-size:16px;color:green;margin-left:12px;' ),
            'begin middle div',
            div( dict( id='inner', style='font-size:12px;color:blue;margin-left:12px;' ),
              'center div'
            ),
            'end middle div'
          ),
          'end outer div'
        )
    return unicode(t)

if __name__ == "__main__":
    print
    print build_example_html()
    print