Skip to content

Very basic Swift templating engine. macOS and Linux ready.

License

Notifications You must be signed in to change notification settings

jcampbell05/Templater

Repository files navigation

Templater

Build Status Platforms Package Managers

Blog Twitter Czechboy0

Very basic Swift templating engine. macOS and Linux ready.

Templater is a very simple tool aimed at solving the simple task: in a string template, fill in a few variables with certain values. Something like Stencil or Mustache. Just a super simple version of them.

❓ Why?

I needed to fill in a large markdown file with fresh data every day, to generate a pretty report. The existing libraries seemed like an overkill for the simple usecase, so I wrote a lightweight (literally less than 100 lines of code) solution myself.

🚀 Features

The template string must contain one or more strings like {{ variable_name }}, such as Hello, {{ name }}!. When you render this template with the context of name = "world", you'll get Hello, world!.

🔨 Usage

do {
	//create the template
	let template = Template("Hello, {{ name }}! Today is {{ day }} and it will be {{ weather }}.")

	//have your context
	let context = [
		"name": "Tim",
		"day": "Thursday",
		"weather": "sunny"
	]

	//render the context
	let result = try template.fill(with: context)

	//result: "Hello, Tim! Today is Thursday and it will be sunny."
} catch {
	print("Template error: \(error)")
}

Installation

Swift Package Manager

.Package(url: "https://github.com/czechboy0/Templater.git", majorVersion: 0, minor: 2)

💙 Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

💝 Contributing

Please create an issue with a description of your problem or open a pull request with a fix.

✌️ License

MIT

👽 Author

Honza Dvorsky - http://honzadvorsky.com, @czechboy0