lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great François Perrad once stated:
> >
> I see there are not many fan of framework.
> But what about template engine (cosmo, lustache, lust, ...) ?

  I wrote my own [1].  Just two functions, one works on strings, and the
other one that will read a file and call the first one.  A sample call:

	TEMPLATE = "Hello %{name}%, you are %{age}% years old."
	CALLBACKS =
	{
	  name = "Sean",
	  age = function(data)
	    if data then
	      return data.age
	    else
	      return math.random(99)
	    end
	  end
	}

	output = template(TEMPLATE,CALLBACKS, { age = 22 })

  -spc (Didn't need anything complicated)

[1]	https://github.com/spc476/lua-conmanorg/blob/1ce4454b0a458fbe8668be7aafb0bd8016098c9a/lua/string.lua#L58