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

Initial development of Gleam playground #1

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

isaacharrisholt
Copy link

@isaacharrisholt isaacharrisholt commented May 6, 2024

See gleam-lang/gleam#2557

TODO:

  • Page generation
  • JS compilation/execution
  • Home page design
  • Show compiled JS
  • Share button
  • Show compiled Erlang (closes Show compiled Erlang #2)
  • Format button
  • Example projects
  • "About the playground" page design and content

Discussion

Share button

For the share button, I was thinking of potentially encoding something like the following as JSON:

{
  "version": 1,
  "files": {
    [
      {"file":"app.gleam","content":"<some gleam code>"}
    ]
  }
}

This would need compressing to keep query string length down.

This will allow us to expand the playground later to include multi-file projects so people can experiment with project structure and so on, and keeping it versioned will help maintain backwards compatibility if this changes in the future.

Example projects

It would be good to have some short example Gleam projects, like the Go playground has, to show off the sort of stuff you can accomplish with Gleam. Let me know if you have any ideas!

@inoas
Copy link

inoas commented May 6, 2024

For sharing the query string length is very precious and thus I would not do that. I would include a g=1 in the QS maybe so if gleam 2 happens the playground is usable for both.

Also escaping gleam code into json adds a lot of string length.

for a download/upload feature + multi module tabs the json structure looks great <3, I'd still include a gleam version and I am uncertain about deps.

@inoas
Copy link

inoas commented May 6, 2024

The QS len is so precious because people might start sharing code snipplets on discord and we would want to limit the length of that strictly I suppose?

@isaacharrisholt
Copy link
Author

Oh it would definitely need compressing. One sec, let me make sure to add that to the description

@inoas
Copy link

inoas commented May 6, 2024

The old playground has some query string compatible compression feature that can be just copied over I guess.

@inoas
Copy link

inoas commented May 6, 2024

However, that only helps "so much"

@isaacharrisholt
Copy link
Author

Agreed, but it means we don't need a database etc. We could definitely go the GitHub gist route, like the Rust playground, but that would require a backend with GitHub access. This way we can keep using a static site. Open to other ideas though!

@lpil
Copy link
Member

lpil commented May 6, 2024

It needs to go in the hash/fragment, not the query string. There are very tight restrictions on query string length which mean it is not usable for this, but there are no such restrictions on the hash/fragment.

Formatting and examples are not a goals of this first version, and I think we can skip the about page too. Less is more and shipping faster is best.

btw you've committed the public directory by mistake. Could you remove those files from the git history please before merging 🙏

@isaacharrisholt
Copy link
Author

Ah, thanks for the advice! Very helpful.

Also, history should now be public-free!

@isaacharrisholt isaacharrisholt marked this pull request as ready for review May 15, 2024 21:33
@isaacharrisholt
Copy link
Author

@lpil should be all good to go. I've left out Erlang compilation for now, as it would require also including the Erlang stdlib, and that's a larger piece of work. I'll create issues for the missing features.

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I've left one large-ish comment on the approach here

</div>
</div>
</section>
</article>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this into Gleam code please 🙏

The tour uses text files for content as a sort of poor-person's CMS. This is not a content based site so let's keep everything in Gleam.

// Don't include deprecated stdlib modules
const skipped_stdlib_modules = [
"bit_string.gleam", "bit_builder.gleam", "map.gleam",
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These have been removed so don't need this special case any more

use pages <- result.try(read_pages(filenames))
use _ <- result.try(write_pages(pages))

io.debug("Done rendering pages")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug message left in here

pub fn main() {
let _ = {
use f <- result.try(load_file_names(pages_path, []))
io.debug(read_pages(f))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug message left in here

Comment on lines 85 to 86
/// Recursively list files in a directory
fn load_file_names(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove all the file system reflection based CMS stuff. We can just render a string of HTML and write it directly.

@isaacharrisholt
Copy link
Author

@lpil all sorted, I believe!

@isaacharrisholt isaacharrisholt marked this pull request as draft May 19, 2024 13:15
Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove all the page abstraction stuff and build and write the HTML directly please. This project doesn't need a CMS so we don't want to port all that stuff from the tour 🙏

Something like this:

    use _ <- result.try(reset_output())
    use _ <- result.try(make_prelude_available())
    use _ <- result.try(make_stdlib_available())
    use _ <- result.try(copy_wasm_compiler())
    use _ <- result.try(write("index.html", page_html()))
    Ok(Nil)

@isaacharrisholt
Copy link
Author

Ah, gotcha! Yes, I can do that.

@isaacharrisholt
Copy link
Author

I think it's still worth having a page_template() or similar function, though. We may want to add an about page or similar later, no? Or can we guarantee this project will always be a single page?

@isaacharrisholt
Copy link
Author

Hey I've been playing around and I'm not entirely sure how you want this to look. I think ultimately we need to keep a lot of the PageConfig, HeadConfig etc. otherwise we'll just end up with some massive function defining all the HTML for the page, and I don't think it'll be readable.

I remove the get_pages function and change it to need a single write call for each page like you suggested, but I'm not sure what that really achieves? All get_pages does really is define the output settings for multiple pages. If we changed it, we'd just be spreading this config throughout multiple functions.

@codemonkey76
Copy link

codemonkey76 commented Jun 7, 2024

I've been playing around with it and there is an issue with the share link generation, it doesn't url encode the title, so if there are spaces in it (like there is in the default "A Gleam Playground project", then the link won't work

static/index.js, line 202:
you need to wrap the title in encodeURIComponent(originalString);

@isaacharrisholt
Copy link
Author

I've been playing around with it and there is an issue with the share link generation, it doesn't url encode the title, so if there are spaces in it (like there is in the default "A Gleam Playground project", then the link won't work

static/index.js, line 202: you need to wrap the title in encodeURIComponent(originalString);

Fixed, thank you! I managed to overlook that because you can paste spaces into Chrome, but totally forgot that these links are made for sharing and wouldn't be clickable 😅

@codemonkey76
Copy link

I have it up on gleam-playground.fly.dev for testing

@isaacharrisholt
Copy link
Author

I have it up on gleam-playground.fly.dev for testing

Thanks for that! Is it the latest version? It doesn't seem to have the encoded URI component.

@codemonkey76
Copy link

no it wasn't... just pulled your change and re-deployed it.,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show compiled Erlang
4 participants