summaryrefslogtreecommitdiff
path: root/plugins/toolkit.lua
blob: e5f162a23e9643301564dc404a014f360d0e9bf0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
local toolkit = {}

toolkit.file_iterator = function(directory)
   local _, files = argent.scanDirectory(directory)
   local i = 0
   local n = table.getn(files)
   return function()
      i = i+1
      if i<=n then return files[i] end
   end
end


toolkit.basename = function(filename)
   return string.gsub(filename, '%.lua$', '')
end


local function extract_page(file)
   if not string.match(file, '%.lua$') then return nil end

   local success, result = pcall(loadfile(file), 0, 1)
   if not success then return nil end
   return result
end

toolkit.pages = function(directory)
   page_array = {}
   local path = argent.config.site_directory..directory
   for file in toolkit.file_iterator(path) do
      local page = extract_page(path..file)
      if page then
	 page.href = '/'..directory..toolkit.basename(file)..'.html'
	 table.insert(page_array, page)
      end
   end

   return page_array
end


return toolkit