local Luan = require "luan:Luan.luan" local error = Luan.error local pairs = Luan.pairs or error() local ipairs = Luan.ipairs or error() local type = Luan.type or error() local String = require "luan:String.luan" local format = String.format or error() local Number = require "luan:Number.luan" local float = Number.float or error() local Table = require "luan:Table.luan" local concat = Table.concat or error() local sort = Table.sort or error() local copy = Table.copy or error() local Time = require "luan:Time.luan" local format_time = Time.format or error() local Io = require "luan:Io.luan" local Http = require "luan:http/Http.luan" local get_data = require "site:/private/lib/get_data.luan" local Pricing = require "site:/private/lib/Pricing.luan" local is_production = Http.domain == "data.tleggings.com" local data = get_data(is_production) local products = data.products or error() local base_url = is_production and "https://www.tleggings.com" or "http://test.tleggings.com" local list = {} for name, product in pairs(products) do product = copy(product) product.name = name list[#list+1] = product end sort(list,function(p1,p2) if p1.added == nil then return p2.added ~= nil else return p2.added ~= nil and p1.added < p2.added end end) return function() local discontinued = Http.request.parameters.discontinued and true Io.stdout = Http.response.text_writer() %> <% local i = 0 for _, product in ipairs(list) do if product.discontinued ~= discontinued then continue end i = i + 1 local name = product.name local code = product.factory_code if type(code) == "table" then code = concat(code,"/") end %> <% end %>
added dir title factory code weight cost old price current price proposed price
<%=i%> <%= product.added and format_time(product.added,"yyyy-MM-dd") %> <%=name%> <%=product.title%> <%= product.factory %> <%= code %> <%= product.factory_weight %> <%= format("$%.2f",Pricing.cost(name)/100) %> <%= format("$%.2f",Pricing.old_price(name)) %> <%= format("$%.2f",float(product.unit_price)) %> <%= format("$%.2f",Pricing.proposed(name)) %>
<% end