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

Enhance Realm Rendering in Gno by Supporting Multiple Render Methods #1422

Open
gfanton opened this issue Dec 7, 2023 · 3 comments
Open
Labels
📦 ⛰️ gno.land Issues or PRs gno.land package related 📦 🤖 gnovm Issues or PRs gnovm related 🧾 package/realm Tag used for new Realms or Packages. 🌟 improvement performance improvements, refactors ...

Comments

@gfanton
Copy link
Member

gfanton commented Dec 7, 2023

In the current implementation, each realm possesses a Render method that returns a Markdown representation of the realm. While there are ongoing efforts to enhance this default rendering format (as discussed in issue #439), the current method is limited in scope, supporting only this single, default rendering format.

To extend the versatility and usability of realms, I propose introducing additional rendering methods. This enhancement would allow realms to support various formats like HTML, JSON, etc., akin to how structures in Go can implement custom MarshalJSON and UnmarshalJSON methods for JSON processing.

Implementation

  • Multiple Render Methods: Each realm could implement multiple render methods such as RenderHTML, RenderJSON, RenderXXX, etc. This approach enables platforms, devices, or any other clients to request a specific render format as per their requirements. These methods could coexist with the existing Render method, providing developers with a suite of flexible rendering options.
  • Default Render Method: To ensure consistency and backward compatibility, it is essential for every realm to implement the default Render method. This method would act as a fallback, guaranteeing that a basic and human readable Markdown rendering is always available, regardless of the additional formats supported.

This proposal, while introducing versatile rendering options like RenderHTML or RenderJSON complements the ongoing improvements to the default Render method discussed in issue #439. It aims to broaden the utility and adaptability of Gno realms without conflicting with existing enhancement efforts. By offering diverse rendering capabilities alongside a reliable Markdown fallback, this enhancement seeks to cater to a wider range of use cases, from web views to specific data representation.

@moul
Copy link
Member

moul commented Dec 7, 2023

I'm not sure about making this a default on gno.land, but it's a good and simple idea.

If we do this, we could try having RenderJSON return an interface{} and do the marshaling from the VMKeeper. This could help since we don't have the reflect package, yet. Maybe RenderObject is a better name?

For RenderHTML, I think we shouldn't use it to avoid issues with XSS and cookies.

@moul moul closed this as completed Dec 7, 2023
@moul moul reopened this Dec 7, 2023
@ajnavarro ajnavarro added 🧾 package/realm Tag used for new Realms or Packages. 🌟 improvement performance improvements, refactors ... labels Dec 11, 2023
@moul
Copy link
Member

moul commented May 22, 2024

Sure, here's an improved version of your comment:


New API I'm proposing for this:

// AnyHandler can be called by Gno import and "maketx q_eval --format=json".
// Depends on #1776.
// In the future, it could also be callable via a proxy server at api.gno.land to simulate a REST API.
func AnyHandler(input MyFirstType) MySecondType {
    // Implementation here
}

// Render returns Markdown content for the given path.
func Render(path string) string {
    // Implementation here
}

// RenderHTML returns HTML content for the given path.
// The HTML is published on a special permissionless playground server, like html.gno.land.
func RenderHTML(path string) string {
    // Implementation here
}

The goal is to avoid having MIME type support in Render() and to avoid any marshalling.

@moul moul added 📦 🤖 gnovm Issues or PRs gnovm related 📦 ⛰️ gno.land Issues or PRs gno.land package related labels May 30, 2024
@grepsuzette
Copy link
Contributor

To extend the versatility and usability of realms, I propose introducing additional rendering methods. This enhancement would allow realms to support various formats like HTML, JSON, etc., akin to how structures in Go can implement custom MarshalJSON and UnmarshalJSON methods for JSON processing.

Since realms can already export whatever function they want, perhaps we should try and turn the question upside down: which kind of consumer/client/device can we think of, which would need a such standardized function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 ⛰️ gno.land Issues or PRs gno.land package related 📦 🤖 gnovm Issues or PRs gnovm related 🧾 package/realm Tag used for new Realms or Packages. 🌟 improvement performance improvements, refactors ...
Projects
Development

No branches or pull requests

4 participants