module Pope

Overview

NOTE Pope.cr is 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.

Defined in:

pope.cr

Constant Summary

VERSION = "0.1.0"

Class Method Summary

Class Method Detail

def self.pope(string : String, data : NamedTuple, opts = {skipUndefined: false, throwOnUndefined: false}) #

parses a given template string and replace dynamic placeholders with actual data.

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"

[View source]
def self.prop(obj : NamedTuple, path : String) #

get nested properties from a given object using dot notation

data = {
  user: {
    id:       123,
    username: "krthr",
    admin:    true,
    config:   {
      email: "test@test.com",
    },
  },
}
Pope.prop(data, "user.id")           #  123
Pope.prop(data, "user.config.email") # test@test.com
Pope.prop(data, "nananana")          # nil

[View source]