Giter Site home page Giter Site logo

pony-templates's Introduction

Templates

A template engine for Pony

Status

Templates is an alpha-level package.

As templates gets used in more projects, we expect to find and fix bugs. We also expect that we will make breaking changes.

Installation

  • Install corral
  • corral add github.com/ponylang/templates.git --version 0.2.3
  • corral fetch to fetch your dependencies
  • use "templates" to include this package
  • corral run -- ponyc to compile your application

API Documentation

https://ponylang.github.io/templates

How to use pony-templates

  • Add a line use "templates" to your source file

  • Load a template with Template.parse("Hello {{ name }}")?. Note that this method is partial. In other words, it can fail.

  • Create a TemplateValues object and fill it with the values you want to see in the rendered template:

      let values = TemplateValues
      values("name") = "world"
  • Finally, render the template with template.render(values)? (assuming template references your template). Note that this method is partial as well.

Supported Features

  • Variables: {{ some_var }} will be replaced with the variable some_var's value. A value can either be a String or a TemplateValue. A TemplateValue is either a String or a Seq[TemplateValue]].

  • Properties: {{ some_var.prop }} will be replaced with value some_var's property prop. Properties are part of TemplateValue: its constructor takes a Map[String, TemplateValue] that defines the value's properties.

  • For loops: {{ for x in xs }}{{ x }} {{ end }} will iterate through the sequence xs and adds each element plus a space to the output.

  • Conditional output: {{ if spam }}Eggs{{ end }} only adds Eggs to the output if the variable spam exists. Can also check for the presence of a property.

    {{ ifnotempty seq }} ignores everything until the next {{ end }} if sequence seq is empty.

  • Calls: {{ escape(var) }} calls escape with argument var and adds the function result to the output. All known functions must be passed as part of a TemplateContext value to the template's constructor.

pony-templates's People

Contributors

ponylang-main avatar seantallen avatar trundle avatar ergl avatar rhagenson avatar

Watchers

 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.