Changes

Jump to navigation Jump to search
954 bytes added ,  08:21, 28 March 2013
no edit summary
== The ConTeXt style file ==
Next, we write the environment file <tt>prices-style.tex</tt> which we will use to process our list. As an exercise, we will use Lua for all xml elements (though this doesn't make sense in most cases). If you have already read the [http://pragma-ade.com/show-man-43.htm manual], most of this will be familiar. The first line connects our environment with the Lua file where all the Lua code will go. The last lines set up a table, since this is how we want to display the information:
<texcode>
\setupTABLE [column] [2,3,4] [style=italic,width=0.2\textwidth]
</texcode>
 
== The Lua file ==
And finally, the Lua file <tt>l-prices.lua</tt>, which will hold all the lua functions we use to process the xml:
<code><pre>
function xml.functions.list(t)
context.bTABLE()
context.bTR()
context.bTD()
context("Model")
context.eTD()
context.bTD()
context("Euros")
context.eTD()
context.bTD()
context("Dollars")
context.eTD()
context.bTD()
context("Yen")
context.eTD()
context.eTR()
lxml.flush(t)
context.eTABLE()
end
 
function xml.functions.item(t)
context.bTR()
lxml.flush(t)
context.eTR()
end
 
function xml.functions.model(t)
context.bTD()
lxml.flush(t)
context.eTD()
end
 
function xml.functions.price(t)
local price = tonumber(xml.text(t, "./"))
local dollar_price = price * 1.28
local yen_price = price * 120.4
context.bTD()
context(price)
context.eTD()
context.bTD()
context(dollar_price)
context.eTD()
context.bTD()
context(yen_price)
context.eTD()
end
</pre></code>
gardener
111

edits

Navigation menu