DEV Community

loading...

Pope.cr: Micro templating engine for strings only. (Crystal version of Pope.js)

wilsontov profile image Wilson Tovar ・1 min read

I have published the Crystal version of Pope: A fast, minimal and micro template engine for strings only, it plays well where you want to embed micro templates inside your module.

GitHub repo: https://github.com/krthr/pope.cr

Here is an example:

require "pope.cr"

data = {
  user: {
    id:       123,
    username: "krthr",
    admin:    true,
    config:   {
      email: "test@test.com",
    },
  },
}

Pope.pope(
  "The user {{user.username}} with id {{user.id}} is cool",
  data
) # "The user krthr with id 123 is cool"

Pope.prop(data, "user.id")           #  123
Pope.prop(data, "user.config.email") # test@test.com
Pope.prop(data, "nananana")          # nil
Enter fullscreen mode Exit fullscreen mode

I hope you enjoy!

Discussion (0)

pic
Editor guide