Awesome Open Source
Awesome Open Source

Tuxedo

Travis CI status Framework version Swift version Code Test Coverage Platforms Lincese

Dependency Managers

CocoaPods compatible Swift Package Manager compatible Carthage compatible


👨🏻‍💻 About

Tuxedo is a template language for Swift. It allows you to separate the UI and rendering layer of your application from the business logic. Smart templates working with raw data allow the frontend to be handled and developed separately from other parts of the application, so processing, layouting and formatting your output can be defined in very simple template formats.

Why the name? It dresses up your static output with elegant dynamic templates, using control statements, and high level operators.

The project was built upon my lightweight interpreter framework, Eval, and served as an example application of what is possible using this evaluator.

Soon, the template language example turned out to be a really useful project on its own, so I extracted it to live as a separate library and be used by as many projects as possible. I see the possibility of applications most valuable especially in server-side Swift projects, but there are a lot of other areas where template parsing fits well.

The project - though most of its featureset is already available - is still having its early days, there is a lot of work needed to be done around open-sourcing activities, such as CI, contribution guidelines and extensive documentation. At this stage, if you're interested in what is already possible using Tuxedo, I encourage you to check out the unit tests and see the use-cases there until the documentation gets ready, or see some of the examples below. Please stay tuned for updates!

The inspiration was the excellent PHP template engine, Twig, and the fact that there is no existing, comprehensive-enough templating library available for the Swift language and platform.

👀 Getting Started

You can evaluate basic expressions ...

let result = Tuxedo().evaluate("Hello {{ name }}!", variables: ["name": "Tuxedo"]) // Hello Tuxedo!

... or even complex ones ...

let result = Tuxedo().evaluate("""
The results are: 
	{% for item in results.sort.reverse %}
		{% if item is not first %}, {% endif %}
		{% if item is last %} and {% endif %}
		{{ item * 2 }}
	{% endfor %}
""", variables: ["results": [3, 1, 2]]) // The results are: 6, 4 and 2

... define macros ...

let templateEngine = Tuxedo()
let _ = templateEngine.evaluate("{% macro concat(a, b) %}a + b{% endmacro %}")
let result = templateEngine.evaluate("{{ concat('Hello ', 'World!') }}") // Hello World!

... or blocks ...

let templateEngine = Tuxedo()
let result = templateEngine.evaluate("""
<html>
	<head>
		<title>
			{% block title %}Website{% endblock %}
		</title>
	</head>
	<body>
		{% block body %}{% endblock %}
	</body>
</html>
""")

... and override them later ...

{% block title %} {{ parent() }} - Subpage {% endblock %}
{% block body %} Content {% endblock %}

Tuxedo handles all kinds of expressions you can imagine. It works with numeric types, strings, booleans, dates, arrays and dictionaries.

You can perform all sorts of operations with functions and operators, such as numeric and logical operations, string manupulation, date formatting, higher level array and dictionary operations, and so on.

It works with hard-coded string inputs and also template files written from disk.

🙋 Contribution

Anyone is more than welcomed to contribute to this great project! Just fire up an issue or pull request to get the conversation started!

👤 Author

I am Laszlo Teveli, software engineer, iOS evangelist. In my free time I like to work on my hobby projects and open sourcing them 😉

Feel free to reach out to me anytime via tevelee [at] gmail [dot] com, or @tevelee on Twitter.

⚖️ License

Tuxedo is available under the Apache 2.0 licensing rules. See the LICENSE file for more information.


Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Swift (94,735) 
Template (7,540) 
Template Engine (826) 
Related Projects
Advertising 📦 9
All Projects
Application Programming Interfaces 📦 120
Applications 📦 181
Artificial Intelligence 📦 72
Blockchain 📦 70
Build Tools 📦 111
Cloud Computing 📦 79
Code Quality 📦 28
Collaboration 📦 30
Command Line Interface 📦 48
Community 📦 81
Companies 📦 60
Compilers 📦 60
Computer Science 📦 74
Configuration Management 📦 39
Content Management 📦 167
Control Flow 📦 197
Data Formats 📦 77
Data Processing 📦 266
Data Storage 📦 132
Economics 📦 60
Frameworks 📦 198
Games 📦 122
Graphics 📦 103
Hardware 📦 148
Integrated Development Environments 📦 47
Learning Resources 📦 147
Legal 📦 28
Libraries 📦 119
Lists Of Projects 📦 21
Machine Learning 📦 336
Mapping 📦 61
Marketing 📦 15
Mathematics 📦 55
Media 📦 228
Messaging 📦 97
Networking 📦 304
Operating Systems 📦 84
Operations 📦 120
Package Managers 📦 52
Programming Languages 📦 229
Runtime Environments 📦 96
Science 📦 42
Security 📦 375
Social Media 📦 26
Software Architecture 📦 70
Software Development 📦 68
Software Performance 📦 57
Software Quality 📦 127
Text Editors 📦 45
Text Processing 📦 131
User Interface 📦 310
User Interface Components 📦 465
Version Control 📦 29
Virtualization 📦 68
Web Browsers 📦 38
Web Servers 📦 25
Web User Interface 📦 194