Skip to content

Commit 5ecc395

Browse files
authored
remove cond/foreach/match components (#1185)
1 parent 4ee8121 commit 5ecc395

File tree

4 files changed

+28
-34
lines changed

4 files changed

+28
-34
lines changed

docs/library/dynamic-rendering/cond.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
---
2-
components:
3-
- rx.components.core.Cond
4-
---
5-
61
```python exec
72
import reflex as rx
83
```
@@ -146,4 +141,4 @@ elif((c>a and c>b) and (c != a and c != b)):
146141
print(c, " is the largest!")
147142
else:
148143
print("Some of the numbers are equal!")
149-
```
144+
```

docs/library/dynamic-rendering/foreach.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
---
2-
components:
3-
- rx.foreach
4-
---
5-
61
```python exec
72
import reflex as rx
83
```
@@ -14,6 +9,7 @@ This is useful for dynamically rendering a list of items defined in a state.
149

1510
```md alert warning
1611
# `rx.foreach` is specialized for usecases where the iterable is defined in a state var.
12+
1713
For an iterable where the content doesn't change at runtime, i.e a constant, using a list/dict comprehension instead of `rx.foreach` is preferred.
1814
```
1915

docs/library/dynamic-rendering/match.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
---
2-
components:
3-
- rx.match
4-
---
5-
61
```python exec
72
import reflex as rx
83
```

pcweb/pages/docs/__init__.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def build_nested_namespace(
7676

7777
def get_components_from_metadata(current_doc):
7878
components = []
79-
79+
8080
for comp_str in current_doc.metadata.get("components", []):
8181
component = eval(comp_str)
8282
if isinstance(component, type):
@@ -85,7 +85,9 @@ def get_components_from_metadata(current_doc):
8585
components.append((component.__self__, comp_str))
8686
elif isinstance(component, SimpleNamespace) and hasattr(component, "__call__"):
8787
components.append((component.__call__.__self__, comp_str))
88-
88+
else:
89+
raise ValueError(f"Invalid component: {component}")
90+
8991
return components
9092

9193

@@ -132,6 +134,7 @@ def exec_blocks(doc, href):
132134
"docs/recipes/content/grid.md": "Grid Recipe",
133135
}
134136

137+
135138
def get_component(doc: str, title: str):
136139
if doc.endswith("-style.md"):
137140
return
@@ -162,13 +165,14 @@ def get_component(doc: str, title: str):
162165
return multi_docs(path=route, comp=d, component_list=clist, title=title2)
163166
if doc.startswith("docs/library"):
164167
clist = [title, *get_components_from_metadata(d)]
165-
if issubclass(
166-
clist[1][0],
167-
(RadixThemesComponent, RadixPrimitiveComponent),
168-
):
169-
component_list[category].append(clist)
170-
else:
171-
component_list[category].append(clist)
168+
if len(clist) > 1:
169+
if issubclass(
170+
clist[1][0],
171+
(RadixThemesComponent, RadixPrimitiveComponent),
172+
):
173+
component_list[category].append(clist)
174+
else:
175+
component_list[category].append(clist)
172176
if should_skip_compile(doc):
173177
outblocks.append((d, route))
174178
return
@@ -183,12 +187,16 @@ def get_component(doc: str, title: str):
183187
)
184188

185189

186-
doc_routes = [
187-
library,
188-
custom_components,
189-
overview,
190-
*components_previews_pages,
191-
] + apiref_pages + cloud_cliref_pages
190+
doc_routes = (
191+
[
192+
library,
193+
custom_components,
194+
overview,
195+
*components_previews_pages,
196+
]
197+
+ apiref_pages
198+
+ cloud_cliref_pages
199+
)
192200

193201

194202
for api_route in apiref_pages:
@@ -200,7 +208,7 @@ def get_component(doc: str, title: str):
200208
build_nested_namespace(docs_ns, ["api_reference"], title, api_route)
201209

202210
for doc in sorted(flexdown_docs):
203-
path = doc.split("/")[1:-1]
211+
path = doc.split("/")[1:-1]
204212

205213
title = rx.utils.format.to_snake_case(os.path.basename(doc).replace(".md", ""))
206214
title2 = to_title_case(title)
@@ -224,8 +232,8 @@ def get_component(doc: str, title: str):
224232

225233

226234
for doc in flexdown_docs:
227-
if 'recipes' in doc:
228-
category = doc.split('/')[2]
235+
if "recipes" in doc:
236+
category = doc.split("/")[2]
229237
recipes_list[category].append(doc)
230238

231239
for name, ns in docs_ns.__dict__.items():

0 commit comments

Comments
 (0)