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.crConstant Summary
-
VERSION =
"0.1.0"
Class Method Summary
-
.apply_filters(value, filters : Array(Filters))
apply a series of filters to a given value, in order
-
.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.
-
.prop(obj : NamedTuple | Hash, path : String = "")
get nested properties from a given object using dot notation
Class Method Detail
apply a series of filters to a given value, in order
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"
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