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
-
.pope(string : String, data : NamedTuple, opts = {skipUndefined: false, throwOnUndefined: false})
parses a given template string and replace dynamic placeholders with actual data.
-
.prop(obj : NamedTuple, path : String)
get nested properties from a given object using dot notation
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"
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