python-fasthtml 0.1.3__tar.gz → 0.1.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. {python_fasthtml-0.1.3/python_fasthtml.egg-info → python_fasthtml-0.1.4}/PKG-INFO +1 -1
  2. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/fasthtml/__init__.py +1 -1
  3. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/fasthtml/_modidx.py +7 -1
  4. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/fasthtml/xtend.py +44 -3
  5. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4/python_fasthtml.egg-info}/PKG-INFO +1 -1
  6. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/settings.ini +1 -1
  7. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/LICENSE +0 -0
  8. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/MANIFEST.in +0 -0
  9. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/README.md +0 -0
  10. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/fasthtml/authmw.py +0 -0
  11. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/fasthtml/cli.py +0 -0
  12. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/fasthtml/common.py +0 -0
  13. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/fasthtml/components.py +0 -0
  14. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/fasthtml/components.pyi +0 -0
  15. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/fasthtml/core.py +0 -0
  16. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/fasthtml/fastapp.py +0 -0
  17. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/fasthtml/js.py +0 -0
  18. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/fasthtml/live_reload.py +0 -0
  19. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/fasthtml/oauth.py +0 -0
  20. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/fasthtml/starlette.py +0 -0
  21. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/fasthtml/svg.py +0 -0
  22. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/fasthtml/toaster.py +0 -0
  23. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/fasthtml/xtend.pyi +0 -0
  24. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/python_fasthtml.egg-info/SOURCES.txt +0 -0
  25. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/python_fasthtml.egg-info/dependency_links.txt +0 -0
  26. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/python_fasthtml.egg-info/entry_points.txt +0 -0
  27. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/python_fasthtml.egg-info/not-zip-safe +0 -0
  28. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/python_fasthtml.egg-info/requires.txt +0 -0
  29. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/python_fasthtml.egg-info/top_level.txt +0 -0
  30. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/setup.cfg +0 -0
  31. {python_fasthtml-0.1.3 → python_fasthtml-0.1.4}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-fasthtml
3
- Version: 0.1.3
3
+ Version: 0.1.4
4
4
  Summary: The fastest way to create an HTML app
5
5
  Home-page: https://github.com/AnswerDotAI/fasthtml
6
6
  Author: Jeremy Howard
@@ -1,4 +1,4 @@
1
- __version__ = "0.1.3"
1
+ __version__ = "0.1.4"
2
2
  from .core import *
3
3
  from .authmw import *
4
4
  from .components import *
@@ -94,9 +94,15 @@ d = { 'settings': { 'branch': 'main',
94
94
  'fasthtml.xtend.Hidden': ('xtend.html#hidden', 'fasthtml/xtend.py'),
95
95
  'fasthtml.xtend.Html': ('xtend.html#html', 'fasthtml/xtend.py'),
96
96
  'fasthtml.xtend.Script': ('xtend.html#script', 'fasthtml/xtend.py'),
97
+ 'fasthtml.xtend.ScriptX': ('xtend.html#scriptx', 'fasthtml/xtend.py'),
97
98
  'fasthtml.xtend.Search': ('xtend.html#search', 'fasthtml/xtend.py'),
98
99
  'fasthtml.xtend.Style': ('xtend.html#style', 'fasthtml/xtend.py'),
100
+ 'fasthtml.xtend.StyleX': ('xtend.html#stylex', 'fasthtml/xtend.py'),
99
101
  'fasthtml.xtend.Titled': ('xtend.html#titled', 'fasthtml/xtend.py'),
102
+ 'fasthtml.xtend.double_braces': ('xtend.html#double_braces', 'fasthtml/xtend.py'),
100
103
  'fasthtml.xtend.jsd': ('xtend.html#jsd', 'fasthtml/xtend.py'),
104
+ 'fasthtml.xtend.loose_format': ('xtend.html#loose_format', 'fasthtml/xtend.py'),
105
+ 'fasthtml.xtend.replace_css_vars': ('xtend.html#replace_css_vars', 'fasthtml/xtend.py'),
101
106
  'fasthtml.xtend.run_js': ('xtend.html#run_js', 'fasthtml/xtend.py'),
102
- 'fasthtml.xtend.set_pico_cls': ('xtend.html#set_pico_cls', 'fasthtml/xtend.py')}}}
107
+ 'fasthtml.xtend.set_pico_cls': ('xtend.html#set_pico_cls', 'fasthtml/xtend.py'),
108
+ 'fasthtml.xtend.undouble_braces': ('xtend.html#undouble_braces', 'fasthtml/xtend.py')}}}
@@ -2,12 +2,14 @@
2
2
 
3
3
  # %% auto 0
4
4
  __all__ = ['picocss', 'picolink', 'picocondcss', 'picocondlink', 'set_pico_cls', 'Html', 'A', 'AX', 'Checkbox', 'Card', 'Group',
5
- 'Search', 'Grid', 'DialogX', 'Hidden', 'Container', 'Script', 'Style', 'run_js', 'Titled', 'jsd']
5
+ 'Search', 'Grid', 'DialogX', 'Hidden', 'Container', 'Script', 'Style', 'double_braces', 'undouble_braces',
6
+ 'loose_format', 'ScriptX', 'replace_css_vars', 'StyleX', 'run_js', 'Titled', 'jsd']
6
7
 
7
8
  # %% ../nbs/02_xtend.ipynb 2
8
9
  from dataclasses import dataclass, asdict
9
10
 
10
11
  from fastcore.utils import *
12
+ from fastcore.xtras import partial_format
11
13
  from fastcore.xml import *
12
14
  from fastcore.meta import use_kwargs, delegates
13
15
  from .components import *
@@ -128,19 +130,58 @@ def Style(*c, **kwargs)->XT:
128
130
  return xt_html('style', map(NotStr,c), **kwargs)
129
131
 
130
132
  # %% ../nbs/02_xtend.ipynb 31
133
+ def double_braces(s):
134
+ "Convert single braces to double braces if next to special chars or newline"
135
+ s = re.sub(r'{(?=[\s:;\'"]|$)', '{{', s)
136
+ return re.sub(r'(^|[\s:;\'"])}', r'\1}}', s)
137
+
138
+ # %% ../nbs/02_xtend.ipynb 32
139
+ def undouble_braces(s):
140
+ "Convert double braces to single braces if next to special chars or newline"
141
+ s = re.sub(r'\{\{(?=[\s:;\'"]|$)', '{', s)
142
+ return re.sub(r'(^|[\s:;\'"])\}\}', r'\1}', s)
143
+
144
+ # %% ../nbs/02_xtend.ipynb 33
145
+ def loose_format(s, **kw):
146
+ "String format `s` using `kw`, without being strict about braces outside of template params"
147
+ return undouble_braces(partial_format(double_braces(s), **kw)[0])
148
+
149
+ # %% ../nbs/02_xtend.ipynb 34
150
+ def ScriptX(fname, type=None, _async=None, defer=None, charset=None, crossorigin=None, integrity=None, **kw):
151
+ "Create a Script from the text of a file"
152
+ attrs = ['src', 'type', 'async', 'defer', 'charset', 'crossorigin', 'integrity', 'nomodule']
153
+ scr_kw = {k:kw.pop(k) for k in attrs if k in kw}
154
+ s = loose_format(Path(fname).read_text(), **kw)
155
+ return Script(s, **scr_kw)
156
+
157
+ # %% ../nbs/02_xtend.ipynb 35
158
+ def replace_css_vars(css, pre='tpl', **kwargs):
159
+ def replace_var(m):
160
+ var_name = m.group(1).replace('-', '_')
161
+ return kwargs.get(var_name, m.group(0))
162
+ return re.sub(fr'var\(--{pre}-([\w-]+)\)', replace_var, css)
163
+
164
+ # %% ../nbs/02_xtend.ipynb 36
165
+ def StyleX(fname, **kw):
166
+ s = Path(fname).read_text()
167
+ attrs = ['type', 'media', 'scoped', 'title', 'nonce', 'integrity', 'crossorigin']
168
+ sty_kw = {k:kw.pop(k) for k in attrs if k in kw}
169
+ return Style(replace_css_vars(s, **kw), **sty_kw)
170
+
171
+ # %% ../nbs/02_xtend.ipynb 37
131
172
  def run_js(js, id=None, **kw):
132
173
  "Run `js` script, auto-generating `id` based on name of caller if needed, and js-escaping any `kw` params"
133
174
  if not id: id = sys._getframe(1).f_code.co_name
134
175
  kw = {k:dumps(v) for k,v in kw.items()}
135
176
  return Script(js.format(**kw), id=id, hx_swap_oob='true')
136
177
 
137
- # %% ../nbs/02_xtend.ipynb 32
178
+ # %% ../nbs/02_xtend.ipynb 38
138
179
  @delegates(xt_hx, keep=True)
139
180
  def Titled(title:str="FastHTML app", *args, **kwargs)->XT:
140
181
  "An HTML partial containing a `Title`, and `H1`, and any provided children"
141
182
  return Title(title), Main(H1(title), *args, cls="container", **kwargs)
142
183
 
143
- # %% ../nbs/02_xtend.ipynb 33
184
+ # %% ../nbs/02_xtend.ipynb 39
144
185
  def jsd(org, repo, root, path, prov='gh', typ='script', ver=None, esm=False, **kwargs)->XT:
145
186
  "jsdelivr `Script` or CSS `Link` tag, or URL"
146
187
  ver = '@'+ver if ver else ''
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-fasthtml
3
- Version: 0.1.3
3
+ Version: 0.1.4
4
4
  Summary: The fastest way to create an HTML app
5
5
  Home-page: https://github.com/AnswerDotAI/fasthtml
6
6
  Author: Jeremy Howard
@@ -1,7 +1,7 @@
1
1
  [DEFAULT]
2
2
  repo = fasthtml
3
3
  lib_name = fasthtml
4
- version = 0.1.3
4
+ version = 0.1.4
5
5
  min_python = 3.10
6
6
  license = apache2
7
7
  requirements = fastcore>=1.5.46 python-dateutil starlette>0.33 oauthlib itsdangerous uvicorn[standard] httpx fastlite>=0.0.6 python-multipart beautifulsoup4
File without changes