2017 © Pedro PelĂĄez
 

library zenml

Converts Hamlbar-like string to Handlebars template

image

savageman/zenml

Converts Hamlbar-like string to Handlebars template

  • Thursday, January 30, 2014
  • by Savageman
  • Repository
  • 2 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

ZenML

I love Handlebars, but I find it still lacks indentation-based DOM tree (like Haml) & Emmet/CSS syntax for ID and classes., (*1)

So I made this pre-processor to solve the problem. It generates Handlebars., (*2)

Quick guide

  • A line containing an HTML tag starts with % ;
  • Indentation is used to create the DOM tree ;
  • Indentation also works for Handlebars {{#helpers}} ;
  • Attributes are added using the regular HTML syntax: title="This is the title" ;
  • Text node can be added either:
    • On a new line using indentation
    • As a text attribute of the current tag: text="This is my text"
  • Any unrecognised line is interpreted as plain-text.

Example

%h1 text="This is my title"

%div #container

    {{ #each items }}
        %h2 text="{{title}}"
        %span .date text="{{date}}"
        %div .description
            The description is a bit longer,
            so I split it on several lines.

    {{ else }}
        %p text="Nothing here..."

%footer
    This is the end of the example.

is converted into:, (*3)



This is my title

{{#each items}}

{{title}}

{{date}}
The description is a bit longer, so I split it on several lines.
{{else}}

Nothing here..., (*4)

{{/each}}
<footer> This is the end of the example. </footer>

Usage

$template = <<<TEMPLATE
%div id="test"
    %p text="First line"
    %p text="Second line"
Plain-text for the end
TEMPLATE;

$zenml = new Zenml\Zenml(array(
    'prepend' => '',
    'input_indentation' => '    ',
    'output_indentation' => '    ',
));

echo htmlspecialchars($zenml->render($template));

Limitations

(I'll be glad if people could help me out sorting these out.), (*5)

  • You must put a space between the tag name and each CSS-like #id and .classes attributes ;
  • Text node must be on a new line (it would be nice to allow it at the end of the line) ;
  • Only one tag per line.

Todo

The Versions

30/01 2014

dev-master

9999999-dev https://www.github.com/Savageman/zenml

Converts Hamlbar-like string to Handlebars template

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Julian Espérat (Savageman)

templating handlebars haml