Giter Site home page Giter Site logo

tasty's Introduction

TASTY

Tom's Amazingly Simple Templates, Yeah!

TASTY is a template format for defining just dang simple templates.

Note: This (semi-)specification and library currently only exist for some internal purposes in Axiom - beyond that unfortunately I don't have the time to maintain or add features to it. However if this is useful to you, more contributors are always welcome!

Show me some examples

Yes sir.

You can substitute variables:

fn main() {
    {{FUNC_NAME}}();
}
// with `FUNC_NAME` = "hello_world", becomes:
fn main() {
    hello_world();
}

You can substitute variables in variables:

fn main() {
   {{{{TO_CALL}}_NAME}}();
}
// with `TO_CALL` = "THING", and `THING_NAME` = "nice_one", becomes:
fn main() {
    nice_one();
}

You can loop:

fn main() {
    {%LOOP {{LOOP_TIMES}}%}
    {{FUNC_NAME_{{LOOP_INDEX}}}}();
    {%END%}
}
// With:
//  - LOOP_TIMES = "3"
//  - FUNC_NAME_0 = "first_func"
//  - FUNC_NAME_1 = "second_func"
//  - FUNC_NAME_2 = "third_func"
// becomes:
fn main() {
    first_func();
    second_func();
    third_func();
}

You can branch:

fn main() {
    {%LOOP {{LOOP_TIMES}}%}
    {%IF {%NOT {{LOOP_INDEX}}%}%}
    called_first_iteration();
    {%END%}
    {%IF {{LOOP_INDEX}}%}
    called_every_other_iteration();
    {%END%}
    {%END%}
}
// With `LOOP_TIMES` = "3", becomes:
fn main() {
    called_first_iteration();
    called_every_other_iteration();
    called_every_other_iteration();
}

And you can set scoped variables:

fn main() {
    {%WITH NAMESPACE={{AUTHOR}}_{{TOOLKIT}}, FUNC_NAME={{NAMESPACE}}_{{FUNC_NAME}}%}
    {{FUNC_NAME}}();
    {%END%}
    {{FUNC_NAME}}();
}
// With `AUTHOR` = "me", `TOOLKIT` = "stuff" and `FUNC_NAME` = "the_func", becomes:
fn main() {
    me_stuff_the_func();
    the_func();
}

And that's literally it! You can do a lot with these primitives, and even more by putting the complex logic in the underlying controller, where it lives.

Things that would be nice to have (in order)

  • Proper documentation
  • Tests
  • Ability to put in a {{ or {% without it being interpreted as the start of some statement (i.e escaping it)
  • Cleaner code (everything's just a quickly written hack at the moment, but it works ¯\_(ツ)_/¯)
  • Put it on crates.io

License

MIT, yo. Check the LICENSE file for more details.

tasty's People

Contributors

bennetthardwick avatar cpdt avatar

Watchers

 avatar  avatar

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.