WLang is a general-purpose (code generation / templating) engine.
Latest commit 732b5d3 Sep 28, 2015 @blambeau Merge pull request #5 from john-denisov/patch-1
Fix wrong Highlighter example syntax in README.md
Failed to load latest commit information.
bin Add wlang command line + example Jan 23, 2012
doc Enhance README, add section about sinatra. Jun 13, 2012
lib FIX# warning: private attribute? Jan 2, 2015
scripts Add helper scripts. Jun 1, 2012
tasks Bundle up, noe up May 31, 2012
.gitignore Use Viiite edge for benchmarks Jan 25, 2012
.travis.yml Allow failures on rbx. Mar 6, 2013
CHANGELOG.md Fix dialect being not shared accross all sinatra partials. Jul 29, 2014
Gemfile Bump to Temple >= 0.6 Jul 29, 2013
Gemfile.lock Bump to Temple >= 0.6 Jul 29, 2013
LICENCE.md Initial commit (v2.0.0) Jan 12, 2012
Manifest.txt Clean manifest Jun 12, 2012
README.md Fix wrong Highlighter example syntax in README.md Sep 24, 2015
wlang.gemspec Bump to Temple >= 0.6 Jul 29, 2013
wlang.noespec Release v2.2.4 Jul 29, 2014



Build Status

WLang is a powerful code generation and templating engine, implemented on top of temple and much inspired by the excellent mustache.



  • Tunable templating engine. You can define your own tags, and their behavior.
  • Powerful logic-less HTML concretization to render web pages à la Mustache with extra.
  • Compiled templates for speedy generation.
  • Tilt and Sinatra integration.

WLang 2.0 also has a few remaining issues.

  • It does not support rubinius so far, due to an incompatibility with the Citrus parser generator.
  • It has some issues with spacing; not a big issue for HTML rendering but might prevent certain generation tasks.

Tunable templating engine

WLang is a templating engine, written in ruby. In that, it is similar to ERB, Mustache and the like:

WLang::Html.render 'Hello to ${who}!', who: 'you & the world'
# => "Hello to you & the world!"

To output HTML pages, WLang does not provides you with killer features or extraordinary shortcus. It supports escaping, as shown above, but many other templating engines do. For such HTML tasks, WLang does a pretty good job but many other engines perform faster and have nicer features. See the examples folder that documents WLang::Html.

WLang is designed to help you for other uses cases, user-defined ones in particular, such as generating code or whatever text generation task for which other engines quickly become inappropriate. WLang helps there because it allows you to create your own dialect, that is, you can define your own tags and their behavior. For instance,

class Highlighter < WLang::Dialect

  def highlight(buf, fn)
    var_name  = render(fn)
    var_value = evaluate(var_name)
    buf << var_value.to_s.upcase

  tag '$', :highlight
Highlighter.render('Hello ${who}!', who: 'you & the world')
# => "Hello YOU & THE WORLD !"

WLang already provides a few useful dialects, such as WLang::Html (inspired by Mustache but a bit more powerful in my opinion). If they don't match your needs, it is up to you to define you own dialect for making your generation task easy. Have a look at the implementation of WLang's ones, it's pretty simple to get started!

Tilt integration

WLang has built-in support for Tilt facade to templating engines. In order to use that API:

require 'tilt'         # needed in your bundle, not a wlang dependency
require 'wlang'        # loads Tilt support provided Tilt has already been required

template = Tilt.new("path/to/a/template.wlang")   # suppose 'Hello ${who}!'
template.render(:who => "world")
# => Hello world!

template = Tilt.new("path/to/a/template.wlang", :dialect => Highlighter)
template.render(:who => "world")
# => Hello WORLD!

Please note that you should require tilt first, then wlang. Otherwise, you'll have to require wlang/tilt explicitely.

Sinatra integration

WLang comes bundled with built-in support for Sinatra >= 1.4 (release still in progress). As usual in Sinatra, you can simply invoke wlang as follows:

get '/' do
  wlang :index, :locals => { ... }

As wlang encourages logic-less templates, you should always use locals. However, there is specific support for layouts and partials, as the following example demonstrates:

get '/' do
  wlang :index, :locals => {:who => "world"}



  Hello from a partial: >{partial}

  yeah, a partial saying hello to '${who}'!

Returned body will be (ignoring carriage returns):

<html>Hello from a partial: yeah, a partial saying hello to 'world'!</html>