Skip to content
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

Add ability to run code examples in the playground #340

Open
SeanTAllen opened this issue Jan 5, 2019 · 18 comments
Open

Add ability to run code examples in the playground #340

SeanTAllen opened this issue Jan 5, 2019 · 18 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@SeanTAllen
Copy link
Member

We had this sort of on the old tutorial but that didn't get migrated over.

@SeanTAllen
Copy link
Member Author

I went looking through the mkdocs material for this functionality and didn't see it. I'm going to reach out to the author and see if I missed the functionality, otherwise, I'll put in a feature request.

@SeanTAllen SeanTAllen self-assigned this Feb 8, 2022
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Feb 8, 2022
@SeanTAllen
Copy link
Member Author

So this is the report:

We can do some custom css and javascript. That's not really my thing, but someone could take this on.

squidfunk/mkdocs-material#3563

@SeanTAllen SeanTAllen added good first issue Good for newcomers help wanted Extra attention is needed labels Feb 10, 2022
@jemc jemc removed the discuss during sync Should be discussed during an upcoming sync label Mar 8, 2022
@SeanTAllen SeanTAllen removed their assignment Oct 26, 2022
@shaedrich
Copy link
Collaborator

shaedrich commented Apr 2, 2024

There doesn't seem to be a native option to add any other button than "copy" and "select" with the latter being sponsors-only:
grafik

I went looking through the mkdocs material for this functionality and didn't see it. I'm going to reach out to the author and see if I missed the functionality, otherwise, I'll put in a feature request.

Others have also wished for this functionality to become more generalized: squidfunk/mkdocs-material#4005 The only solution given there is to fork the theme.

However, one could add custom JavaScript to add this behavior: https://squidfunk.github.io/mkdocs-material/customization/#additional-javascript

grafik

To achieve a quick and easy solution, we could add buttons to all code blocks manually

grafik

Something, that would be more work but would prevent us from duplicating the code (once inside the code block and once URL-encoded in the button), would be to move the code to separate files and embed them. Alternatively, it could be gists.

This could also help in cases where the examples are longer than the URL is allowed to be by the browser (I don't know if we would run into that problem) 🤔

Or should the preview be in the tutorial, not just (in a new tab) in the playground?

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Apr 2, 2024
@SeanTAllen
Copy link
Member Author

We use the insiders build. So that is available as an option.

@shaedrich
Copy link
Collaborator

shaedrich commented Apr 3, 2024

Yeah, but that is only the "select" button, not the "play"/"run"/"execute" button

@jemc
Copy link
Member

jemc commented Apr 9, 2024

The other nice thing about the idea of moving the code examples to separate Pony files, is that we easily could start including testing to prove that all the examples compile.

@shaedrich
Copy link
Collaborator

If it helps, this can be done in a separate PR, when other questions are not yet answered

@SeanTAllen
Copy link
Member Author

@shaedrich are you interesting in tackling this? if yes, what additional information or discussion do you need from us?

@SeanTAllen SeanTAllen removed the discuss during sync Should be discussed during an upcoming sync label Apr 16, 2024
@shaedrich
Copy link
Collaborator

shaedrich commented Apr 16, 2024

@SeanTAllen I am indeed. The questions asked above still stand:

  • tutorial code examples inline, as separate files (still everything in one place), or as gist?
  • playground preloaded code inline (URLs might get too long), via gist (already implemented), or via file (see above, not implemented yet, afaik)?
  • "Play"/"Run"/"Exec" button in tutorial separately below the code block (custom code) or in the top right corner as part of the editor widget (might be a little more complicated)?

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Apr 16, 2024
@SeanTAllen
Copy link
Member Author

I'd prefer

  • separate files but...
  • it seems like gist is the only reasonable solution at this time
  • "all other things being more or less equal" i would go with "whatever you think is easiest to maintain"

my worry with gists is... that seems hard to maintain as the code is "somewhere else". which i think means, yes files is best. Looking at the tutorial I seriously doubt any of our code is going to hit a URL limit so...

I'd love to see the code stored in files and then the content put into the block at build time. then we can use ponyc to verify that all the code samples build. we can have the code inline in the block in the built site and do preloaded code inline. given that our code samples are in the hundreds to low thousands for the examples, i think that would work.

@jemc what are your thoughts?

@shaedrich
Copy link
Collaborator

it seems like gist is the only reasonable solution at this time

Grabbing the code from files could easily be implemented here:

https://github.com/ponylang/pony-playground/blob/59b1ffdac935f27cd73d7fd77ff380e7a38e9b7d/static/web.js#L516-L527

I'd love to see the code stored in files and then the content put into the block at build time.

There's even an option to embed external files in the code block widget: https://squidfunk.github.io/mkdocs-material/reference/code-blocks/#embedding-external-files

@jemc
Copy link
Member

jemc commented Apr 18, 2024

Yes, if it's possible I'd want the code to be in files in this repo (rather than gists) and get incorporated at tutorial build time. And get tested with ponyc at CI time.

@shaedrich
Copy link
Collaborator

shaedrich commented May 24, 2024

Possible follow-up features

→ Custom code fence: #555

jemc added a commit to ponylang/pony-playground that referenced this issue May 28, 2024
…ippet from URL by file name (#205)

See ponylang/pony-tutorial#340

> [!WARNING]
Will only work, after #222 has been merged.

Example: https://playground.ponylang.io/?snippet=hello-world-main.pony

Co-authored-by: Joe Eli McIlvain <[email protected]>

---------

Co-authored-by: Matthias Wahl <[email protected]>
Co-authored-by: Joe Eli McIlvain <[email protected]>
@shaedrich
Copy link
Collaborator

  • ❓ Get pony snippets tested with ponyc at CI time → I still need to figure out, how that might work 🤔 If there's someone else who would take this on, I wouldn't be mad 😅

From #549:

Where do we put the expectations for stdOut, stdErr, and exitCode? Because if we don't do that, only snippets that print to stdOut could be tested

@shaedrich
Copy link
Collaborator

  • ❓ Get pony snippets tested with ponyc at CI time → I still need to figure out, how that might work 🤔 If there's someone else who would take this on, I wouldn't be mad 😅

From #549:

Where do we put the expectations for stdOut, stdErr, and exitCode? Because if we don't do that, only snippets that print to stdOut could be tested

See #550 for a possible implementation

@shaedrich
Copy link
Collaborator

shaedrich commented Jun 4, 2024

One thing, I just thought about: When we have a snippet should there still be an option to create a gist from that? That seems to be a little redundant 🤔

@jemc
Copy link
Member

jemc commented Jun 25, 2024

Discussed on the sync call - while it isn't super helpful to anyone to create a few gist from a github-sourced snippet, it's not a problem per se, and it would potentially be confusing (or a maintenance problem) to add special case behavior to disable that.

@jemc jemc removed the discuss during sync Should be discussed during an upcoming sync label Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants