Exemple #1
0
def main(p):
    with p(html.html()):
        with p(html.head()):
            p(html.title('Weby templates'))
        with p(html.body({'style':'max-width:600px'})):
            p(html.h1('Weby templates'))

            p(html.p(u"""
                Weby Templates are used in production on websites that have garnered over 500,000 uniques a month.  They are incredibly easy to work with.  They are the "templates for lazy people".  They have 3 main benefits:
            """))

            with p(html.ul()):
                p(html.li(u'easier'))
                p(html.li(u'faster'))
                p(html.li(u'more flexible'))
                #p(html.li(u'shorter'))
                #p(html.li(u'safer') # when it has object cleaning

            p(html.p(u"""
                The main codebase is implemented in 100 source lines of code.  Extensive libraries only add just a couple hundred other lines of code. It is simple.  It ensures that all tags have closing tags.  It is compiled and fast.  It is unicode compliant and safe.  You can be fully fluent within 5 minutes since it is just Python and a transparent library.
            """))

            p(easier())
            p(faster())
            p(more_flexible())


            p(faq())
Exemple #2
0
def easier(p):
    p(html.h2(u'Easier'))
    p(html.p(u"""
       Writing with weby templates takes less than 3 minutes to learn.  Below is a sample:
    """))

    with p(html.table({'width':'80%'})):
        with p(html.tr({'width': '100%'})):
            with p(html.td({'width':'40%', 'valign': 'top'})):
                with p((u'<pre><code>', u'</code></pre>')):
                    p(html.h("""
import weby_templates as weby
from weby_templates.templates.lib import html

@weby.template()
def index(p):
    with p(html.html()):
        with p(html.head()):
            p(html.title('Hello, World!'))
        with p(html.body()):
            p(html.h1('Hello, World!'))
            p(html.p('Please choose from the following items:'))
            with p(html.ul()):
                p(html.li('Lorem'))
                p(html.li('Ipsum'))
                p(html.li('Dolor'))
            with p(html.div({'class':'footer'})):
                p(u'About | Links | ... | ')
                    """))
            with p(html.td({'width':'20%', 'valign': 'top'})):
                p(u'&nbsp;')
            with p(html.td({'width':'40%', 'valign': 'top'})):
                with p((u'<pre><code>', u'</code></pre>')):
                    p(html.h(u"""
<html>
    <head>
        <title>Hello, World!</title>
    </head>
    <body>
        <h1>Hello, World!</h1>
        <p>
            Please choose from the following items:
        </p>
        <ul>
            <li>Lorem</li>
            <li>Ipsum</li>
            <li>Dolor</li>
        </ul>
        <div class="footer">
            About | Links | ... | 
        </div>
    </body>
</html>
                    """))

    p(split_paragraphs(u"""
        Fundamentally, weby templates are based on 3 simple concepts.  
    """))

    with p(html.ol()):
        p(html.li(u"""
        First, use Python to its fullest.  Weby does not invent a new esoteric language for you to learn. You know enough useful ones already.  For mature developers, using the full power of Python makes things obvious and intuitive.  Moreover, the simplicity allows the core code of Weby Templates to be just 100 lines.  

        Every template is just a function that returns a unicode string.  A template is just a string, not a fancy programming language or a complicated environmental-variable dependent rigamarole.  Just call any functino that returns a string.
        """))

        p(html.li(u"""
        Second, we include a decorator to make building the string easier.  @weby.template() is a decorator that adds a first argument to the function.  This first argument is an accumulator, conventionally named 'p', as in 'print'.  With it, you can basically print out each html element in the text.  It can also work with the 'with' statement in Python to ensure that all tags are properly enclosed.
        """))

        p(html.li(u"""
        Finally, straightforward helper libraries exist that make writing html or xml or using filters (functions that accept and output strings) easier.  For example, the html library is extremely useful.  Every html tag has an analogous function in the html library, as seen above.  The first argument are the content words, and the second argument is a dictionary of the attributes.  If the tag is in a with statement, then the first argument is just the dictionary of the attributes of the tag (since the contents are contained within the with statement.  That's all of the documentation you need to be productive in the library.
        """))

    p(split_paragraphs(u"""
        This README is generated with Weby templates if you want more examples.

    """ + html.code('./README.py > README.html') + u"""

    or

    """ + html.code('./README.py | ./weby_templates/tools/beautifier.py > README.html') + u"""
"""))