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.apply_filters(value, filters : Array(Filters)) #

apply a series of filters to a given value, in order


[View source]
def self.pope(string : String, data : NamedTuple, opts = {skip_undefined: false, throw_on_undefined: false}) #

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

data = {
  user: {
    id:       123,
    username: "krthr",
    admin:    true,
    config:   {
      email: "[email protected]",
    },
  },
}
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 | Hash, path : String = "") #

get nested properties from a given object using dot notation

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

[View source]