Skip to content

Commit

Permalink
Documentation: Support for including node examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ideoforms committed Dec 3, 2023
1 parent 5f7faff commit 839d709
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions auxiliary/scripts/auto-generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def generate_node_library(node_classes):
cls_doc_abs_folder = os.path.dirname(cls_doc_abs_path)
os.makedirs(cls_doc_abs_folder, exist_ok=True)
example_scripts = glob.glob(os.path.join(cls_doc_abs_folder, "*.py"))
example_scripts = [os.path.basename(s) for s in example_scripts]
# example_scripts = [os.path.basename(s) for s in example_scripts]
with open(cls_doc_abs_path, "w") as fd:
output_markdown_params = ", ".join(("%s=%s" % (param.name, param.default)) \
for param in cls.constructors[0])
Expand All @@ -378,8 +378,12 @@ def generate_node_library(node_classes):
if len(example_scripts):
fd.write(f"### Examples\n\n")
for example_script in example_scripts:
example_code = open(example_script, "r").read()
example_code = re.sub(r".*graph = AudioGraph\(\)\n", "", example_code, flags=re.DOTALL)
example_code = re.sub(r"graph.wait\(\).*", "", example_code, flags=re.DOTALL)
fd.write(f"```python\n")
fd.write('{%% include-markdown "./%s" comments=false %%}\n' % example_script)
# fd.write('{%% include-markdown "./%s" comments=false %%}\n' % example_script)
fd.write(example_code)
fd.write(f"```\n\n")

def generate_readme(node_classes) -> None:
Expand Down
6 changes: 5 additions & 1 deletion docs/library/oscillators/sinelfo/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Produces a sinusoidal LFO at the given `frequency` and `phase` offset, with outp
### Examples

```python
{% include-markdown "./example-0.py" comments=false %}

# Siren effect, using a sinewave LFO to modulate a sawtooth's frequency
lfo = SineLFO(1, 200, 1000)
saw = SawOscillator(lfo)
saw.play()
```

0 comments on commit 839d709

Please sign in to comment.