GithubHelp home page GithubHelp logo

quik's Introduction

Quik

Build Status - Travis CI

A fast and lightweight Python template engine

Features

  • Easy to use.
  • High performance.
  • Autoescaping.
  • Template inheritance.
  • Supports native python expressions.

Install

pip install quik

or developer mode:

pip install -r git+https://github.com/avelino/quik.git#egg=quik

Nutshell

Here a small example of a Quik template

<ul>
    #for @user in @users:
        #if @user.age > 18:
        <li><a href="@user.url">@user.username</a></li>
        #end
    #end
</ul>

Use It

Render via template:

from quik import FileLoader

loader = FileLoader('html')
template = loader.load_template('index.html')
print template.render({'author': 'Thiago Avelino'},
                      loader=loader).encode('utf-8')

Render via string:

from quik import Template

temp = Template("""
<ul>
    #for @user in @users:
        #if @user.age > 18:
        <li><a href="@user.url">@user.username</a></li>
        #end
    #end
</ul>
""")

users = [
    {'username': 'foo', 'url': 'http://...', 'age': 25},
    {'username': 'bar', 'url': 'https://...', 'age': 18}]

print temp.render(locals())

quik's People

Contributors

avelino avatar xuhdev 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

Watchers

 avatar  avatar  avatar  avatar  avatar

quik's Issues

if statement is not working in template

if i got template like:

if @session.user_id == @user.id:

  • @user.name
  • # end

    it gets rendered as:

    if 3 == 3:

  • John Doe
  • without evaluating the condition

    update:
    now I see that condition works with different syntax

    if(condition)

    ...

    end

    it is ok now

    New syntax to methods

    example

    #for @foo in @bar:
        <strong>@foo</strong>
    #end
    
    #if @foo > 10:
        <strong>Ok
    #end
    

    Removed () and add : end line.

    replace tokens containg dot defined in property files

    Hi there,
    I tried t use this library to replace tokens from one xml file that are defined in a property file.
    My case is:
    in myprops.properties contains following keys:
    application.server.host=192.168.101.105
    application.server.port=8888

    So in xml that I need to change, I will have


    But this is not working
    If the properties are changed to:
    applicationServerHost=192.168.101.105
    applicationServerPort=8888

    and the xml to:


    it's working without problem

    Can this kind of token be covered by a fix?
    Thank you in advance.

    example not working

    The example from the main page isn't working - not sure if i'm doing something wrong.

    from quik import Template

    temp = Template("""

    """)

    users = [
    {'username': 'foo', 'url': 'http://...', 'age': 25},
    {'username': 'bar', 'url': 'https://...', 'age': 18}]

    print temp.render(locals())

    /usr/local/bin/python quik_template_test.py
    Traceback (most recent call last):
    File "/Users/opensourcegeek/PycharmProjects/jsf_robot_case_generator/tests/py/quik_template_test.py", line 18, in
    print temp.render(users)
    File "/usr/local/lib/python2.7/site-packages/quik.py", line 27, in render
    self.merge_to(namespace, output, loader)
    File "/usr/local/lib/python2.7/site-packages/quik.py", line 37, in merge_to
    self.ensure_compiled()
    File "/usr/local/lib/python2.7/site-packages/quik.py", line 32, in ensure_compiled
    self.root_element = TemplateBody(self.content)
    File "/usr/local/lib/python2.7/site-packages/quik.py", line 157, in init
    self.parse()
    File "/usr/local/lib/python2.7/site-packages/quik.py", line 941, in parse
    raise self.syntax_error('block element')
    quik.TemplateSyntaxError: line 7, column 5: expected block element in template body, got: #end

    ...

    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.