Changeset 1452
- Timestamp:
- 08/04/08 21:35:20
- Files:
-
- HTTP/HTTP.lua (modified) (1 diff)
- HTTP/Nanoki.lua (modified) (5 diffs)
- HTTP/WikiContentFileService.lua (modified) (1 diff)
- HTTP/WikiContentService.lua (modified) (4 diffs)
- HTTP/WikiIndexService.lua (modified) (2 diffs)
- HTTP/WikiService.lua (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
HTTP/HTTP.lua
r1416 r1452 533 533 534 534 aResponse( aWriter ) 535 535 536 536 return self 537 537 elseif not aResult then HTTP/Nanoki.lua
r1451 r1452 13 13 14 14 -- import dependencies 15 local debug = require( 'debug' ) 15 16 local io = require( 'io' ) 16 17 local os = require( 'os' ) … … 21 22 local getfenv = getfenv 22 23 local getmetatable = getmetatable 24 local package = package 23 25 local require = require 24 26 local select = select … … 55 57 end 56 58 59 local function Environment( aFunction, aKey, aValue ) 60 local anEnvironment = getfenv( assert( aFunction, 'invalid function' ) ) 61 62 if not anEnvironment or anEnvironment == _G then 63 anEnvironment = {} 64 setfenv( aFunction, anEnvironment ) 65 end 66 67 if aKey then 68 anEnvironment[ aKey ] = aValue 69 end 70 71 return anEnvironment 72 end 73 57 74 local function Log( ... ) 58 75 local aWriter = io.stderr … … 67 84 end 68 85 69 local function Environment( aFunction, aKey, aValue ) 70 local anEnvironment = getfenv( assert( aFunction, 'invalid function' ) ) 71 72 if not anEnvironment or anEnvironment == _G then 73 anEnvironment = {} 74 setfenv( aFunction, anEnvironment ) 75 end 76 77 if aKey then 78 anEnvironment[ aKey ] = aValue 79 end 80 81 return anEnvironment 86 local function Path( aName ) 87 local aSource = debug.getinfo( 1, 'S' ).source 88 local aSeparator = package.path:match( '(%p)%?%.' ) or '/' 89 local anIndex = aSource:len() - ( aSource:reverse():find( aSeparator, 1, true ) or aSource:len() ) 90 local aPath = ( '%s%s%s' ):format( aSource:sub( 2, anIndex + 1 ), aName, aSeparator ) 91 92 return aPath 82 93 end 83 94 … … 167 178 HTTP[ '/' ] = WikiMainService() 168 179 HTTP[ '/a' ] = WikiAbout() 169 HTTP[ '/etc/(.+)' ] = HTTPFile( 'etc/')180 HTTP[ '/etc/(.+)' ] = HTTPFile( Path( 'etc' ) ) 170 181 171 182 aService = HTTPService( '/date', WikiDateService ) HTTP/WikiContentFileService.lua
r1439 r1452 130 130 function self:get() 131 131 local aContent = self.content 132 local aName = self.name :lower()132 local aName = self.name 133 133 134 134 if aContent and aContent.exists and aName then 135 local aName = aName:lower() 136 135 137 if ValidContent( aContent, aName ) then 136 138 HTTP.response.header[ 'content-type' ] = 'text/plain; charset=utf-8' HTTP/WikiContentService.lua
r1443 r1452 36 36 local Tag = WikiService.Tag 37 37 38 local debug = require( 'debug' ) 38 39 local os = require( 'os' ) 39 40 local table = require( 'table' ) 40 41 41 42 local getmetatable = getmetatable 43 local package = package 42 44 local require = require 43 45 local setmetatable = setmetatable … … 60 62 61 63 local function Message( self ) 62 local aModification = self.content.modification 64 local aModification = self.content.modification or 0 63 65 local aTime = os.time() 64 66 local anInterval = aTime - aModification … … 192 194 local WikiRecent = require( 'WikiRecent' ) 193 195 local WikiSearch = require( 'WikiSearch' ) 194 local aDirectory = File( 'Nanoki' ) 196 local aSource = debug.getinfo( 1, 'S' ).source 197 local aSeparator = package.path:match( '(%p)%?%.' ) or '/' 198 local anIndex = aSource:len() - ( aSource:reverse():find( aSeparator, 1, true ) or aSource:len() ) 199 local aPath = ( '%sNanoki' ):format( aSource:sub( 2, anIndex + 1 ) ) 200 local aDirectory = File( aPath ) 195 201 local aTemplate = Template[ 'Nanoki.txt' ] 196 202 … … 266 272 267 273 function self:getHtml() 268 local aLayoutTemplate = Template[ 'WikiLayout.txt' ] 269 local aTemplate = Template[ 'WikiContentService.txt' ] 270 local aLinkTemplate = aTemplate[ 'link' ] 271 local aLinkIterator, aLinkCount = ContentIterator( self.content.link ) 272 local aDate = os.date( '!*t', self.content.creation ) 273 local aDateLink = DateLink( aDate.year, aDate.month, aDate.day ) 274 275 Referer( self ) 276 277 aTemplate[ 'editorLink' ] = EditorLink( self ) 278 aTemplate[ 'version' ] = Encode(self.content.version ) 279 aTemplate[ 'title' ] = Encode( self.content.data.title ) 280 aTemplate[ 'dateLink' ] = Encode( aDateLink ) 281 aTemplate[ 'creation' ] = Encode( FormatDate( self.content.creation ) ) 282 aTemplate[ 'modification' ] = Encode( FormatDateTime( self.content.modification ) ) 283 aTemplate[ 'tag' ] = Tag( self.content.modification ) 284 aTemplate[ 'by' ] = Encode( URL( self.content.by ).host or 'localhost' ) 285 aTemplate[ 'message' ] = Message( self ) 286 aTemplate[ 'content' ] = HTML( self.content ) 287 288 for aContent, aURL in aLinkIterator do 289 local aNameTemplate = aLinkTemplate[ 'names' ] 290 291 aNameTemplate[ 'href' ] = Encode( aURL.path ) 292 aNameTemplate[ 'name' ] = Encode( aContent.title ) 293 294 aLinkTemplate[ 'names' ] = aNameTemplate 295 end 296 297 if aLinkCount == 0 then 298 aLinkTemplate = nil 299 end 300 301 aTemplate[ 'link' ] = aLinkTemplate 302 303 aLayoutTemplate[ 'baseLink' ] = Encode( BaseLink() ) 304 aLayoutTemplate[ 'indexLink' ] = Encode( IndexLink( self.content.prefix ) ) 305 aLayoutTemplate[ 'dateLink' ] = Encode( aDateLink ) 306 aLayoutTemplate[ 'feedLink' ] = FeedLink( self, 1 ) 307 aLayoutTemplate[ 'path' ] = Path( self ) 308 aLayoutTemplate[ 'query' ] = nil 309 aLayoutTemplate[ 'robot' ] = Robot( self.content.modification ) 310 aLayoutTemplate[ 'title' ] = Encode( self.content.title ) 311 aLayoutTemplate[ 'content' ] = aTemplate 274 if self.content and self.content.exists then 275 local aLayoutTemplate = Template[ 'WikiLayout.txt' ] 276 local aTemplate = Template[ 'WikiContentService.txt' ] 277 local aLinkTemplate = aTemplate[ 'link' ] 278 local aLinkIterator, aLinkCount = ContentIterator( self.content.link ) 279 local aDate = os.date( '!*t', self.content.creation ) 280 local aDateLink = DateLink( aDate.year, aDate.month, aDate.day ) 281 282 Referer( self ) 283 284 aTemplate[ 'editorLink' ] = EditorLink( self ) 285 aTemplate[ 'version' ] = Encode(self.content.version ) 286 aTemplate[ 'title' ] = Encode( self.content.data.title ) 287 aTemplate[ 'dateLink' ] = Encode( aDateLink ) 288 aTemplate[ 'creation' ] = Encode( FormatDate( self.content.creation ) ) 289 aTemplate[ 'modification' ] = Encode( FormatDateTime( self.content.modification ) ) 290 aTemplate[ 'tag' ] = Tag( self.content.modification ) 291 aTemplate[ 'by' ] = Encode( URL( self.content.by ).host or 'localhost' ) 292 aTemplate[ 'message' ] = Message( self ) 293 aTemplate[ 'content' ] = HTML( self.content ) 294 295 for aContent, aURL in aLinkIterator do 296 local aNameTemplate = aLinkTemplate[ 'names' ] 297 298 aNameTemplate[ 'href' ] = Encode( aURL.path ) 299 aNameTemplate[ 'name' ] = Encode( aContent.title ) 312 300 313 return tostring( aLayoutTemplate ) 301 aLinkTemplate[ 'names' ] = aNameTemplate 302 end 303 304 if aLinkCount == 0 then 305 aLinkTemplate = nil 306 end 307 308 aTemplate[ 'link' ] = aLinkTemplate 309 310 aLayoutTemplate[ 'baseLink' ] = Encode( BaseLink() ) 311 aLayoutTemplate[ 'indexLink' ] = Encode( IndexLink( self.content.prefix ) ) 312 aLayoutTemplate[ 'dateLink' ] = Encode( aDateLink ) 313 aLayoutTemplate[ 'feedLink' ] = FeedLink( self, 1 ) 314 aLayoutTemplate[ 'path' ] = Path( self ) 315 aLayoutTemplate[ 'query' ] = nil 316 aLayoutTemplate[ 'robot' ] = Robot( self.content.modification ) 317 aLayoutTemplate[ 'title' ] = Encode( self.content.title ) 318 aLayoutTemplate[ 'content' ] = aTemplate 319 320 return tostring( aLayoutTemplate ) 321 end 322 323 return nil, self.path( 'editor' ) 314 324 end 315 325 316 326 function self:getLua() 317 local Data = require( 'Data' ) 318 319 HTTP.response.header[ 'content-type' ] = 'text/plain; charset=utf-8' 320 321 return Data( self.content.data ) 327 if self.content and self.content.exists then 328 local Data = require( 'Data' ) 329 330 HTTP.response.header[ 'content-type' ] = 'text/plain; charset=utf-8' 331 332 return Data( self.content.data ) 333 end 334 335 return nil, self.path( 'editor' ) 322 336 end 323 337 324 338 function self:getTxt() 325 HTTP.response.header[ 'content-type' ] = 'text/plain; charset=utf-8' 326 327 return self.content.text 339 if self.content and self.content.exists then 340 HTTP.response.header[ 'content-type' ] = 'text/plain; charset=utf-8' 341 342 return self.content.text 343 end 344 345 return nil, self.path( 'editor' ) 328 346 end 329 347 330 348 function self:getXml() 331 local WikiFeed = require( 'WikiFeed' ) 332 local anIterator = NameIterator( { self.content.name } ) 333 local aGenerator = HTML 334 local aContext = { title = self.content.data.title, link = HTTP.request.url, creation = self.content.creation } 335 336 HTTP.response.header[ 'content-type' ] = 'application/atom+xml; charset=utf-8' 337 338 return tostring( WikiFeed( anIterator, aGenerator, aContext ) ) 349 if self.content and self.content.exists then 350 local WikiFeed = require( 'WikiFeed' ) 351 local anIterator = NameIterator( { self.content.name } ) 352 local aGenerator = HTML 353 local aContext = { title = self.content.data.title, link = HTTP.request.url, creation = self.content.creation } 354 355 HTTP.response.header[ 'content-type' ] = 'application/atom+xml; charset=utf-8' 356 357 return tostring( WikiFeed( anIterator, aGenerator, aContext ) ) 358 end 359 360 return nil, self.path( 'editor' ) 339 361 end 340 362 HTTP/WikiIndexService.lua
r1419 r1452 235 235 236 236 if aFirst and aFirst:len() > 0 then 237 local aFirst = aFirst:match( '^(%w)' ) 237 local aFirst = aFirst:match( '^(%w)' ) or '' 238 238 239 239 aService.first = aFirst:lower() … … 242 242 243 243 if aSecond and aSecond:len() > 0 then 244 local aSecond = aSecond:match( '^(%w)' ) 244 local aSecond = aSecond:match( '^(%w)' ) or '' 245 245 246 246 aService.second = aSecond:lower() HTTP/WikiService.lua
r1419 r1452 187 187 188 188 function Yesterday( aModification ) 189 local aModification = aModification or 0 189 190 local _, aStartTime, anEndTime = Today( aModification ) 190 191 local aStartTime = aStartTime - 86400 … … 196 197 197 198 function ThisWeek( aModification ) 199 local aModification = aModification or 0 198 200 local _, aStartTime, anEndTime = Today( aModification ) 199 201 local aStartTime = aStartTime - ( 7 * 86400 )