-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example decorators #566
Example decorators #566
Conversation
1ce5be4
to
054b64e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, as always! Thank you. It might take a while (> 2 weeks) before I can do a full review.
Of course, take your time! |
b26a711
to
944e7e8
Compare
2e26f09
to
17c2a9f
Compare
Thank you for the update. Will continue my review over the next days. This is great! |
numbat/examples/inspect.rs
Outdated
//Print the example | ||
if let Some(example_description) = example_description { | ||
println!( | ||
"* {}\n\n <a href=\"{}\"><i class=\"fa fa-play\"></i> Run this example</a>", | ||
replace_equation_delimiters(example_description), | ||
example_url | ||
); | ||
} else { | ||
println!( | ||
"* <a href=\"{}\"><i class=\"fa fa-play\"></i> Run this example</a>\n", | ||
example_url | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that is fine for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice! Thank you 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I finished my review. Again: thank you very much for implementing this — and adding examples to all existing functions!
Thanks a lot for the review. |
Co-authored-by: David Peter <[email protected]>
e642e34
to
45cba26
Compare
This PR resolves #503, implements the
@example
decorator and adds basic examples to most standard library functions.The
@example
decorator takes the example code as the first positional argument and optionally an example description as second argument. Multiple examples can be defined by using@example
multiple times:At the moment the examples are only used to compile the documentation, however it might be nice to make them accessible in the CLI or web interface in the future. In the documentation the example code is run trough the Numbat interpreter and is shown together with the results as if it was typed in the CLI interface. Additionally the example description is displayed (if available) and a "Run this example" link is shown. Since the examples can be a bit lengthy, I chose to display them collapsed by default.
I have not added any examples to non pure functions like
random()
, ornow()
for the moment. While this would work in principle, it would modify the documentation every time someone re-runsbook/build.py
which doesn't feel very practical.