Coder Social home page Coder Social logo

tevelee / tuxedo Goto Github PK

View Code? Open in Web Editor NEW
88.0 4.0 5.0 1.34 MB

Tuxedo is a template language for Swift.

Home Page: https://tevelee.github.io/Tuxedo/

License: Apache License 2.0

Swift 39.92% HTML 35.13% CSS 15.00% JavaScript 5.01% Ruby 4.73% Shell 0.22%
template swift template-language template-engine tuxedo

tuxedo's Introduction

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.

tuxedo's People

Contributors

daniel-muhra-cw avatar dependabot[bot] avatar tevelee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

tuxedo's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.