What is wlang ?

WLang is a general-purpose code generation/templating engine. It's main aim is to help you generating web pages, sql queries, ruby code (that is, generating code in general) without having to worry too much about html entities encoding, sql back quoting, string escaping and the like. WLang proposes a generic engine that you can extend to fit your needs. It also proposes standard instantiations of this engine for common tasks such as creating SQL queries, instantiating web pages, and so on.

Basic concepts and usage is illustrated below. Also have a look at the detailed specification.

A collection of typical encoders

The first basic usage of WLang is to provide a collection of text encoders:

WLang::encode('&',      'xhtml/entities-encoding')      # &
WLang::encode("O'Neil", 'sql/single-quoting')           # O\'Neil   
WLang::encode("O'Neil", 'sql/sybase/single-quoting')    # O''Neil   
...
WLang::encode("hello world",  'plain-text/camel')        # HelloWorld  
WLang::encode("hello world",  'plain-text/lower-camel')  # helloWorld  
...
WLang::encode("helloWorld",   'ruby/method-case')        # hello_world

A powerful alternative to ruby string interpolation

The second usage is to have shortcuts for using these encoders in typical situations:

# Hello world!
"Hello ${who}!".wlang(:who => 'world')                          

# Hello cruel & world!
"Hello ${who}!".wlang({:who => 'cruel & world'}, 'wlang/xhtml') 

# Hello blambeau, llambeau
"Hello *{authors as a}{${a}}{, }".wlang(:authors => ['blambeau', 'llambeau'])

# INSERT INTO people VALUES ('O\'Neil')
INSERT INTO people VALUES ('{who}')".wlang(:who => "O'Neil")

A powerful templating engine

But the main usage of wlang is as follows (for bold words, see terminology later): you have a template file (written in a given wlang dialect), you have some instantiation context (data provided through a Ruby Hash or a yaml file for example) and you would like to instantiate the template with that data.

Example: a template.whtml as follows

<html>
  <head>
    <title>${title}</title>
  </head>
  <body>
    <h1>Hello ${who} !</h1>
  </body>
</html>

Instantiation data is a hash containing values for title and who. Instantiating the template is straightforward:

require 'wlang'
context = {"title" => "Hello world in WLang", "who" => "Alice"}
STDOUT << WLang.file_instantiate("template.whtml", context)

Behind the scene

Additional examples (availability of the tags may depend on the dialect)

Roadmap

Terminology