pongo2

package
v0.0.0-...-aeb31df Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2016 License: BSD-3-Clause Imports: 2 Imported by: 0

README

Middleware information

This folder contains a middleware ported to Iris for a third-party package named pongo2.

More can be found here: https://github.com/flosch/pongo2

Description

pongo2 is the successor of pongo, a Django-syntax like templating-language.

Behaviour

  1. Entirely rewritten from the ground-up.
  2. Advanced C-like expressions.
  3. Complex function calls within expressions.
  4. Easy API to create new filters and tags (including parsing arguments)
  5. Additional features: 1. Macros including importing macros from other files (see template_tests/macro.tpl) 2. Template sandboxing (directory patterns, banned tags/filters)

Notes


<html><head><title>Our admins and users</title></head>
{# This is a short example to give you a quick overview of pongo2's syntax. #}

{% macro user_details(user, is_admin=false) %}
    <div class="user_item">
        <!-- Let's indicate a user's good karma -->
        <h2 {% if (user.karma >= 40) || (user.karma > calc_avg_karma(userlist)+5) %}
            class="karma-good"{% endif %}>

            <!-- This will call user.String() automatically if available: -->
            {{ user }}
        </h2>

        <!-- Will print a human-readable time duration like "3 weeks ago" -->
        <p>This user registered {{ user.register_date|naturaltime }}.</p>

        <!-- Let's allow the users to write down their biography using markdown;
             we will only show the first 15 words as a preview -->
        <p>The user's biography:</p>
        <p>{{ user.biography|markdown|truncatewords_html:15 }}
            <a href="/user/{{ user.id }}/">read more</a></p>

        {% if is_admin %}<p>This user is an admin!</p>{% endif %}
    </div>
{% endmacro %}

<body>
    <!-- Make use of the macro defined above to avoid repetitive HTML code
         since we want to use the same code for admins AND members -->

    <h1>Our admins</h1>
    {% for admin in adminlist %}
        {{ user_details(admin, true) }}
    {% endfor %}

    <h1>Our members</h1>
    {% for user in userlist %}
        {{ user_details(user) }}
    {% endfor %}
</body>
</html>

Usage


package main

import (
	"github.com/kataras/iris"
	"github.com/kataras/iris/middleware/pongo2"
)

func main() {
	iris.Use(pongo2.Pongo2())

	iris.Get("/", func(ctx *iris.Context) {
		ctx.Set("template", "index.html")
		ctx.Set("data", map[string]interface{}{"message": "Hello World!"})
	})

	iris.Listen(":8080")
}


Documentation

Overview

Copyright (c) 2016, Gerasimos Maropoulos All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  1. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  1. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER AND CONTRIBUTOR, GERASIMOS MAROPOULOS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pongo2

func Pongo2() *pongo2Middleware

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL