Skip to content

Commit 1ad2f0d

Browse files
committed
fixes #893
1 parent 684678a commit 1ad2f0d

File tree

6 files changed

+556
-54
lines changed

6 files changed

+556
-54
lines changed

nbdev/_modidx.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
'pip_requirements': 'PyYAML',
6060
'readme_nb': 'getting_started.ipynb',
6161
'recursive': 'False',
62-
'requirements': 'fastcore>=1.5.17 execnb>=0.0.10 astunparse ghapi',
62+
'requirements': 'fastcore>=1.5.18 execnb>=0.0.10 astunparse ghapi',
6363
'status': '2',
6464
'title': 'nbdev',
6565
'tst_flags': 'notest',
@@ -175,6 +175,10 @@
175175
'nbdev.processors.strip_hidden_metadata': 'https://nbdev.fast.ai/processors.html#strip_hidden_metadata',
176176
'nbdev.processors.yaml_str': 'https://nbdev.fast.ai/processors.html#yaml_str',
177177
'nbdev.processors.yml2dict': 'https://nbdev.fast.ai/processors.html#yml2dict'},
178+
'nbdev.qmd': { 'nbdev.qmd.qmd_btn': 'https://nbdev.fast.ai/qmd.html#qmd_btn',
179+
'nbdev.qmd.qmd_div': 'https://nbdev.fast.ai/qmd.html#qmd_div',
180+
'nbdev.qmd.qmd_img': 'https://nbdev.fast.ai/qmd.html#qmd_img',
181+
'nbdev.qmd.qmd_meta': 'https://nbdev.fast.ai/qmd.html#qmd_meta'},
178182
'nbdev.quarto': { 'nbdev.quarto.BASE_QUARTO_URL': 'https://nbdev.fast.ai/quarto.html#base_quarto_url',
179183
'nbdev.quarto.deploy': 'https://nbdev.fast.ai/quarto.html#deploy',
180184
'nbdev.quarto.install': 'https://nbdev.fast.ai/quarto.html#install',

nbdev/qmd.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/14_qmd.ipynb.
2+
3+
# %% ../nbs/14_qmd.ipynb 2
4+
from __future__ import annotations
5+
6+
from fastcore.utils import *
7+
from fastcore.meta import delegates
8+
9+
# %% auto 0
10+
__all__ = ['qmd_meta', 'qmd_div', 'qmd_img', 'qmd_btn']
11+
12+
# %% ../nbs/14_qmd.ipynb 5
13+
def qmd_meta(md, # Markdown to add meta to
14+
classes=None, # List of CSS classes to add
15+
style=None, # Dict of CSS styles to add
16+
**kwargs): # Additional attributes to add to meta
17+
"A metadata section for qmd div in `{}`"
18+
if style: kwargs['style'] = "; ".join(f'{k}: {v}' for k,v in style.items())
19+
props = ' '.join(f'{k}="{v}"' for k,v in kwargs.items())
20+
classes = ' '.join('.'+c for c in L(classes))
21+
meta = []
22+
if classes: meta.append(classes)
23+
if props: meta.append(props)
24+
meta = ' '.join(meta)
25+
return md + ("{" + meta + "}" if meta else "")
26+
27+
# %% ../nbs/14_qmd.ipynb 6
28+
def qmd_div(txt, # Markdown to add meta to
29+
classes=None, # List of CSS classes to add
30+
style=None, # Dict of CSS styles to add
31+
**kwargs):
32+
"A qmd div with optional metadata section"
33+
return qmd_meta("::: ", classes=classes, style=style, **kwargs) + f"\n\n{txt}\n\n:::\n\n"
34+
35+
# %% ../nbs/14_qmd.ipynb 7
36+
def qmd_img(fname, # Image to link to
37+
classes=None, # List of CSS classes to add
38+
style=None, # Dict of CSS styles to add
39+
height=None, # Height attribute
40+
relative=None, # Tuple of (position,px)
41+
link=False, # Hyperlink to this image
42+
**kwargs):
43+
"A qmd image"
44+
kwargs,style = kwargs or {}, style or {}
45+
if height: kwargs["height"]= f"{height}px"
46+
if relative:
47+
pos,px = relative
48+
style["position"] = "relative"
49+
style[pos] = f"{px}px"
50+
res = f'![]({fname})'
51+
res = qmd_meta(res, classes=classes, style=style, **kwargs)
52+
if link: res = f'[{res}]({fname})'
53+
return res
54+
55+
# %% ../nbs/14_qmd.ipynb 8
56+
def qmd_btn(txt, # Button text
57+
link, # Button link URL
58+
classes=None, # List of CSS classes to add
59+
style=None): # Dict of CSS styles to add
60+
"A qmd button"
61+
return qmd_meta(f'[{txt}]({link})', classes=classes, style=style, role="button")

nbs/14_qmd.ipynb

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "510ed03d-0c3b-4caf-910d-e6eaec08fd63",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"#|default_exp qmd"
11+
]
12+
},
13+
{
14+
"cell_type": "markdown",
15+
"id": "f0f931c2",
16+
"metadata": {},
17+
"source": [
18+
"# qmd\n",
19+
"\n",
20+
"> Basic qmd generation helpers (experimental)"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": null,
26+
"id": "6a35c7c4-748f-4c82-a9bf-c780a8d83e90",
27+
"metadata": {},
28+
"outputs": [],
29+
"source": [
30+
"#|export\n",
31+
"from __future__ import annotations\n",
32+
"\n",
33+
"from fastcore.utils import *\n",
34+
"from fastcore.meta import delegates"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": null,
40+
"id": "1e623a3d-3e77-44c6-adf3-4768b78328c5",
41+
"metadata": {},
42+
"outputs": [],
43+
"source": [
44+
"#|hide\n",
45+
"from fastcore.test import *"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": null,
51+
"id": "5a64f1f4",
52+
"metadata": {},
53+
"outputs": [],
54+
"source": [
55+
"#| export\n",
56+
"def qmd_meta(md, # Markdown to add meta to\n",
57+
" classes=None, # List of CSS classes to add\n",
58+
" style=None, # Dict of CSS styles to add\n",
59+
" **kwargs): # Additional attributes to add to meta\n",
60+
" \"A metadata section for qmd div in `{}`\"\n",
61+
" if style: kwargs['style'] = \"; \".join(f'{k}: {v}' for k,v in style.items())\n",
62+
" props = ' '.join(f'{k}=\"{v}\"' for k,v in kwargs.items())\n",
63+
" classes = ' '.join('.'+c for c in L(classes))\n",
64+
" meta = []\n",
65+
" if classes: meta.append(classes)\n",
66+
" if props: meta.append(props)\n",
67+
" meta = ' '.join(meta)\n",
68+
" return md + (\"{\" + meta + \"}\" if meta else \"\")"
69+
]
70+
},
71+
{
72+
"cell_type": "code",
73+
"execution_count": null,
74+
"id": "52637a70",
75+
"metadata": {},
76+
"outputs": [],
77+
"source": [
78+
"#| export\n",
79+
"def qmd_div(txt, # Markdown to add meta to\n",
80+
" classes=None, # List of CSS classes to add\n",
81+
" style=None, # Dict of CSS styles to add\n",
82+
" **kwargs):\n",
83+
" \"A qmd div with optional metadata section\"\n",
84+
" return qmd_meta(\"::: \", classes=classes, style=style, **kwargs) + f\"\\n\\n{txt}\\n\\n:::\\n\\n\""
85+
]
86+
},
87+
{
88+
"cell_type": "code",
89+
"execution_count": null,
90+
"id": "f9f499f4",
91+
"metadata": {},
92+
"outputs": [],
93+
"source": [
94+
"#| export\n",
95+
"def qmd_img(fname, # Image to link to\n",
96+
" classes=None, # List of CSS classes to add\n",
97+
" style=None, # Dict of CSS styles to add\n",
98+
" height=None, # Height attribute\n",
99+
" relative=None, # Tuple of (position,px)\n",
100+
" link=False, # Hyperlink to this image\n",
101+
" **kwargs):\n",
102+
" \"A qmd image\"\n",
103+
" kwargs,style = kwargs or {}, style or {}\n",
104+
" if height: kwargs[\"height\"]= f\"{height}px\"\n",
105+
" if relative:\n",
106+
" pos,px = relative\n",
107+
" style[\"position\"] = \"relative\"\n",
108+
" style[pos] = f\"{px}px\"\n",
109+
" res = f'![]({fname})'\n",
110+
" res = qmd_meta(res, classes=classes, style=style, **kwargs)\n",
111+
" if link: res = f'[{res}]({fname})'\n",
112+
" return res"
113+
]
114+
},
115+
{
116+
"cell_type": "code",
117+
"execution_count": null,
118+
"id": "16d7aa5f",
119+
"metadata": {},
120+
"outputs": [],
121+
"source": [
122+
"#| export\n",
123+
"def qmd_btn(txt, # Button text\n",
124+
" link, # Button link URL\n",
125+
" classes=None, # List of CSS classes to add\n",
126+
" style=None): # Dict of CSS styles to add\n",
127+
" \"A qmd button\"\n",
128+
" return qmd_meta(f'[{txt}]({link})', classes=classes, style=style, role=\"button\")"
129+
]
130+
},
131+
{
132+
"cell_type": "markdown",
133+
"id": "aa35b010",
134+
"metadata": {},
135+
"source": [
136+
"## Export -"
137+
]
138+
},
139+
{
140+
"cell_type": "code",
141+
"execution_count": null,
142+
"id": "3d8031ce",
143+
"metadata": {},
144+
"outputs": [],
145+
"source": [
146+
"#|hide\n",
147+
"import nbdev; nbdev.nbdev_export()"
148+
]
149+
},
150+
{
151+
"cell_type": "code",
152+
"execution_count": null,
153+
"id": "12588a26-43a6-42c4-bacd-896293c871ab",
154+
"metadata": {},
155+
"outputs": [],
156+
"source": []
157+
}
158+
],
159+
"metadata": {
160+
"kernelspec": {
161+
"display_name": "Python 3 (ipykernel)",
162+
"language": "python",
163+
"name": "python3"
164+
}
165+
},
166+
"nbformat": 4,
167+
"nbformat_minor": 5
168+
}

nbs/index.py

Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1+
"""
2+
---
3+
pagetitle: nbdev – Create delightful software with Jupyter Notebooks
4+
page-layout: custom
5+
section-divs: false
6+
jupyter: python3
7+
execute:
8+
enabled: false
9+
css: index.css
10+
toc: false
11+
image: https://nbdev.fast.ai/images/card.png
12+
description: Write, test, document, and distribute software packages and technical articles — all in one place, your notebook.
13+
---
14+
"""
15+
116
from fastcore.foundation import L
17+
import sys,os
18+
from nbdev.qmd import *
19+
from nbdev.config import get_config
20+
21+
os.chdir(get_config().path('nbs_path'))
22+
sys.stdout = open('index.qmd', 'w')
23+
print(__doc__)
224

3-
def qmd_meta(md, classes=None, style=None, **kwargs):
4-
if style: kwargs['style'] = "; ".join(f'{k}: {v}' for k,v in style.items())
5-
props = ' '.join(f'{k}="{v}"' for k,v in kwargs.items())
6-
classes = ' '.join('.'+c for c in L(classes))
7-
meta = []
8-
if classes: meta.append(classes)
9-
if props: meta.append(props)
10-
meta = ' '.join(meta)
11-
return md + ("{" + meta + "}" if meta else "")
12-
13-
def qmd_div(txt, classes=None, style=None, **kwargs): return qmd_meta("::: ", classes=classes, style=style, **kwargs) + f"\n\n{txt}\n\n:::\n\n"
14-
15-
def img(fname, classes=None, style=None, height=None, relative=None, link=False, **kwargs):
16-
kwargs,style = kwargs or {}, style or {}
17-
if height: kwargs["height"]= f"{height}px"
18-
if relative:
19-
pos,px = relative
20-
style["position"] = "relative"
21-
style[pos] = f"{px}px"
22-
res = f'![](images/{fname})'
23-
res = qmd_meta(res, classes=classes, style=style, **kwargs)
24-
if link: res = f'[{res}](images/{fname})'
25-
return res
25+
def img(fname, classes=None, **kwargs):
26+
return qmd_img(f"images/{fname}", classes=classes, **kwargs)
2627

2728
def btn(txt, link):
2829
classes = ['btn-action-primary', 'btn-action', 'btn', 'btn-success', 'btn-lg']
29-
return qmd_meta(f'[{txt}]({link})', classes, role="button")
30+
return qmd_btn(txt, link=link, classes=classes)
3031

3132
def banner(txt, classes=None, style=None): return qmd_div(txt, L('hero-banner')+classes, style=style)
3233

@@ -68,3 +69,45 @@ def feature(im, desc): return qmd_div(f"{img(im+'.svg')}\n\n{desc}\n", ['feature
6869
def b(*args, **kwargs): print(banner (*args, **kwargs))
6970
def d(*args, **kwargs): print(qmd_div(*args, **kwargs))
7071

72+
###
73+
# Output section
74+
###
75+
76+
b(f"""# <span style='color:#009AF1'>Create delightful software</span><br>with Jupyter Notebooks
77+
78+
### Write, test, document, and distribute software packages and technical articles — all in one place, your notebook.
79+
80+
{btn('Get started', 'getting_started.ipynb')}
81+
82+
{img('card.png', style={"margin-top": "40px", "margin-bottom": "40px"}, link=True)}""", "content-block")
83+
84+
industries = '\n'.join([
85+
industry('netflix.svg', height=26, relative=("top",1)),
86+
industry('transform.svg', height=26, relative=("bottom",1)),
87+
industry('outerbounds.svg', height=26, relative=("bottom",1)),
88+
industry('novetta.svg', height=30, relative=("top",1)),
89+
industry('amd.svg', height=22),
90+
industry('overstory.png', height=26),
91+
industry('bom.png', height=46, relative=("bottom",12)),
92+
industry('lyft.svg', height=34),
93+
])
94+
industries = qmd_div(industries, 'grid', style={"column-gap": "50px"})
95+
96+
b(f"""## <span style='color:#009AF1'>Trusted</span> in industry
97+
98+
{industries}""", "mid-content")
99+
100+
feature_h = banner(f"""## <span style='color:#009AF1'>Exploratory programming</span><br>without compromise
101+
102+
### Traditional programming environments throw away the result of your exploration in REPLs or notebooks. nbdev makes exploration an integral part of your workflow, all while promoting software engineering best practices.""")
103+
104+
d(feature_h+feature_d, "content-block")
105+
106+
expert_b = banner("## Here's what experts are saying")
107+
108+
d(expert_b+expert_d, "mid-content")
109+
110+
b(f"""## Get started in seconds
111+
112+
{btn('Install nbdev', 'getting_started.ipynb')}""", 'content-block', style={"margin-top": "40px"})
113+

0 commit comments

Comments
 (0)