- Timestamp:
- 11/07/07 04:36:41 (6 years ago)
- Location:
- lang/lua/bluasxom
- Files:
-
- 2 modified
-
bluasxom.lua (modified) (4 diffs)
-
template.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/lua/bluasxom/bluasxom.lua
r1200 r1201 2 2 -- vim:ft=lua: 3 3 -- POSIX かつ ruby がインストールされている前提 4 -- Lua 5.1 4 5 5 6 package.path = "./lib/?.lua" … … 27 28 } 28 29 29 function get_entries(dir, ext)30 local ret = List.new()31 local tf = os.tmpname()32 os.execute('ruby -rpathname -e "Pathname.glob(%|'..dir..'/**/*'..ext..'|){|f|puts %|#{f.mtime.to_i} #{f}|}" > ' .. tf)33 for line in io.lines(tf) do34 local time, filename = string.match(line, "(%d+) (.+)")35 local e = Entry.new(filename, tonumber(time, 10))36 e.name = string.gsub(string.gsub(filename, "%.%w+$", ""), "^"..dir, "")37 ret:push(e)38 end39 return ret40 end41 42 43 30 ELua = Class { super = nil, 44 31 initialize = function (self, template) … … 56 43 ret = ret .. pre 57 44 if string.match(code, "^==") then 58 ret = ret .. "]===] .. " .. string.sub(code, 3) .. ".. [===["45 ret = ret .. "]===] .. tostring(" .. string.sub(code, 3) .. ") .. [===[" 59 46 elseif string.match(code, "^=") then 60 ret = ret .. "]===] .. " .. string.sub(code, 2) .. ".. [===["47 ret = ret .. "]===] .. htmlescape(" .. string.sub(code, 2) .. ") .. [===[" 61 48 else 62 49 ret = ret .. "]===]\n" .. code .. "\nret = ret .. [===[" … … 68 55 end, 69 56 57 htmlescape = function (str) 58 local m = {["<"] = "<", [">"] = ">", ["&"] = "&"} 59 return string.gsub(tostring(str), "[<>&]", function (s) 60 return m[s] 61 end) 62 end, 63 70 64 result = function (self, context) 71 65 local f = loadstring(self.src, "ELua") 72 -- グローバル環境を context のコピー66 -- グローバル環境を context にコピー 73 67 -- うわがきされる。 74 68 for k, v in pairs(_G) do 75 69 context[k] = v 76 70 end 71 context.htmlescape = self.htmlescape 77 72 setfenv(f, context) 78 73 return f() 79 74 end, 75 76 run = function (filename, context) 77 local f = io.open(filename) 78 local tmpl = f:read("*a") 79 f:close() 80 print(ELua.new(tmpl):result(context)) 81 end, 80 82 } 81 83 82 local f = io.open("template.html")83 tmpl = f:read("*a")84 f:close()85 84 86 local entries = get_entries("data", ".txt") 85 function get_entries(dir, ext) 86 local ret = List.new() 87 local tf = os.tmpname() 88 -- ruby++ 89 os.execute('ruby -rpathname -e "Pathname.glob(%|'..dir..'/**/*'..ext..'|){|f|puts %|#{f.mtime.to_i} #{f}|}" > ' .. tf) 90 for line in io.lines(tf) do 91 local time, filename = string.match(line, "(%d+) (.+)") 92 local e = Entry.new(filename, tonumber(time, 10)) 93 e.name = string.gsub(string.gsub(filename, "%.%w+$", ""), "^"..dir, "") 94 ret:push(e) 95 end 96 return ret 97 end 87 98 88 entries = entries:sort(function (a, b) 89 return a.time > b.time90 end) 91 92 local result = ELua.new(tmpl):result({ 93 title = "test",94 home = "test",95 entries = entries,99 ELua.run("template.html", { 100 title = "test", 101 home = os.getenv("SCRIPT_NAME"), 102 server = "http://" .. tostring(os.getenv("SERVER_NAME")), 103 entries = 104 get_entries("data", ".txt"):sort(function (a, b) 105 return a.time > b.time 106 end), 96 107 debugObj = "aaa", 97 version = _VERSION,98 108 }) 99 109 100 print(result) -
lang/lua/bluasxom/template.html
r1200 r1201 99 99 100 100 <div id="footer"> 101 <p>Powered by Lua (+ruby) <%= version%></p>101 <p>Powered by Lua (+ruby) <%= _VERSION %></p> 102 102 </div> 103 103 </div>
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)