Code Monkey home page Code Monkey logo

pyhaml's Introduction

#pyHaml

deprecated: do not use.

pyHaml is a python port of Haml, an HTML templating engine used primarily with Ruby on Rails. Ruby Haml will be referred to as rHaml for the purposes of this document.

In order to make pyHaml a bit more pythonic, most of the syntax evaluated as Ruby in rHaml is evaluated as python. For example, instead of using ruby hashes for attributes pyhaml uses python dict syntax:

%tagname{'attr1': 'value1', 'attr2': 'value2'} Contents

pyHaml aims to be flexible and intuitive, allowing python to be evaluated inline as would be expected.

-def foo(i):
  %p = i ** 2
-for i in range(4):
  -foo(i)

yields

<p>0</p>
<p>1</p>
<p>4</p>
<p>9</p>

By allowing haml inside of python code blocks, some handy functionality can be produced through function composition. For instance, to wrap the output of a function in some predefined html one could use the following construct:

-def wrap(f):
  .wrapper
    %p
      -f()

-def foo():
  foo

-wrap(foo)

which produces the following html:

<div class="wrapper">
  <p>
    foo
  </p>
</div>

#imports

Markup should be reused just like code (since it is code). In this vein there should be some way to use one haml document from within another. In the spirit of python, pyHaml does this using the import statement. For instance, assuming the following two documents:

-# foo.haml
-def foo():
  %p foo

-# bar.haml
-import foo
-foo.foo()

rendering bar.haml produces <p>foo</p>. Some versions of python, particularly the one used in google appengine, cache imports. This makes it impossible to use import for this purpose. For this reason, the _haml.imp method is provided instead. In the previous example the line -import foo would be written as -foo = _haml.imp('foo').

#portability

pyHaml runs on python 2.5, 2.6, 2.7 and the latest version of python 3.

pyhaml's People

Contributors

braddunbar avatar kroo avatar

Stargazers

 avatar  avatar

Watchers

 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.