Coder Social home page Coder Social logo

jincaogg / art-mustache Goto Github PK

View Code? Open in Web Editor NEW

This project forked from itmuse/art-mustache

0.0 2.0 0.0 77 KB

Art Mustache is simple syntax template engine and It is not a new programming language itself, but uses native language(just like python) syntax for having code.

art-mustache's Introduction

Art Mustache

##About ArtMustache

Art Mustache is simple and it was designed as an easy to learn, compact and expressive template engine that enables a fluid coding workflow.

Art Mustache is not a new programming language itself, but uses native language(just like python) syntax for having code.

##ArtMustache Syntax

Before getting introduced to Art Mustache you should first know some simple rules that will help you understand how to write template with python in the same page:

  1. '@' is the magic character that precedes code instructions in the following contexts:

    1. '@' For a single code line/values: A single code line inside the markup:

      	<p>Hello @variable</p>
    2. '@{...}' For a single code line/python code:

      	@{my_name = 'I am art mustache.'}
      
          @{status = True}
      
          @{my_name = 'art mustache' if status else 'no art mustache'}
    3. '@{...}' For code blocks with multiple lines:

      	@{
          	def say_hello(name):
                  return 'hello %s' % name
              name = 'Hyson'
              
              say_hello(name)
              
              if name == 'Hyson':
                  for n in ['hello',name]:
                      @:<li>@i</li> # @: syntax
              else:
                  say_hello('you have no name.')
           
      	}
    4. '@:' For single plain text to be rendered in '@{}' in template:

      	@{
              for i in range(10):
                  @:this is a single plain text,this is @i line.
          }
  2. plain text or HTML markup can be included at any part of the code:

    It is no need to open or close code blocks to write HTML inside a page. If you want to add a code instruction inside HTML, you will need to use โ€˜@โ€™ before the code:

    	@{your_name = 'geeker'}
    
        @def func(name){
            <h1>Hello @name</h1>
        }
    
        @{func2 = lambda x,y:x+y}
    
        @if status == 1{
            <span>Hello,what's are you doing?</span>
        }@elif status == 1{
            <span>Hello @your_name,do you like a simple template engine?</span>
        }@else{
            <span>I am sorry to that.</span>
        }
    
        @for i in range(20){
            @if i % 2{
                <li class="odd">@i</li>
            }@else{
                <li class="even">@i</li>
            }
            @func('art mustache'+str(i))
        }
    
        @{index=0}
    
        @while index<10{
            @if i % 2{
                <li class="odd">@i</li>
            }@else{
                <li class="even">@i</li>
            }
            @func('art mustache'+str(i))
        }
    
        @try{
            @{1+'a'}
        }@except Exception as e{
            <span><b style="color:red"></b>@e</span>
        }
    
  3. How to use Art Mustache

    	tpl = """
               @name
        ~~~~~~~~~~~~~~~~~
        @{my_name = 'hyson'}
        @{
            def say_hello(name):
                return 'hello'+str(name)
        }
        @for i in numbers{
            <li>line @i</li>
        }
        @say_hello(my_name)
        @say_hello('world')
        """
        t = ArtMustache(tpl)
        print t.render(
            name='Art Mustache',
            numbers=[1,2,3,4,5,6]
            )

##Copyright Copyright (c) 2012 Hyson Wu. All rights reserved.

##License Art Mustache is MIT Lisense

art-mustache's People

Contributors

itmuse avatar

Watchers

James Cloos 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.