Changeset 1182
- Timestamp:
- 01/31/08 17:28:52
- Files:
-
- HTTP/HTTPExtra.lua (modified) (6 diffs)
- HTTP/URL.lua (modified) (5 diffs)
- HTTP/WikiContentService.lua (modified) (10 diffs)
- HTTP/WikiContentService.txt (modified) (1 diff)
- HTTP/WikiDateService.lua (modified) (6 diffs)
- HTTP/WikiEditorService.lua (modified) (7 diffs)
- HTTP/WikiHistoryService.lua (modified) (6 diffs)
- HTTP/WikiIndexService.lua (modified) (5 diffs)
- HTTP/WikiLayout.txt (modified) (1 diff)
- HTTP/WikiPreview.lua (moved) (moved from HTTP/WikiPreviewService.lua) (7 diffs)
- HTTP/WikiPreview.txt (moved) (moved from HTTP/WikiPreviewService.txt)
- HTTP/WikiRecentService.lua (modified) (5 diffs)
- HTTP/WikiSearchService.lua (modified) (5 diffs)
- HTTP/WikiService.lua (modified) (3 diffs)
- HTTP/WikiVersionService.lua (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
HTTP/HTTPExtra.lua
r1180 r1182 10 10 11 11 -- import dependencies 12 local HTTP = require( 'HTTP' ) 13 12 14 local io = require( 'io' ) 13 15 local os = require( 'os' ) 14 16 local table = require( 'table' ) 15 local HTTP = require( 'HTTP' )16 17 17 18 local getmetatable = getmetatable … … 28 29 local type = type 29 30 local unpack = unpack 31 local print = print 30 32 31 33 -------------------------------------------------------------------------------- … … 514 516 aMethod = 'get' 515 517 end 516 518 517 519 aHandlerAction = aMethod:lower() .. Capitalize( aHandlerAction ) 518 520 519 521 if type( anObject ) == 'table' and type( anObject[ aHandlerAction ] ) == 'function' then 520 522 local someArguments = Argument( anObject, anArgument ) … … 549 551 550 552 local function Iterator( aURL, aBase ) 553 local URL = require( 'URL' ) 551 554 local URLPath = require( 'URLPath' ) 552 555 local aPath = URLPath( tostring( aURL.path ):sub( tostring( aBase.path ):len() + 1 ) ) 556 local aServicePath = URLPath( aBase.path ) 553 557 local anAction = Action() 554 local aCount = #aPath 555 local anIndex = 0558 local aCount = #aPath + 1 559 local anIndex = 1 556 560 557 561 if anAction then 558 aPath[ aCount+ 1 ] = anAction559 aCount = aCount + 1562 aPath[ #aPath + 1 ] = anAction 563 aCount = #aPath 560 564 else 561 aPath[ aCount+ 1 ] = ''562 aCount = aCount + 1563 end 564 565 aPath[ #aPath + 1 ] = '' 566 aCount = #aPath 567 end 568 565 569 return function() 566 anIndex = anIndex + 1567 568 570 if anIndex <= aCount then 569 571 local isLast = anIndex == aCount 572 local aComponent = aPath[ anIndex ] 570 573 571 return aPath[ anIndex ], isLast 574 if anIndex > 1 then 575 aServicePath = aServicePath( aPath[ anIndex - 1 ] ) 576 end 577 578 anIndex = anIndex + 1 579 580 return URLPath( aServicePath ), aComponent, isLast 572 581 end 573 582 end … … 576 585 local function Dispatch( aService, aURL, anObject, aMethod ) 577 586 local aBase = aService[ anObject ] 587 local aLocation = nil 578 588 579 589 if not aBase then … … 584 594 return nil, aBase 585 595 end 586 587 for a nAction, isLast in Iterator( aURL, aBase ) do596 597 for aPath, anAction, isLast in Iterator( aURL, aBase ) do 588 598 local aHandler, someArguments = Handler( anObject, aMethod, anAction, isLast ) 589 local aLocation = nil 590 591 if isLast then 592 return aHandler( unpack( someArguments ) ) 593 else 594 anObject, aLocation = aHandler( unpack( someArguments ) ) 599 600 print( 'Dispatch', Type( anObject ), aPath, isLast ) 601 if type( anObject ) == 'table' then 602 anObject.path = aPath 603 end 604 605 anObject, aLocation = aHandler( unpack( someArguments ) ) 606 607 print( 'Dispatch', aLocation ) 608 609 if aLocation then 610 return anObject, aLocation 611 end 612 end 595 613 596 if aLocation then 597 return anObject, aLocation 598 end 599 end 600 end 614 return anObject, aLocation 601 615 end 602 616 HTTP/URL.lua
r1166 r1182 67 67 aPath.absolute = aValue:sub( 1, 1 ) == '/' 68 68 aPath.directory = aValue:sub( -1, -1 ) == '/' 69 69 70 70 return aPath 71 71 end … … 104 104 105 105 local function NewPath( aValue ) 106 local aPath = nil 107 108 if type( aValue ) == 'table' then 109 aPath = ReadPath( WritePath( aValue ) ) 110 else 111 aPath = ReadPath( tostring( aValue or '' ) ) 112 end 106 local aPath = ReadPath( tostring( aValue or '' ) ) 113 107 114 108 setmetatable( aPath, self ) … … 167 161 end 168 162 163 function self:__call( aValue ) 164 local aPath = NewPath( self ) 165 166 if aValue then 167 aPath[ #aPath + 1 ] = tostring( aValue ) 168 else 169 aPath[ #aPath ] = nil 170 end 171 172 return aPath 173 end 174 169 175 function self:__add( aValue ) 170 return AddPath( self , NewPath( aValue ) )176 return AddPath( self(), NewPath( aValue ) ) 171 177 end 172 178 … … 228 234 229 235 local function NewParameter( aValue ) 230 local aParameter = nil 231 232 if type( aValue ) == 'table' then 233 aParameter = ReadParameter( WriteParameter( aValue ) ) 234 else 235 aParameter = ReadParameter( tostring( aValue or '' ) ) 236 end 236 local aParameter = ReadParameter( tostring( aValue or '' ) ) 237 237 238 238 setmetatable( aParameter, self ) … … 388 388 389 389 local function NewURL( aValue ) 390 local aURL = nil 391 392 if type( aValue ) == 'table' then 393 aURL = ReadURL( WriteURL( aValue ) ) 394 else 395 aURL = ReadURL( tostring( aValue or '' ) ) 396 end 390 local aURL = ReadURL( tostring( aValue or '' ) ) 397 391 398 392 setmetatable( aURL, self ) HTTP/WikiContentService.lua
r1173 r1182 11 11 -- import dependencies 12 12 local HTTP = require( 'HTTP' ) 13 local HTTPExtra = require( 'HTTPExtra' )14 local HTTPService = require( 'HTTPService' )15 13 local Template = require( 'Template' ) 16 14 local URL = require( 'URL' ) … … 19 17 local WikiService = require( 'WikiService' ) 20 18 19 local BaseLink = WikiService.BaseLink 20 local DateLink = WikiService.DateLink 21 local FeedLink = WikiService.FeedLink 22 local IndexLink = WikiService.IndexLink 23 21 24 local ContentIterator = WikiService.ContentIterator 22 25 local NameIterator = WikiService.NameIterator 26 23 27 local Encode = WikiService.Encode 24 28 local GetType = WikiService.GetType 25 29 local HTML = WikiService.HTML 30 local Path = WikiService.Path 26 31 27 32 local os = require( 'os' ) … … 44 49 local meta = getmetatable( self ) 45 50 46 self.toURL = function( aService, anObject ) 47 if anObject.content then 48 local aPath = URLPath() 49 50 aPath[ #aPath + 1 ] = anObject.content.name 51 52 return URL( aService.prefix .. aPath ) 53 end 54 end 55 56 self.toObject = function( aService, aURL ) 57 local aPath = aURL.path 58 local aName = aPath[ 1 ] or 'main' 59 local aContent = WikiContent( aName ) 60 61 if aContent then 62 local WikiContentService = require( 'WikiContentService' ) 63 local aService = WikiContentService( aContent ) 64 65 return aService 66 end 67 end 68 69 function meta:__call( aContent ) 70 local aService = { content = aContent } 71 72 setmetatable( aService, self ) 73 self.__index = self 74 75 return aService 76 end 77 78 local function Path( self ) 79 local WikiPath = require( 'WikiPath' ) 80 local WikiContentService = require( 'WikiContentService' ) 81 local aPath = WikiPath( { href = HTTPService[ WikiContentService( self.content ) ].path, title = self.content.data.title } ) 82 83 return aPath 84 end 51 -------------------------------------------------------------------------------- 52 -- Utilites methods 53 -------------------------------------------------------------------------------- 85 54 86 55 local function Message( self ) … … 98 67 end 99 68 100 local function Link( self )69 local function Referer( self ) 101 70 if self.content.name ~= 'main' and HTTP.request.header[ 'referer' ] then 102 71 local URL = require( 'URL' ) … … 127 96 end 128 97 98 -------------------------------------------------------------------------------- 99 -- Service methods 100 -------------------------------------------------------------------------------- 101 102 self.toURL = function( aService, anObject ) 103 if anObject.content then 104 local aPath = URLPath() 105 106 aPath[ #aPath + 1 ] = anObject.content.name 107 108 return URL( aService.prefix .. aPath ) 109 end 110 end 111 112 self.toObject = function( aService, aURL ) 113 local aPath = aURL.path 114 local aName = aPath[ 1 ] or 'main' 115 local aContent = WikiContent( aName ) 116 117 if aContent then 118 local WikiContentService = require( 'WikiContentService' ) 119 local aService = WikiContentService( aContent ) 120 121 return aService 122 end 123 end 124 129 125 function self:getHtml() 130 126 if self.content.exists then … … 134 130 local aLinkIterator, aLinkCount = ContentIterator( self.content.link ) 135 131 local aDate = os.date( '!*t', self.content.creation ) 136 local WikiDateService = require( 'WikiDateService' ) 137 local aDateService = WikiDateService( aDate.year, aDate.month, aDate.day ) 138 local aDatePath = HTTPService[ aDateService ].path 139 140 Link( self ) 141 142 aTemplate[ 'editorLink' ] = Encode( HTTPService[ self ] .. '/editor' ) 143 aTemplate[ 'historyLink' ] = Encode( HTTPService[ self ] .. '/editor/history' ) 132 local aDateLink = DateLink( aDate.year, aDate.month, aDate.day ) 133 134 Referer( self ) 135 136 aTemplate[ 'editorLink' ] = Encode( self.path( 'editor' ) ) 137 aTemplate[ 'historyLink' ] = Encode( self.path( 'editor' )( 'history' ) ) 144 138 aTemplate[ 'version' ] = Encode(self.content.version ) 145 139 aTemplate[ 'title' ] = Encode( self.content.data.title ) 146 aTemplate[ ' href' ] = Encode( aDatePath)140 aTemplate[ 'dateLink' ] = Encode( aDateLink ) 147 141 aTemplate[ 'creation' ] = Encode( os.date( '!%A, %d %B %Y', self.content.creation ) ) 148 142 aTemplate[ 'modification' ] = Encode( os.date( '!%A, %d %B %Y at %I:%M %p', self.content.modification ) ) … … 166 160 aTemplate[ 'link' ] = aLinkTemplate 167 161 168 aLayoutTemplate[ 'baseLink' ] = Encode( HTTP.request.url + '/' ) 169 aLayoutTemplate[ 'feedLink' ] = Encode( HTTP.request.url.path .. '.xml' ) 162 aLayoutTemplate[ 'baseLink' ] = Encode( BaseLink() ) 163 aLayoutTemplate[ 'feedLink' ] = Encode( FeedLink( self ) ) 164 aLayoutTemplate[ 'indexLink' ] = Encode( IndexLink( self.content.prefix ) ) 165 aLayoutTemplate[ 'dateLink' ] = Encode( aDateLink ) 170 166 aLayoutTemplate[ 'path' ] = Path( self ) 171 167 aLayoutTemplate[ 'query' ] = nil … … 176 172 return tostring( aLayoutTemplate ) 177 173 else 178 return nil, HTTPService[ self ] .. '/editor'174 return nil, self.path( 'editor' ) 179 175 end 180 176 end … … 229 225 end 230 226 231 return WikiEditorService( aContent )227 return WikiEditorService( aContent, self ) 232 228 end 233 229 … … 242 238 end 243 239 240 -------------------------------------------------------------------------------- 241 -- Metamethods 242 -------------------------------------------------------------------------------- 243 244 function meta:__call( aContent ) 245 local aService = { content = aContent } 246 247 setmetatable( aService, self ) 248 self.__index = self 249 250 return aService 251 end 252 253 function self:__concat( aValue ) 254 return tostring( self ) .. tostring( aValue ) 255 end 256 257 function self:__tostring() 258 return tostring( self.content.data.title ) 259 end HTTP/WikiContentService.txt
r1173 r1182 1 1 <h1><a href='[v:editorLink]' title='Editor' rel='nofollow'>[v:title]</a></h1> 2 <h4><a href='[v: href]' title='Created on [v:creation]. Updated on [v:modification] by [v:by].'>[v:creation]</a></h4>2 <h4><a href='[v:dateLink]' title='Created on [v:creation]. Updated on [v:modification] by [v:by].'>[v:creation]</a></h4> 3 3 [v:message] 4 4 [v:content] HTTP/WikiDateService.lua
r1167 r1182 19 19 local WikiService = require( 'WikiService' ) 20 20 21 local BaseLink = WikiService.BaseLink 22 local DateLink = WikiService.DateLink 23 local FeedLink = WikiService.FeedLink 24 local IndexLink = WikiService.IndexLink 25 21 26 local ContentIterator = WikiService.ContentIterator 22 27 local Description = WikiService.Description … … 24 29 local GetType = WikiService.GetType 25 30 local HTML = WikiService.HTML 31 local Path = WikiService.Path 26 32 27 33 local os = require( 'os' ) … … 42 48 local self = setmetatable( _M, {} ) 43 49 local meta = getmetatable( self ) 50 51 -------------------------------------------------------------------------------- 52 -- Utilities 53 -------------------------------------------------------------------------------- 54 55 local function Title( aYear, aMonth, aDay ) 56 local aTime = os.time( { year = aYear or 1, month = aMonth or 1, day = aDay or 1 } ) 57 local aFormat = '!%a, %d %b %Y' 58 59 if aDay then 60 aFormat = '!%A, %d %B %Y' 61 elseif aMonth then 62 aFormat = '!%B %Y' 63 else 64 aFormat = '!%Y' 65 end 66 67 return os.date( aFormat, aTime ) 68 end 69 70 -------------------------------------------------------------------------------- 71 -- Service methods 72 -------------------------------------------------------------------------------- 44 73 45 74 self.toURL =function( aService, anObject ) … … 74 103 end 75 104 76 function meta:__call( aYear, aMonth, aDay )77 local aTime = os.time( { year = aYear or 1, month = aMonth or 1, day = aDay or 1 } )78 local aDate = os.date( '!*t', aTime )79 local aService = { year = aYear, month = aMonth, day = aDay }80 81 if aYear and aYear ~= aDate.year then82 aService.year = aDate.year83 end84 85 if aMonth and aMonth ~= aDate.month then86 aService.month = aDate.month87 end88 89 if aDay and aDay ~= aDate.day then90 aService.day = aDate.day91 end92 93 setmetatable( aService, self )94 self.__index = self95 96 return aService97 end98 99 local function Title( aYear, aMonth, aDay )100 local aTime = os.time( { year = aYear or 1, month = aMonth or 1, day = aDay or 1 } )101 local aFormat = '!%a, %d %b %Y'102 103 if aDay then104 aFormat = '!%A, %d %B %Y'105 elseif aMonth then106 aFormat = '!%B %Y'107 else108 aFormat = '!%Y'109 end110 111 return os.date( aFormat, aTime )112 end113 114 local function Path( self )115 local WikiDateService = require( 'WikiDateService' )116 local WikiPath = require( 'WikiPath' )117 local aPath = WikiPath()118 local aYear = self.year119 local aMonth = self.month120 local aDay = self.day121 122 if aYear then123 local aHref = HTTPService[ WikiDateService( aYear ) ].path124 local aTitle = Title( aYear )125 126 aPath[ #aPath + 1 ] = { href = aHref, title = aTitle }127 end128 129 if aMonth then130 local aHref = HTTPService[ WikiDateService( aYear, aMonth ) ].path131 local aTitle = Title( aYear, aMonth )132 133 aPath[ #aPath + 1 ] = { href = aHref, title = aTitle }134 end135 136 if aDay then137 local aHref = HTTPService[ WikiDateService( aYear, aMonth, aDay ) ].path138 local aTitle = Title( aYear, aMonth, aDay )139 140 aPath[ #aPath + 1 ] = { href = aHref, title = aTitle }141 end142 143 return aPath144 end145 146 105 function self:getHtml() 147 106 local WikiDateNavigation = require( 'WikiDateNavigation' ) … … 172 131 aTemplate[ 'title' ] = Encode( aTitle ) 173 132 174 aLayoutTemplate[ 'baseLink' ] = Encode( HTTP.request.url + '/' ) 175 aLayoutTemplate[ 'feedLink' ] = Encode( HTTP.request.url.path .. '.xml' ) 133 aLayoutTemplate[ 'baseLink' ] = Encode( BaseLink() ) 134 aLayoutTemplate[ 'feedLink' ] = Encode( FeedLink( self ) ) 135 aLayoutTemplate[ 'indexLink' ] = Encode( IndexLink() ) 136 aLayoutTemplate[ 'dateLink' ] = Encode( DateLink( self.year, self.month, self.day ) ) 176 137 aLayoutTemplate[ 'path' ] = Path( self ) 177 138 aLayoutTemplate[ 'query' ] = nil … … 200 161 end 201 162 163 -------------------------------------------------------------------------------- 164 -- Metamethods 165 -------------------------------------------------------------------------------- 202 166 167 function meta:__call( aYear, aMonth, aDay ) 168 local aTime = os.time( { year = aYear or 1, month = aMonth or 1, day = aDay or 1 } ) 169 local aDate = os.date( '!*t', aTime ) 170 local aService = { year = aYear, month = aMonth, day = aDay } 171 172 if aYear and aYear ~= aDate.year then 173 aService.year = aDate.year 174 end 175 176 if aMonth and aMonth ~= aDate.month then 177 aService.month = aDate.month 178 end 179 180 if aDay and aDay ~= aDate.day then 181 aService.day = aDate.day 182 end 183 184 setmetatable( aService, self ) 185 self.__index = self 186 187 return aService 188 end 189 190 function self:__concat( aValue ) 191 return tostring( self ) .. tostring( aValue ) 192 end 193 194 function self:__tostring() 195 return Title( self.year, self.month, self.day ) 196 end HTTP/WikiEditorService.lua
r1181 r1182 23 23 local WikiService = require( 'WikiService' ) 24 24 25 local BaseLink = WikiService.BaseLink 26 local DateLink = WikiService.DateLink 27 local FeedLink = WikiService.FeedLink 28 local IndexLink = WikiService.IndexLink 29 25 30 local Encode = WikiService.Encode 26 31 local GetType = WikiService.GetType 32 local Path = WikiService.Path 27 33 28 34 local os = require( 'os' ) … … 48 54 local meta = getmetatable( self ) 49 55 50 function meta:__call( aContent ) 51 local anEditor = { content = aContent } 52 53 setmetatable( anEditor, self ) 54 self.__index = self 55 56 return anEditor 57 end 58 59 local function Path( self ) 60 local WikiPath = require( 'WikiPath' ) 61 local aContentPath = URLPath( HTTP.request.url.path ) 62 local aPath = WikiPath() 63 64 table.remove( aContentPath ) 65 aPath[ #aPath + 1 ] = { href = tostring( aContentPath ), title = self.content.data.title } 66 aPath[ #aPath + 1 ] = { title = 'Editor' } 67 68 return aPath 69 end 56 -------------------------------------------------------------------------------- 57 -- Utilities 58 -------------------------------------------------------------------------------- 70 59 71 60 local function Message( self ) … … 165 154 end 166 155 156 -------------------------------------------------------------------------------- 157 -- Service methods 158 -------------------------------------------------------------------------------- 159 167 160 function self:get() 168 161 local aLayoutTemplate = Template[ 'WikiLayout.txt' ] 169 162 local aTemplate = Template[ 'WikiEditorService.txt' ] 170 163 local aContent = self.content 164 local aDate = os.date( '!*t', aContent.creation ) 165 local aDateLink = DateLink( aDate.year, aDate.month, aDate.day ) 171 166 local aContext = Context() 172 167 local aToken = Token() 173 168 174 169 aTemplate[ 'actionPath' ] = Encode( HTTP.request.url.path ) 175 aTemplate[ 'history' ] = Encode( HTTP.request.url.path .. '/history')170 aTemplate[ 'history' ] = Encode( HTTP.request.url.path( 'history' ) ) 176 171 aTemplate[ 'message' ] = Message( self ) 177 172 … … 190 185 aTemplate[ 'version' ] = Encode( Version( aContent, aContext ) ) 191 186 192 aLayoutTemplate[ 'baseLink' ] = Encode( HTTP.request.url + '/' ) 193 aLayoutTemplate[ 'feedLink' ] = Encode( HTTP.request.url.path .. '.xml' ) 187 aLayoutTemplate[ 'baseLink' ] = Encode( BaseLink() ) 188 aLayoutTemplate[ 'feedLink' ] = Encode( FeedLink( self.parent ) ) 189 aLayoutTemplate[ 'indexLink' ] = Encode( IndexLink( aContent.prefix ) ) 190 aLayoutTemplate[ 'dateLink' ] = Encode( aDateLink ) 194 191 aLayoutTemplate[ 'path' ] = Path( self ) 195 192 aLayoutTemplate[ 'query' ] = nil … … 206 203 207 204 function self:postPreview() 208 local WikiPreview Service = require( 'WikiPreviewService' )205 local WikiPreview = require( 'WikiPreview' ) 209 206 local aContext = Context() 210 207 local aPath = Path( self ) … … 213 210 aContext.path = aPath 214 211 aContext.token = Token() 215 216 return tostring( WikiPreview Service( self.content, aContext ) )212 213 return tostring( WikiPreview( self.content, self, aContext ) ) 217 214 end 218 215 … … 261 258 local WikiHistoryService = require( 'WikiHistoryService' ) 262 259 263 return WikiHistoryService( self.content )260 return WikiHistoryService( self.content, self ) 264 261 end 265 262 266 263 return nil, HTTPService[ WikiContentService( self.content ) ] 267 264 end 265 266 -------------------------------------------------------------------------------- 267 -- Metamethods 268 -------------------------------------------------------------------------------- 269 270 function meta:__call( aContent, aParent ) 271 local anEditor = { content = aContent, parent = aParent } 272 273 setmetatable( anEditor, self ) 274 self.__index = self 275 276 return anEditor 277 end 278 279 function self:__concat( aValue ) 280 return tostring( self ) .. tostring( aValue ) 281 end 282 283 function self:__tostring() 284 return 'Editor' 285 end HTTP/WikiHistoryService.lua
r1173 r1182 18 18 local WikiService = require( 'WikiService' ) 19 19 20 local BaseLink = WikiService.BaseLink 21 local DateLink = WikiService.DateLink 22 local FeedLink = WikiService.FeedLink 23 local IndexLink = WikiService.IndexLink 24 20 25 local Description = WikiService.Description 21 26 local Encode = WikiService.Encode 22 27 local GetType = WikiService.GetType 28 local Path = WikiService.Path 23 29 24 30 local os = require( 'os' ) … … 43 49 local meta = getmetatable( self ) 44 50 45 function meta:__call( aContent ) 46 local aHistory = { content = aContent } 47 48 setmetatable( aHistory, self ) 49 self.__index = self 50 51 return aHistory 52 end 53 54 local function Path( self ) 55 local URLPath = require( 'URLPath' ) 56 local WikiPath = require( 'WikiPath' ) 57 local aContentPath = URLPath( HTTP.request.url.path ) 58 local aPath = WikiPath() 59 60 table.remove( aContentPath ) 61 table.remove( aContentPath ) 62 aPath[ #aPath + 1 ] = { href = tostring( aContentPath ), title = self.content.data.title } 63 64 aContentPath = URLPath( HTTP.request.url.path ) 65 table.remove( aContentPath ) 66 aPath[ #aPath + 1 ] = { href = tostring( aContentPath ), title = 'Editor' } 67 aPath[ #aPath + 1 ] = { title = 'History' } 68 69 return aPath 70 end 51 -------------------------------------------------------------------------------- 52 -- Utilities 53 -------------------------------------------------------------------------------- 71 54 72 55 local function EntryComparator( anEntry, anotherEntry ) … … 121 104 end 122 105 106 -------------------------------------------------------------------------------- 107 -- Service methods 108 -------------------------------------------------------------------------------- 109 123 110 function self:get() 124 111 local aLayoutTemplate = Template[ 'WikiLayout.txt' ] … … 126 113 local aDate = os.date( '!*t', self.content.creation ) 127 114 local aDateTitle = os.date( '!%A, %d %B %Y', self.content.creation ) 115 local aDateLink = DateLink( aDate.year, aDate.month, aDate.day ) 128 116 local someEntries = Entries( self.content.name, self.content.versions ) 129 117 local aCount = 0 … … 159 147 aTemplate[ 'description' ] = Description( aCount ) 160 148 161 aLayoutTemplate[ 'baseLink' ] = Encode( HTTP.request.url + '/' ) 162 aLayoutTemplate[ 'feedLink' ] = Encode( HTTP.request.url.path .. '.xml' ) 149 aLayoutTemplate[ 'baseLink' ] = Encode( BaseLink() ) 150 aLayoutTemplate[ 'feedLink' ] = Encode( FeedLink( self ) ) 151 aLayoutTemplate[ 'indexLink' ] = Encode( IndexLink( self.content.prefix ) ) 152 aLayoutTemplate[ 'dateLink' ] = Encode( aDateLink ) 163 153 aLayoutTemplate[ 'path' ] = Path( self ) 164 154 aLayoutTemplate[ 'query' ] = nil … … 180 170 local WikiVersionService = require( 'WikiVersionService' ) 181 171 182 return WikiVersionService( aContent )172 return WikiVersionService( aContent, self ) 183 173 end 184 174 end 185 175 end 176 177 -------------------------------------------------------------------------------- 178 -- Metamethods 179 -------------------------------------------------------------------------------- 180 181 function meta:__call( aContent, aParent ) 182 local aHistory = { content = aContent, parent = aParent } 183 184 setmetatable( aHistory, self ) 185 self.__index = self 186 187 return aHistory 188 end 189 190 function self:__concat( aValue ) 191 return tostring( self ) .. tostring( aValue ) 192 end 193 194 function self:__tostring() 195 return 'History' 196 end HTTP/WikiIndexService.lua
r1167 r1182 19 19 local WikiService = require( 'WikiService' ) 20 20 21 local BaseLink = WikiService.BaseLink 22 local DateLink = WikiService.DateLink 23 local FeedLink = WikiService.FeedLink 24 local IndexLink = WikiService.IndexLink 25 21 26 local ContentIterator = WikiService.ContentIterator 22 27 local Description = WikiService.Description 23 28 local Encode = WikiService.Encode 24 29 local GetType = WikiService.GetType 30 local Path = WikiService.Path 25 31 26 32 local getmetatable = getmetatable … … 38 44 local self = setmetatable( _M, {} ) 39 45 local meta = getmetatable( self ) 46 47 -------------------------------------------------------------------------------- 48 -- Utilities 49 -------------------------------------------------------------------------------- 50 51 -------------------------------------------------------------------------------- 52 -- Service methods 53 -------------------------------------------------------------------------------- 40 54 41 55 self.toURL =function( aService, anObject ) … … 63 77 64 78 return aService 65 end66 67 function meta:__call( aFirst, aSecond )68 local aFirst = ( aFirst or 'a' ):match( '^(%w)' ) or 'a'69 local aSecond = ( aSecond or '' ):match( '^(%w)' )70 local aPrefix = nil71 local aService = {}72 73 if aFirst then74 aService.first = aFirst:lower()75 aPrefix = aService.first76 end77 78 if aSecond then79 aService.second = aSecond:lower()80 aPrefix = aService.first .. aService.second81 end82 83 aService.prefix = aPrefix84 85 setmetatable( aService, self )86 self.__index = self87 88 return aService89 end90 91 local function Path( self )92 local HTTPService = require( 'HTTPService' )93 local WikiIndexService = require( 'WikiIndexService' )94 local WikiPath = require( 'WikiPath' )95 local aPath = WikiPath()96 97 aPath[ #aPath + 1 ] = { href = HTTPService[ WikiIndexService( self.first ) ].path, title = self.first:upper() }98 99 if self.second then100 aPath[ #aPath + 1 ] = { href = HTTPService[ WikiIndexService( self.first, self.second ) ].path, title = self.second:lower() }101 end102 103 return aPath104 79 end 105 80 … … 132 107 aTemplate[ 'title' ] = aTitle 133 108 134 aLayoutTemplate[ 'baseLink' ] = Encode( HTTP.request.url + '/' ) 135 aLayoutTemplate[ 'feedLink' ] = Encode( HTTP.request.url.path .. '.xml' ) 109 aLayoutTemplate[ 'baseLink' ] = Encode( BaseLink() ) 110 aLayoutTemplate[ 'feedLink' ] = Encode( FeedLink( self ) ) 111 aLayoutTemplate[ 'indexLink' ] = Encode( IndexLink( self.prefix ) ) 112 aLayoutTemplate[ 'dateLink' ] = Encode( DateLink() ) 136 113 aLayoutTemplate[ 'path' ] = Path( self ) 137 114 aLayoutTemplate[ 'query' ] = nil … … 159 136 end 160 137 138 -------------------------------------------------------------------------------- 139 -- Metamethods 140 -------------------------------------------------------------------------------- 161 141 142 function meta:__call( aFirst, aSecond ) 143 local aFirst = ( aFirst or 'a' ):match( '^(%w)' ) or 'a' 144 local aSecond = ( aSecond or '' ):match( '^(%w)' ) 145 local aPrefix = nil 146 local aService = {} 147 148 if aFirst then 149 aService.first = aFirst:lower() 150 aPrefix = aService.first 151 end 152 153 if aSecond then 154 aService.second = aSecond:lower() 155 aPrefix = aService.first .. aService.second 156 end 157 158 aService.prefix = aPrefix 159 160 setmetatable( aService, self ) 161 self.__index = self 162 163 return aService 164 end 165 166 function self:__concat( aValue ) 167 return tostring( self ) .. tostring( aValue ) 168 end 169 170 function self:__tostring() 171 return self.second or self.first 172 end HTTP/WikiLayout.txt
r1166 r1182 26 26 27 27 <div class='column span-4 append-1 last label'> 28 <a href=' /index' title='Index'>Index</a> | <a href='/date' title='Date'>Date</a> | <a href='/recent' title='Recent'>Recent</a>28 <a href='[v:indexLink]' title='Index'>Index</a> | <a href='[v:dateLink]' title='Date'>Date</a> | <a href='/recent' title='Recent'>Recent</a> 29 29 </div> 30 30 HTTP/WikiPreview.lua
r1166 r1182 1 1 -------------------------------------------------------------------------------- 2 -- Title: WikiPreview Service.lua2 -- Title: WikiPreview.lua 3 3 -- Description: Like a square peg in a round hole 4 4 -- Author: RaphaĆ«l Szwarc http://alt.textdrive.com/lua/ … … 14 14 local WikiService = require( 'WikiService' ) 15 15 16 local BaseLink = WikiService.BaseLink 17 local DateLink = WikiService.DateLink 18 local FeedLink = WikiService.FeedLink 19 local IndexLink = WikiService.IndexLink 20 16 21 local Encode = WikiService.Encode 22 23 local os = require( 'os' ) 17 24 18 25 local getmetatable = getmetatable … … 22 29 23 30 -------------------------------------------------------------------------------- 24 -- WikiPreview Service31 -- WikiPreview 25 32 -------------------------------------------------------------------------------- 26 33 27 module( 'WikiPreview Service' )34 module( 'WikiPreview' ) 28 35 _VERSION = '1.0' 29 36 … … 31 38 local meta = getmetatable( self ) 32 39 33 function meta:__call( aContent, aContext ) 34 local aPreview = { content = aContent, context = aContext } 40 -------------------------------------------------------------------------------- 41 -- Metamethods 42 -------------------------------------------------------------------------------- 43 44 function meta:__call( aContent, aParent, aContext ) 45 local aPreview = { content = aContent, parent = aParent, context = aContext } 35 46 36 47 setmetatable( aPreview, self ) … … 43 54 local markdown = require( 'markdown' ) 44 55 local aLayoutTemplate = Template[ 'WikiLayout.txt' ] 45 local aTemplate = Template[ 'WikiPreview Service.txt' ]56 local aTemplate = Template[ 'WikiPreview.txt' ] 46 57 local aContext = self.context 58 local aDate = os.date( '!*t', self.content.creation ) 59 local aDateLink = DateLink( aDate.year, aDate.month, aDate.day ) 47 60 local aToken = aContext.token 48 61 … … 66 79 aTemplate[ 'version' ] = Encode( aContext.version ) 67 80 68 aLayoutTemplate[ 'baseLink' ] = Encode( HTTP.request.url + '/' ) 69 aLayoutTemplate[ 'feedLink' ] = Encode( HTTP.request.url.path .. '.xml' ) 81 aLayoutTemplate[ 'baseLink' ] = Encode( BaseLink() ) 82 aLayoutTemplate[ 'feedLink' ] = Encode( FeedLink( self.parent.parent ) ) 83 aLayoutTemplate[ 'indexLink' ] = Encode( IndexLink( self.content.prefix ) ) 84 aLayoutTemplate[ 'dateLink' ] = Encode( aDateLink ) 70 85 aLayoutTemplate[ 'path' ] = aContext.path 71 86 aLayoutTemplate[ 'query' ] = nil … … 76 91 return tostring( aLayoutTemplate ) 77 92 end 93 94 HTTP/WikiRecentService.lua
r1167 r1182 27 27 local GetType = WikiService.GetType 28 28 local HTML = WikiService.HTML 29 local Path = WikiService.Path 29 30 30 31 local os = require( 'os' ) … … 37 38 local require = require 38 39 local tostring = tostring 39 local print = print40 40 41 41 -------------------------------------------------------------------------------- … … 49 49 local meta = getmetatable( self ) 50 50 51 self.toURL =function( aService, anObject ) 52 return URL( aService.prefix ) 53 end 54 55 self.toObject = function( aService, aURL ) 56 local WikiRecentService = require( 'WikiRecentService' ) 57 local aService = WikiRecentService() 58 59 return aService 60 end 61 62 function meta:__call() 63 local aService = {} 64 65 setmetatable( aService, self ) 66 self.__index = self 67 68 return aService 69 end 70 71 local function Path( self ) 72 local WikiPath = require( 'WikiPath' ) 73 local aPath = WikiPath( { title = 'Recent' } ) 74 75 return aPath 76 end 51 -------------------------------------------------------------------------------- 52 -- Utilities 53 -------------------------------------------------------------------------------- 77 54 78 55 local function EntryComparator( anEntry, anotherEntry ) … … 111 88 112 89 return aList 90 end 91 92 -------------------------------------------------------------------------------- 93 -- Service methods 94 -------------------------------------------------------------------------------- 95 96 self.toURL =function( aService, anObject ) 97 return URL( aService.prefix ) 98 end 99 100 self.toObject = function( aService, aURL ) 101 local WikiRecentService = require( 'WikiRecentService' ) 102 local aService = WikiRecentService() 103 104 return aService 113 105 end 114 106 … … 177 169 end 178 170 171 -------------------------------------------------------------------------------- 172 -- Metamethods 173 -------------------------------------------------------------------------------- 174 175 function meta:__call() 176 local aService = {} 177 178 setmetatable( aService, s