Giter VIP home page Giter VIP logo

herml's Introduction

Welcome to herml, the Haml-like templating language!

Building:
1) Install leex 0.3 or greater. Putting it in your $ERLANG_HOME/lib is best.
   leex is included with R13B01.
2) Clone the herml repo from Github.
3) Run make
4) Put the herml/ebin directory somewhere on your code path:
  4a) Symlink the top-level herml directory into your $ERLANG_HOME/lib directory
                                -or-
  4b) Use the -pz or -pa switches on erl to place herml/ebin onto your code path

Using in Sinan:
1) Clone the herml repo from Github
2) Run `make special` in the herml directory
3) Make sure your sinan project can find the herml repo
   3a) Clone inside your projects lib directory
                  -or-
   3b) Symlink the herml directory to your projects lib directory

4) Keep it up to date:
  a) Pull down latest changes
  b) `make clean`
  c) `make special`

Running tests:
1) Run make clean tests


Using herml:

1) Start up a herml_manager process for your template directory:

1> herml_manager:start_link(my_web_app,"/path/to/templates").

Note: herml_manager can cache the compiled template and use it over and over.

2) Execute the template by calling the herml_manager process:

2> Result = herml_manager:execute_template("file.herml", Env).

Note: Env is a proplist containing the execution environment for the
template. herml expects all variable names to be Erlang strings. For
example, here's a valid environment proplists: [{"UserName", "herml"}].

The UserName variable would be referenced from herml as @UserName.

Another note: For efficiency reasons, herml_manager:execute_template/2,3,4 
returns iolists when it executes templates. If you want to view the 
template output as a standard string, you can use the io module 
to flatten the iolist: 

3> io:format("~s", [Result]). 

herml's People

Contributors

asceth avatar averyj avatar seancribbs 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  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

herml's Issues

text after tag opening

Hi, nice stuff!

However I noticed that it fails to parse some common hamls:

%h1 Some title

or

%p
nice
%span Chicken Fried

Herml hangs in infinite recursion on double quotes and non-ASCII chars.

I've found Herml (tested on 2942bd1) to hang in parser-generated code on the following template:

!!!
%html
  %head
    %meta[{charset,"utf-8"}]/

Generated parser continued to recursively call itself herml_scan:string/4 in an endless loop, quickly hogging all memory. Unfortunately, I'm too newbie to Erlang and leex, so I don't really understand why this happens. Anyway, the calls are occurring in this way:

...
string/4(",\"utf-8\"}]/", 1, ",\"utf-8\"}]/", [{chr,1,"charset"},{lcurly,1,[123]},{lbrace,1,[91]},{chr,1,[109,101,116,97]},{tag_start,1,[37]}])
string/4("\"utf-8\"}]/", 1, "\"utf-8\"}]/", [{comma,1,[44]},{chr,1,"charset"},{lcurly,1,[123]},{lbrace,1,[91]},{chr,1,[109,101,116,97]},{tag_start,1,[37]}])
string/4("\"utf-8\"}]/", 1, "\"utf-8\"}]/", [{pipe,1,[]},{comma,1,[44]},{chr,1,"charset"},{lcurly,1,[123]},{lbrace,1,[91]},{chr,1,[109,101,116,97]},{tag_start,1,[37]}])
string/4("\"utf-8\"}]/", 1, "\"utf-8\"}]/", [{pipe,1,[]},{pipe,1,[]},{comma,1,[44]},{chr,1,"charset"},{lcurly,1,[123]},{lbrace,1,[91]},{chr,1,[109,101,116,97]},{tag_start,1,[37]}])
string/4("\"utf-8\"}]/", 1, "\"utf-8\"}]/", [{pipe,1,[]},{pipe,1,[]},{pipe,1,[]},{comma,1,[44]},{chr,1,"charset"},{lcurly,1,[123]},{lbrace,1,[91]},{chr,1,[109,101,116,97]},{tag_start,1,[37]}])
string/4("\"utf-8\"}]/", 1, "\"utf-8\"}]/", [{pipe,1,[]},{pipe,1,[]},{pipe,1,[]},{pipe,1,[]},{comma,1,[44]},{chr,1,"charset"},{lcurly,1,[123]},{lbrace,1,[91]},{chr,1,[109,101,116,97]},{tag_start,1,[37]}])
...

There are certainly no "|" characters in template, and I really don't know why {pipe,1,[]} is there.

After some mindless fiddling, I've found that similiar hangs happen on intentionally malformed %meta[{charset,"utf-8}]/ (missing second double quote) code, and when there are any "unknown" characters (for example, UTF-8 Cyrillic).

I've attempted to fix the issue with drdaeman/herml@58b4958, but due to a lack of expertise I don't know whenever this is the proper solution, or it just happen to work.

Proposal: compile each template to into a module

Although it spawns processes, I doubt that herml_manager may be a bottle neck.

I propose that a template be compiled to a module in-memory (the module name can be referred from the template path implicitly, or specified explicitly) with a function "render" so that it can render itself.

In other words, a template is converted into code instead of data. This way, the Erlang VM caches and manages the templates for us efficiently. When we want to render, just call it. When we want to update a template, just recompile it and the Erlang VM will automatically replace the old code with the new one for us.

For example, the library "erlang-gettext" can compile a plain text .po file to a module elegantly like this:
http://github.com/davide/erlang-gettext/blob/baee1560a705d1337fa05be822fde57abef1d312/src/gettext_generate.erl

For a feeling, ErlyDTL is working like this:
erlydtl:compile("/path/to/welcome.html", welcome_template),
welcome_template:render([
{name, "Johnny"},
{friends, [<<"Frankie Lee">>, <<"Judas Priest">>]},
{primes, [1, 2, "3", <<"5">>]}
]).

I'm new to AST. I found some instruction here:
http://www.evanmiller.org/write-a-template-compiler-for-erlang.html

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.