Skip to content

jasonprogrammer/glerd_example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Glerd Tutorial

This is an example Gleam project to help demonstrate how to use Glerd, a library that can generate metadata for Records in Gleam.

Instructions

  1. Clone this repository:
git clone https://github.com/jasonprogrammer/glerd_example.git
  1. Change into the glerd_example directory:
cd glerd_example
  1. Install glerd as a development dependency:
gleam add --dev glerd
  1. Run Glerd:
gleam run -m glerd
  1. After running this, you'll notice that Glerd has created a src/glerd_gen.gleam file locally. The file looks like this:
// this file was generated via "gleam run -m glerd"

import glerd/types

pub const record_info = [
  #(
    "User",
    "user",
    [
      #("id", types.IsInt), #("name", types.IsString),
      #("email", types.IsString),
    ],
    "",
  ),
]

This file was created as a result of Glerd scanning the src directory, finding the user.gleam file:

pub type User {
  User(id: Int, name: String, email: String)
}

and generating the glerd_gen.gleam metadata file.

How can we run Glerd each time we build the Gleam project?

There are multiple ways of doing this. Here's one possibility. We could:

  1. Clone the Glerd repository and build a single binary of Glerd using Gleescript.

  2. Add this glerd binary to the project repo so that we can run it each time we build the Gleam project (e.g. before running gleam run).

Creating a single binary helps us avoid adding all of Glerd's dependencies to our project, and helps us avoid rebuilding Glerd each time we want to invoke it.

  1. Use a shell script or task runner (e.g. task) to run Glerd and gleam run sequentially.

About

An example of using Glerd to generate metadata for records in a Gleam project

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages