Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • BackTrack 5 R2
  • Wine 1.4 / 1.5.5
  • Mozilla Firefox 12...
  • Ubuntu 11.04
  • Angry Birds 1.1.2.1
  • Ubuntu 10.04.4 LTS
  • Linux Kernel 3.4
  • Ubuntu Manual 10.10
  • Adobe Flash Player...
  • Pidgin 2.10.4
  • Home > Linux > Programming > Libraries

    mint 0.5

    Download button

    No screenshots available
    Downloads: 170  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Tim Perevezentsev | More programs
    Other/Proprietary Li... / FREE
    August 2nd, 2011, 23:26 GMT
    ROOT / Programming / Libraries

     Read user reviews (0)  Refer to a friend  Subscribe

    mint description

    Simple indetion based template engine

    mint is single Python module that allows you to write short html/xml templates, which then work fast. Template engine was inspired by haml (a template engine written in ruby), but some conceptions were redisigned due to simplification.

    mint uses AST python module to compile python bytecode from templates. So, during first call template is compiling and  every next call to it takes really small amount of time (of course it depends on python method and attribute calls in template).

    Example:

        @html
            @head
                @title {{ title }}
            @body
                @div.id(wrapper)
                    @div.id(header)
                        #def content(action='hello'):
                            @p.class(slot)
                                {{ action }}, {{ name }}!
                        #content()
                    @div.id(footer)
                        Here we have banners from our sponsors


    If you execute this template with namespace {'title':'site title', 'name':'mint'}, you will get

        < html >
            < head >
                < title >site title< /title >
            < /head >
            < body >
                < div id="wrapper" >
                    < div id="header" >
                        < p class="slot" >
                            hello, mint!
                        < /p >
                    < /div >
                    < div id="footer" >
                        Here we have banners from our sponsors
                    < /div >
                < /div >
            < /body >
        < /html >


    @ - token defines tags, all tag attributes are dot-separated name of attrubte values pairs, values can be text or variables or mixed.

        @a.href({{ url }}).title(Url to somewhere) {{ name_of_somewhere }}

        < a title="Url to somewhere" href="http://somewhere">somewhere site title< /a >

    # - token defines special parts of templates such as loops, conditions and slots

        @ul
            #for i in range(10)
                #if i % 2
                    @li {{ i }}
                #else
                    @li.class(odd) {{ i }}

        < ul >
            < li >0< /li >
            < li class="odd" >1< /li >
            < li >2< /li >
            ...
            < li class="odd" >9< /li >
        < /ul >


    NOTE: ':' colon at the end of python expression may be ommited
    NOTE: condition and loop statements may have any valid python expressions (!).

    Slots - something like python functions, which can be defined at any place of template and then call in other place.  Template inheritance implements with slots, so it is very important part of mint.

        #def content(action='hello'):
            @p.class(slot)
                {{ action }}, {{ name }}!


    Slot have scope (!) and see global variables too (variables which came to template from inside). In this case {{ action }} is local variable, but {{ name }} is not. If you want to inherit a template just tell mint which template and implement slots you want to change.

        #base: hello.mint

        #def content(action='Hello'):
            @p.class(slot)
                {{ action }}, {{ name }}! You are inherited!


    This template inherits first template defined in this memo and overrides slot "content", so when you will compile and  execute last template you would see something like

        < html >
            < head >
                < title >site title< /title >
            < /head >
            < body >
                < div id="wrapper" >
                    < div id="header" >
                        < p class="slot" >
                            Hello, mint! You are inherited!
                        < /p >
                    < /div >
                    < div id="footer" >
                        Here we have banners from our sponsors
                    < /div >
                < /div >
            < /body >
        < /html >


    API:

    For end user there is one useful class Loader

        from mint import Loader

        loader = Loader(PATH_TO_TEMPLATES, cache=True)
        print loader.get_template(TEMPLATE_NAME).render(**kwargs).encode('utf-8')


    If you want to see python code, to which your template will be compiled run

        $python mint.py hello.mint


    Product's homepage

    Requirements:

    · Python

      


    TAGS:

    template engine | Python library | indetion | template | engine



    HTML code for linking to this page:


    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM