Isomorphic-crystal-view :a Vue-like developing approach to Crystal GUI development (writing no HTML or JS, just Crystal classes)

Yet another approach to developing GUI’s for Desktop apps using Crystal and Webview

Specificity of this variant :

  1. The underlying HTML is generated using “Blueprint”, which allows for a Vue-like developing experience (while writing no HTML or JS).
  2. The code that generates the interface maps the actual visual layout of the interface elements.
  3. Basically, Blueprint plays the role of JSX in React.

Excerpt:

class Form
  include Blueprint::HTML

  def initialize(@state : Int32 = state)
  end

  private def blueprint
    # Global style
    style { picoCSS }

    # Local widget Style
    style { <<-CSS
      article {
        padding: 20px;
      }
      input {
        border: 1px solid black;
      }
      CSS
    }

    # Widget description

    # Links (routing)
    a href: "/hello" {"[Hello]"} 
    a href: "/#{ROOT}" {"[Root]"} 
    
    br 
    br

    div {
      article {
        form action: "/get_name", method: "POST" {

          label for: "#{Fname}" { "First name" }
          input type: "text", id: Fname, name: Fname

          br

          label for: "#{Lname}" { "Last name" }
          input type: "text", id: Lname, name: Lname

          br
          br

          input type: "submit", value: "Get name (and increment state)"
        }

        br

        form action: "/reset", method: "POST" {
          input type: "submit", value: "Reset state"
        }
      }

      article {
        label { "#{@state}" }
      }
    }
  end
end
3 Likes

Although I’m not a fan of JSX and similar, I acknowledge that many like it.

This positively enriches the Crystal ecosystem and, at the same time, is a creative, functional and useful approach for the target audience.

1 Like

It is

  1. Expressive / intuitive
  2. Concise.
  3. Its code structure matches the widgets hierarchy / layout of the app (not unlike HTML tags).
  4. No extra parser or language needed: its all Crystal.
1 Like

New version:

  • Improved CSS.
  • Modular GUI development example (as in Svelte, for instance).
2 Likes

How does it compare to Lucky framework template methods?
You also mentioned front-end frameworks like Svelte. Is this reactive on the front-end, just like Svelte, or uses backend rendering?

It is Backend rendering, but the widgets can be built in a modular manner.

It is Backend rendering, but one could create separately custom HTML tags with Svelte (for instance) that would do some client-side stuff or alternatively use a prefabricated HTML/JS/Css object
(widget) which does its own client-side stuff (like, e.g. an editor widget written in javascript)…