2017 © Pedro Peláez
 

library lavender

jade-esque templates for PHP 5.3

image

lavender/lavender

jade-esque templates for PHP 5.3

  • Monday, July 18, 2016
  • by sudoreboot
  • Repository
  • 8 Watchers
  • 18 Stars
  • 5,194 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 3 Forks
  • 17 Open issues
  • 61 Versions
  • 0 % Grown

The README.md

Lavender

Lavender is a templating language for php loosely based on jade., (*1)

installation

via composer:, (*2)

first get yourself some composer. next you need to make yourself a composer.json, here's an example., (*3)

{
  "require": {
    "lavender/lavender": "*"
  }
}

then run php composer.phar install or composer install depending on how you installed composer. once composer has finished it will generate an autoloader in vendor/autoload.php which you can require() from your application's bootstrap process., (*4)

via git:, (*5)

add the lavender submodule with git submodule add git@github.com:golavender/lavender.git <folder to clone to> and include it with require "<where you put lavender>/src/Lavender/lavender.php", (*6)

usage

once you have installed and included lavender the only required configuration is to tell lavender where the views directory is., (*7)

Lavender::config(array(

  /*
   * required - path to views directory
   */
  'view_dir'       => String,

  /*
   * optional - cache view files, if this is true
   *            the cache folder needs to be emptied
   *            every time view files are changed
   */
  //'caching'        => FALSE,

  /*
   * optional - defaults to something random in your tmp directory
   */
  //'cache_dir'      => NULL,

  /*
   * optional - defaults to "lavender"
   */
  //'file_extension' => String,

  /*
   * optional - defaults to TRUE
   *
   * renders a debugging error page instead of throwing an exception.
   * in production you should disable this and use a 500 page.
   */
  //'handle_errors'  => Boolean, 
));

rendering a template is as easy as, (*8)

$output = Lavender::view('some_template')->compile();

// or if you need to pass data into the template (probably the case)

$output = Lavender::view('some_template')->compile(array(
  'data'      => 'some data that the template will use',
  'more_data' => "moar data",
));

language reference

html:, (*9)

section#some_id.foo.bar(attribute1='foo',attribute2='bar')

becomes, (*10)

<section id="some_id" class="foo bar" attribute1="foo" attribute2="bar"></section>

child nodes are indented below their parent, (*11)

section.foo
  div(data-something='foo') 
  div(data-something='bar') 

becomes, (*12)

<section class="foo">
  <div data-something="foo"></div>
  <div data-something="bar"></div>
</section>

there is a shortcut if you just want a div, you can skip right to class or id definitions, (*13)

.foobar text text
#foobar text text

becomes, (*14)

<div class="foobar">text text</div>
<div id="foobar">text text</div>

text can be added to nodes in two ways, (*15)

section.foo
  div(data-something='foo') this is some text 
  div(data-something='bar')
    | this is also some text 

Lavender knows not to put a closing tag on certain nodes. (we got the list from here), (*16)

input(type="text",value="fooooobar")

becomes, (*17)

<input type="text" value="fooooobar">

doctype:, (*18)

do you always forget the syntax for doctype? Lavender exists to solve your first world problems. just throw a !!! at the top of your layout and you get yourself a nice html doctype. doctypes supported are html, transitional, strict, frameset, 1.1, basic and mobile. here are some pretty examples., (*19)

!!!

defaults to html but you can also specify, (*20)

!!! html

the word doctype works too, (*21)

doctype html

```lavender doctype strict, (*22)


**comments** comments are a thing ```lavender // this is an html comment. it will be rendered to the page //- this is a lavender comment. it will not be rendered

conditional comments, (*23)

the IE shorthand can be used to generate conditional comments for Internet Explorer. check out this if you're not farmiliar with conditional comments., (*24)

IE
  script(src="some script to make IE work")
IE lt 7
  script(src="some script to make super old IE work")

becomes, (*25)

<!--[if IE]>
  <script src="some script to make IE work"></script>
<![endif]-->
<!--[if lt IE 7]>
  <script src="some script to make super old IE work"></script>
<![endif]-->

variables:, (*26)

lavender views can be passed variables from the parent php application or they can be defined right in the template., (*27)

this just assigns a variable without outputting anything to the page, (*28)

- some_variable = "this is stored in a variable"

note the - symbol, which evaluates an expression without outputting. the content of the variable can then later be output using the = symbol, (*29)

- some_variable = "this is stored in a variable"

span.foo= some_variable

span.bar
  = some_variable

becomes, (*30)

<span class="foo">this is stored in a variable</div>
<span class="bar">this is stored in a variable</div>

arrays too, (*31)

- some_array = ['foo', 'bar', 'baz']

and associative arrays, (*32)

- some_array = {key1: 'foo', key2: 'bar', key3: 'baz'} 

conditionals:, (*33)

markup can be conditionally rendered using the if keyword. Lavender supports all the conditional operations you know and love !, &&, ||, <. >, <=, >=, ==, != and does a truthy check against the result., (*34)

- some_variable = "this is stored in a variable"

if some_variable
  span.foo= some_variable

if some_variable_that_doesnt_exist
  span.foo this won't be rendered

if FALSE
  div this isn't rendered
elseif FALSE
  div still not rendered
elseif TRUE
  div wooooooooo
else
  div sadface

becomes, (*35)

<span class="foo">this is stored in a variable</div>
<div>wooooooooo</div>

TRUE and FALSE (and true and false) are keywords in Lavender, they can be assinged to variables or used in conditionals directly (but if you actually do that then wat), (*36)

- my_variable = TRUE

if my_variable
  div this will show up

if false
  div this will not

loops:, (*37)

Lavender supports iterating over arrays and associative arrays with the each keyword, (*38)

ul
  each value in some_random_array
    li= value 

ul
  each value, key in some_random_array
    li(data-key=key)= value 

you may have noticed how i snuck in using variables for your html attributes there, yea you can do that too., (*39)

else:, (*40)

the else keyword can be used after loops or conditionals, (*41)

if FALSE
  div will not show up
else
  div will show up

- empty_array = []

each value in empty_array
  div nothing to see here
else
  div empty array!

math:, (*42)

math. you can do it. supported operators are %, +, -, *, /, (, ), (*43)

div
  | 1 + 1 = 
  = 1 + 1

div
  | 2 - 3 = 
  = 2 - 3

div
  | 2 * 3 = 
  = 2 * 3

div
  | 10 / 5 = 
  = 10 / 5

ul
  each value, key in some_random_array
    if key % 2 == 0
      li(data-key=key)= value 

include:, (*44)

partials are a thing, (*45)

span stuff and things

div.content
  include /path/relative/to/view/directory/somefile

div.content
  include /path/relative/to/view/directory/somefile with {stuff: "Asdfasdf"}

extends:, (*46)

Lavender supports block style layout extension. this means that in the parent template you define blocks using the block keyword. then in the child template you only have blocks which override the blocks in the parent template, (*47)

so if this was layout.lavender, (*48)

h1 this is a pretty cool web page

block header
  | you can put some default content in here
  | it will be displayed if no child template
  | overrides it

div.content
  block content

and this is the child template, (*49)

extends layout

block header
  div
    span
      | foo bar baz


block content
  | content
  | more content
  | moar content

and you were to render the child temlate, you would get, (*50)



this is a pretty cool web page

foo bar baz
content more content moar content

a special case has been added to allow definining variables at the top of your child templates, these variables can be referenced from the layout to do cool things like specifying a list of javascript files necessary for a template to work or setting the page title., (*51)

whitespace

newlines are added automatically after every html element, if you don't want the newline you can add a - to the node definition like so., (*52)

p
  a(href="/some/place")- click here for some cool stuff
  |.

automagic whitespace management is hard and subject to change., (*53)

filters

programatic expressions in Lavender are a little limited, none of your favorite php functions are available for modifying the template data. this is by design, we don't think there should be a ton of logic in templates when that logic could be in controllers or models. however since you have to be able to do some templating logic we added filters. it's super easy to add your own filters to Lavender and there are (or will be) plenty in place out of the box. here's how they work., (*54)

- myvariable = "some really cool text"

div
  span
    | i'm gonna filter some stuff. it's gonna be cool. 
    = myvariable | upper 

becomes, (*55)

```html, (*56)

im gonna filter some stuff. it's gonna be cool. SOME REALLY COOL TEXT

```` profound right? not that we invented this, we copied the idea from twig. the filters Lavender comes with are:, (*57)

upper: ="string"|upper becomes STRING, (*58)

trim: =" string "|trim becomes string, (*59)

title: ="this is a title"|title becomes This Is A Title, (*60)

split: "these are some words"|split(' ') becomes the array ['these', 'are', 'some', 'words'], (*61)

sort: "these are some words"|split(' ')|sort becomes the array ['are', 'some', 'these', 'words'], (*62)

capitalize: = "these are some words"|capitalize becomes These are some words, (*63)

date: = "1396372567"|date becomes 4/1/2014 = "1396372567"|date('Y') becomes 2014, (*64)

default: = []|default('foobar') becomes foobar, (*65)

first: = ['asdf','qwer']|first becomes asdf, (*66)

join: = ['asdf','qwer']|join becomes asdf qwer = ['asdf','qwer']|join('-') becomes asdf-qwer, (*67)

last: = ['asdf','qwer']|last becomes qwer = ['asdf','qwer', 'zxcv']|last(2)|join('-') becomes qwer-zxcv, (*68)

keys: {'asdf': 'foo','qwer': 'bar'}|keys becomes the array ['asdf', 'qwer'], (*69)

length: = ['asdf','qwer']|length becomes 2, (*70)

lower: = "FOO BAR"|lower becomes foo bar, (*71)

nl2br: = "new\nline"|nl2br becomes new<br>line, (*72)

round: = 12345.123|round(2) becomes 12345.12, (*73)

merge: ['foo', 'bar']|merge(['baz']) becomes the array ['foo', 'bar', 'baz'], (*74)

replace: = "foo bar"|replace(' ', '-') becomes foo-bar, (*75)

reverse: ['asdf', 'qwer']|reverse becomes the array ['qwer', 'asdf'], (*76)

slice: ['foo', 'bar', 'baz']|slice(1, 1) becomes the array ['bar'], (*77)

number_format: = 10000000000.12345|number_format() becomes 10,000,000,000 = 10000000000.12345|number_format(2, ',', '.') becomes 10.000.000.000,12, (*78)

ceil: = 10000000000.12345|ceil becomes 10000000001, (*79)

floor: = 10000000000.12345|floor becomes 10000000000, (*80)

relative: if you had a timestamp variable timestamp|relative would return things like 'just now' or 'in 3 days' or 6 minutes ago, (*81)

contains: = ['asdf', 'qwer']|contains('asdf') returns TRUE, (*82)

is:, (*83)

= ['asdf', 'qwer']|is('list') returns TRUE, (*84)

= {asdf: 'qwer'}|is('object') returns TRUE, (*85)

= 8|is('number') returns TRUE, (*86)

= myVariable|is('My_Class_Name') also works, (*87)

json: = ['asdf', 'qwer']|json returns "['asdf','qwer']", (*88)

url_encode: = user@email.com|url_encode becomes user%40email.com, (*89)

The Versions

18/07 2016

dev-master

9999999-dev http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

12/07 2016

dev-first_filter_return_change

dev-first_filter_return_change http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

05/05 2016

dev-minmax

dev-minmax http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

10/02 2016

v0.26.1

0.26.1.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

14/12 2015

v0.26.0

0.26.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

11/06 2015

v0.25.0

0.25.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

08/06 2015

v0.24.1

0.24.1.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

05/06 2015

v0.24.0

0.24.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

11/05 2015

v0.22.4

0.22.4.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

11/05 2015

v0.23.4

0.23.4.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

29/04 2015

v0.22.3

0.22.3.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

29/04 2015

v0.22.1

0.22.1.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

08/04 2015

v0.22.0

0.22.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

03/04 2015

v0.21.0

0.21.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

02/04 2015

v0.20.0

0.20.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

30/03 2015

v0.19.1

0.19.1.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

02/03 2015

v0.19.0

0.19.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

11/02 2015

v0.18.4

0.18.4.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

09/02 2015

v0.18.3

0.18.3.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

04/02 2015

v0.18.2

0.18.2.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

03/02 2015

v0.18.1

0.18.1.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

03/02 2015

v0.18.0

0.18.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

02/02 2015

v0.17.0

0.17.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

02/02 2015

v0.17.1

0.17.1.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

13/01 2015

v0.16.1

0.16.1.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

13/01 2015

v0.16.0

0.16.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

12/01 2015

v0.15.4

0.15.4.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

12/01 2015

v0.15.3

0.15.3.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

16/12 2014

v0.15.2

0.15.2.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

12/12 2014

v0.15.1

0.15.1.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

12/12 2014

v0.15.0

0.15.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

10/12 2014

v0.14.2

0.14.2.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

28/11 2014

v0.14.1

0.14.1.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

01/10 2014

v0.14.0

0.14.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

17/09 2014

v0.13.0

0.13.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

16/09 2014

v0.12.0

0.12.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

16/09 2014

v0.11.0

0.11.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

16/09 2014

v0.10.0

0.10.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

16/09 2014

v0.9.0

0.9.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

15/09 2014

v0.8.1

0.8.1.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

15/09 2014

v0.8.0

0.8.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

19/08 2014

v0.7.5

0.7.5.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

06/08 2014

v0.7.4

0.7.4.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

29/07 2014

v0.7.3

0.7.3.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

28/07 2014

v0.7.2

0.7.2.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

28/07 2014

v0.7.1

0.7.1.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

25/07 2014

v0.7.0

0.7.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

24/07 2014

v0.6.0

0.6.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

21/07 2014

v0.5.3

0.5.3.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

07/07 2014

v0.5.2

0.5.2.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

29/05 2014

v0.5.1

0.5.1.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

22/05 2014

v0.5.0

0.5.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

05/05 2014

v0.4.3

0.4.3.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

05/05 2014

v0.4.2

0.4.2.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

05/05 2014

v0.4.1

0.4.1.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

01/05 2014

v0.4.0

0.4.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

30/04 2014

v0.3.0

0.3.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

30/04 2014

v0.2.1

0.2.1.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

22/04 2014

v0.2.0

0.2.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

29/03 2014

v0.1.1

0.1.1.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml

29/03 2014

v0.1.0

0.1.0.0 http://golavender.com

jade-esque templates for PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

templating jade haml