Skip to content

Commit

Permalink
fixes #602
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 committed Aug 13, 2024
1 parent ba8bcd1 commit 9ac59d8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion fastcore/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def attrmap(o):

# %% ../nbs/11_xml.ipynb
def valmap(o):
if is_listy(o): return ' '.join(o)
if is_listy(o): return ' '.join(map(str,o))
if isinstance(o, dict): return '; '.join(f"{k}:{v}" for k,v in o.items())
return o

Expand Down
35 changes: 28 additions & 7 deletions nbs/11_xml.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"source": [
"#| export\n",
"def valmap(o):\n",
" if is_listy(o): return ' '.join(o)\n",
" if is_listy(o): return ' '.join(map(str,o))\n",
" if isinstance(o, dict): return '; '.join(f\"{k}:{v}\" for k,v in o.items())\n",
" return o"
]
Expand Down Expand Up @@ -162,6 +162,31 @@
"for o in _all_: _g[o] = partial(ft, o.lower(), void_=o.lower() in voids)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "306844ba",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['body',\n",
" (['div', ('hi',), {'a': 1, 'b': True}],\n",
" ['p', ('hi',), {'class': 'a 1', 'style': 'a:1; b:2'}]),\n",
" {}]"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = Body(Div('hi', a=1, b=True), P('hi', cls=['a',1], style=dict(a=1,b=2)))\n",
"a"
]
},
{
"cell_type": "markdown",
"id": "732e44ab",
Expand Down Expand Up @@ -415,15 +440,11 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"class PageTitle:\n",
" \n",
" def __ft__(self):\n",
" return H1(\"Hello\")\n",
" def __ft__(self): return H1(\"Hello\")\n",
"\n",
"class HomePage:\n",
" def __ft__(self):\n",
" return Div(PageTitle(), Div('hello'))\n",
" def __ft__(self): return Div(PageTitle(), Div('hello'))\n",
"\n",
"h = to_xml(Div(HomePage()))\n",
"expected_output = \"\"\"<div>\n",
Expand Down

0 comments on commit 9ac59d8

Please sign in to comment.