|
1 | | -from templater import button, div |
| 1 | +""" |
| 2 | +Helper for Bootstrap 4.3 |
| 3 | +""" |
| 4 | + |
| 5 | +from templater import ( |
| 6 | + html, |
| 7 | + head, |
| 8 | + meta, |
| 9 | + body, |
| 10 | + link, |
| 11 | + title as t, |
| 12 | + script, |
| 13 | + div, |
| 14 | + h1, |
| 15 | + blockquote, |
| 16 | + footer, |
| 17 | +) |
2 | 18 | from templater.utils import classing |
3 | 19 |
|
4 | 20 |
|
5 | | -def container(*args, breakpoint=''): |
| 21 | +RESPONSIVE_BP = ["xs", "sm", "md", "lg", "xl"] |
| 22 | + |
| 23 | + |
| 24 | +def starter(*args, **kwargs): |
| 25 | + """ |
| 26 | + Starter Template |
| 27 | + """ |
| 28 | + |
| 29 | + BOOTSTRAP_CSS = ( |
| 30 | + "https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" |
| 31 | + ) |
| 32 | + INTEGRITY_BSCSS = ( |
| 33 | + "sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" |
| 34 | + ) |
| 35 | + |
| 36 | + POPPER_JS = ( |
| 37 | + "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.15.0/umd/popper.min.js" |
| 38 | + ) |
| 39 | + INTEGRITY_POJS = ( |
| 40 | + "sha384-L2pyEeut/H3mtgCBaUNw7KWzp5n9+4pDQiExs933/5QfaTh8YStYFFkOzSoXjlTb" |
| 41 | + ) |
| 42 | + |
| 43 | + BOOTSTRAP_JS = ( |
| 44 | + "https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" |
| 45 | + ) |
| 46 | + INTEGRITY_BSJS = ( |
| 47 | + "sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" |
| 48 | + ) |
| 49 | + |
| 50 | + title = kwargs.pop("title", "Document") |
| 51 | + additional_head = kwargs.pop("in_head", []) |
| 52 | + |
| 53 | + component = html(lang="en")( |
| 54 | + head( |
| 55 | + meta(charset="utf-8"), |
| 56 | + meta(name="viewport", content="width=device-width, initial-scale=1"), |
| 57 | + link( |
| 58 | + rel="stylesheet", |
| 59 | + href=BOOTSTRAP_CSS, |
| 60 | + integrity=INTEGRITY_BSCSS, |
| 61 | + crossorigin="anonymous", |
| 62 | + ), |
| 63 | + *additional_head, |
| 64 | + t(title), |
| 65 | + ), |
| 66 | + body( |
| 67 | + *args, |
| 68 | + script(src=POPPER_JS, integrity=INTEGRITY_POJS, crossorigin="anonymous"), |
| 69 | + script(src=BOOTSTRAP_JS, integrity=INTEGRITY_BSJS, crossorigin="anonymous"), |
| 70 | + ), |
| 71 | + ) |
| 72 | + |
| 73 | + return component |
| 74 | + |
| 75 | + |
| 76 | +# Layout |
| 77 | + |
| 78 | + |
| 79 | +def container(breakpoint="", **kwargs): |
| 80 | + """ |
| 81 | + >>> c = container("md")( |
| 82 | + ... 'text' |
| 83 | + ... ) |
| 84 | + >>> c.render() |
| 85 | + <div class="container-md">text<div/> |
| 86 | + """ |
| 87 | + |
6 | 88 | if breakpoint: |
7 | | - breakpoint = '-' + breakpoint |
| 89 | + if breakpoint in RESPONSIVE_BP + "fluid": |
| 90 | + breakpoint = "-" + breakpoint |
| 91 | + else: |
| 92 | + print(f'Breakpoint should be one of {RESPONSIVE_BP} or "fluid') |
| 93 | + breakpoint = "" |
| 94 | + |
| 95 | + c = kwargs.pop("_class", []) |
| 96 | + c = classing("container" + breakpoint, *c) |
| 97 | + |
| 98 | + return div(_class=c, **kwargs) |
| 99 | + |
| 100 | + |
| 101 | +def row(*args, **kwargs): |
| 102 | + """ |
| 103 | + >>> c = row('text') |
| 104 | + >>> c.render() |
| 105 | + <div class="row">text<div/> |
| 106 | + """ |
| 107 | + |
| 108 | + c = kwargs.pop("_class", []) |
| 109 | + c = classing("row", *c) |
| 110 | + |
| 111 | + return div(_class=c, **kwargs)(*args) |
| 112 | + |
| 113 | + |
| 114 | +def col(breakpoint="", **kwargs): |
| 115 | + """ |
| 116 | + >>> c = col("md-6")( |
| 117 | + ... 'text' |
| 118 | + ... ) |
| 119 | + >>> c.render() |
| 120 | + <div class="col-md-6">text<div/> |
| 121 | + """ |
| 122 | + |
| 123 | + if breakpoint: |
| 124 | + breakpoint = "-" + breakpoint |
| 125 | + |
| 126 | + c = kwargs.pop("_class", []) |
| 127 | + c = classing("col" + breakpoint, *c) |
| 128 | + |
| 129 | + return div(_class=c, **kwargs) |
| 130 | + |
| 131 | + |
| 132 | +# typography |
| 133 | + |
| 134 | + |
| 135 | +def display(n=1, **kwargs): |
| 136 | + """ |
| 137 | + >>> c = display(3)('text') |
| 138 | + >>> c.render() |
| 139 | + <h1 class="display-3">text<h1/> |
| 140 | + """ |
| 141 | + |
| 142 | + if n < 1 or n > 4: |
| 143 | + print('"n" should be between 1 - 4') |
| 144 | + |
| 145 | + c = kwargs.pop("_class", []) |
| 146 | + c = classing("display-" + n, *c) |
| 147 | + |
| 148 | + return h1(_class=c, **kwargs) |
8 | 149 |
|
9 | | - return div(*args, _class=f"container{breakpoint}") |
10 | 150 |
|
| 151 | +def lead(*args, **kwargs): |
| 152 | + """ |
| 153 | + >>> c = lead('text') |
| 154 | + >>> c.render() |
| 155 | + <p class="lead">text<p/> |
| 156 | + """ |
11 | 157 |
|
12 | | -def alert(*args): |
13 | | - return div(*args, _class=["alert", "alert-primary"], role="alert") |
| 158 | + c = kwargs.pop("_class", []) |
| 159 | + c = classing("lead", *c) |
14 | 160 |
|
| 161 | + return div(_class=c, **kwargs)(*args) |
15 | 162 |
|
16 | | -def btn(*args, color="primary", block=False, **kwargs): |
17 | | - _class = kwargs.pop('_class', []) |
18 | 163 |
|
19 | | - c = ["btn", f"btn-{color}"] |
| 164 | +def quote(author='', **kwargs): |
| 165 | + class b(blockquote): |
| 166 | + TAG_NAME = 'blockquote' |
20 | 167 |
|
21 | | - if block: |
22 | | - c.append("btn-block") |
| 168 | + def __call__(self, *args): |
| 169 | + firstChild = self.content[0](*args) |
23 | 170 |
|
24 | | - c = classing(_class, c) |
| 171 | + return self |
25 | 172 |
|
26 | | - return button(*args, _class=c, **kwargs) |
| 173 | + c = kwargs.pop("_class", []) |
| 174 | + c = classing("blockquote", *c) |
27 | 175 |
|
28 | | -container() |
| 176 | + return b(_class=c, **kwargs)( |
| 177 | + p(_class="mb-0"), |
| 178 | + footer(_class="blockquote-footer")(author) |
| 179 | + ) |
0 commit comments