Coverage for khufu/buttons/button.py : 88%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# encoding: utf-8
2from . import *
4def button(
5 buttonText="",
6 buttonStyle="default",
7 buttonSize="default",
8 htmlId=False,
9 htmlClass=False,
10 href=False,
11 pull=False,
12 submit=False,
13 block=False,
14 disable=False,
15 dataToggle=False,
16 popover=False,
17 postInBackground=False,
18 notification=False,
19 close=False,
20 formId=False):
21 """
22 *Generate a button - TBS style*
24 **Key Arguments**
26 - ``buttonText`` -- the text to display on the button
27 - ``buttonStyle`` -- the style of the button required [ default | primary | info | success | warning | danger | inverse | link ]
28 - ``buttonSize`` -- the size of the button required [ large | small | mini ]
29 - ``htmlId`` -- the htmlId for the button
30 - ``href`` -- link the button to another location?
31 - ``pull`` -- left, right or center
32 - ``submit`` -- set to true if a form button [ true | false ]
33 - ``block`` -- create block level buttons—those that span the full width of a parent [ True | False ]
34 - ``disable`` -- this class is only for aesthetic; you must use custom JavaScript to disable links here
35 - ``dataToggle`` -- for use with js to launch, for example, a modal
38 - ``popover`` -- add a popover element for this button
40 **Return**
42 - ``button`` -- the button
44 """
45 if buttonStyle == "default":
46 buttonStyle = ""
47 else:
48 buttonStyle = "btn-%(buttonStyle)s" % locals()
50 if htmlClass is False:
51 htmlClass = ""
53 if buttonSize == "default":
54 buttonSize = ""
55 else:
56 buttonSize = "btn-%(buttonSize)s" % locals()
58 if notification is False:
59 notification = ""
60 else:
61 notification = """notification="%(notification)s" """ % locals()
63 if block is True:
64 block = "btn-block"
65 else:
66 block = ""
68 if postInBackground is True:
69 postInBackground = "postInBackground"
70 else:
71 postInBackground = ""
73 if disable is True:
74 disable = "disabled"
75 else:
76 disable = ""
78 if submit is True:
79 ttype = "submit"
80 else:
81 ttype = "button"
83 if formId is False:
84 formId = ""
85 else:
86 formId = """formId="%(formId)s" """ % locals()
88 if close is False:
89 close = ""
90 dismiss = ""
91 else:
92 close = "close"
93 dismiss = 'data-dismiss="modal"'
95 if not dataToggle:
96 dataToggle = ""
97 else:
98 dataToggle = """data-toggle="%(dataToggle)s" """ % locals()
100 if href:
101 elementOpen = """a href="%(href)s" type="%(ttype)s" """ % locals()
102 elementClose = """a"""
103 else:
104 elementOpen = """button type="%(ttype)s" """ % locals()
105 elementClose = """button"""
107 if htmlId == False:
108 htmlId = ""
110 if pull == False:
111 pull = ""
112 else:
113 pull = "pull-%(pull)s" % locals()
115 if popover is False:
116 popover = ""
118 if len(dataToggle):
119 popover = popover.replace("data-toggle", "rel")
121 button = """<%(elementOpen)s class="%(htmlClass)s btn %(close)s %(buttonStyle)s %(buttonSize)s %(block)s %(disable)s %(pull)s %(postInBackground)s" %(popover)s id="%(htmlId)s" %(formId)s %(dataToggle)s %(dismiss)s %(notification)s>%(buttonText)s</%(elementClose)s>""" % locals()
123 return button