Changeset 1182

Show
Ignore:
Timestamp:
01/31/08 17:28:52
Author:
rsz
Message:

cleanup

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • HTTP/HTTPExtra.lua

    r1180 r1182  
    1010 
    1111-- import dependencies 
     12local HTTP = require( 'HTTP' ) 
     13 
    1214local io = require( 'io' ) 
    1315local os = require( 'os' ) 
    1416local table = require( 'table' ) 
    15 local HTTP = require( 'HTTP' ) 
    1617 
    1718local getmetatable = getmetatable 
     
    2829local type = type 
    2930local unpack = unpack 
     31local print = print 
    3032 
    3133-------------------------------------------------------------------------------- 
     
    514516        aMethod = 'get' 
    515517    end 
    516  
     518     
    517519    aHandlerAction = aMethod:lower() .. Capitalize( aHandlerAction ) 
    518      
     520 
    519521    if type( anObject ) == 'table' and type( anObject[ aHandlerAction ] ) == 'function' then 
    520522        local someArguments = Argument( anObject, anArgument ) 
     
    549551 
    550552local function Iterator( aURL, aBase ) 
     553    local URL = require( 'URL' ) 
    551554    local URLPath = require( 'URLPath' ) 
    552555    local aPath = URLPath( tostring( aURL.path ):sub( tostring( aBase.path ):len() + 1 ) ) 
     556    local aServicePath = URLPath( aBase.path ) 
    553557    local anAction = Action() 
    554     local aCount = #aPath 
    555     local anIndex = 0 
     558    local aCount = #aPath + 1 
     559    local anIndex = 1 
    556560     
    557561    if anAction then 
    558         aPath[ aCount + 1 ] = anAction 
    559         aCount = aCount + 1 
     562        aPath[ #aPath + 1 ] = anAction 
     563        aCount = #aPath 
    560564    else 
    561         aPath[ aCount + 1 ] = '' 
    562         aCount = aCount + 1 
    563     end 
    564              
     565        aPath[ #aPath + 1 ] = '' 
     566        aCount = #aPath 
     567    end 
     568     
    565569    return function() 
    566         anIndex = anIndex + 1 
    567          
    568570        if anIndex <= aCount then 
    569571            local isLast = anIndex == aCount 
     572            local aComponent = aPath[ anIndex ] 
    570573             
    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 
    572581        end 
    573582    end 
     
    576585local function Dispatch( aService, aURL, anObject, aMethod ) 
    577586    local aBase = aService[ anObject ] 
     587    local aLocation = nil 
    578588 
    579589    if not aBase then 
     
    584594        return nil, aBase 
    585595    end 
    586      
    587     for anAction, isLast in Iterator( aURL, aBase ) do 
     596 
     597    for aPath, anAction, isLast in Iterator( aURL, aBase ) do 
    588598        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 
    595613             
    596             if aLocation then 
    597                 return anObject, aLocation 
    598             end 
    599         end 
    600     end 
     614    return anObject, aLocation 
    601615end 
    602616 
  • HTTP/URL.lua

    r1166 r1182  
    6767    aPath.absolute = aValue:sub( 1, 1 ) == '/'  
    6868    aPath.directory = aValue:sub( -1, -1 ) == '/'  
    69      
     69 
    7070    return aPath 
    7171end 
     
    104104 
    105105local 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 '' ) ) 
    113107     
    114108    setmetatable( aPath, self ) 
     
    167161end 
    168162 
     163function 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 
     173end 
     174 
    169175function self:__add( aValue ) 
    170     return AddPath( self, NewPath( aValue ) ) 
     176    return AddPath( self(), NewPath( aValue ) ) 
    171177end 
    172178 
     
    228234 
    229235local 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 '' ) ) 
    237237     
    238238    setmetatable( aParameter, self ) 
     
    388388 
    389389local 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 '' ) ) 
    397391     
    398392    setmetatable( aURL, self ) 
  • HTTP/WikiContentService.lua

    r1173 r1182  
    1111-- import dependencies 
    1212local HTTP = require( 'HTTP' ) 
    13 local HTTPExtra = require( 'HTTPExtra' ) 
    14 local HTTPService = require( 'HTTPService' ) 
    1513local Template = require( 'Template' ) 
    1614local URL = require( 'URL' ) 
     
    1917local WikiService = require( 'WikiService' ) 
    2018 
     19local BaseLink = WikiService.BaseLink 
     20local DateLink = WikiService.DateLink 
     21local FeedLink = WikiService.FeedLink 
     22local IndexLink = WikiService.IndexLink 
     23 
    2124local ContentIterator = WikiService.ContentIterator 
    2225local NameIterator = WikiService.NameIterator 
     26 
    2327local Encode = WikiService.Encode 
    2428local GetType = WikiService.GetType 
    2529local HTML = WikiService.HTML 
     30local Path = WikiService.Path 
    2631 
    2732local os = require( 'os' ) 
     
    4449local meta = getmetatable( self ) 
    4550 
    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-------------------------------------------------------------------------------- 
    8554 
    8655local function Message( self ) 
     
    9867end 
    9968 
    100 local function Link( self ) 
     69local function Referer( self ) 
    10170    if self.content.name ~= 'main' and HTTP.request.header[ 'referer' ] then 
    10271        local URL = require( 'URL' ) 
     
    12796end 
    12897 
     98-------------------------------------------------------------------------------- 
     99-- Service methods 
     100-------------------------------------------------------------------------------- 
     101 
     102self.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 
     110end 
     111 
     112self.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 
     123end 
     124 
    129125function self:getHtml() 
    130126    if self.content.exists then 
     
    134130        local aLinkIterator, aLinkCount = ContentIterator( self.content.link ) 
    135131        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' ) ) 
    144138        aTemplate[ 'version' ] = Encode(self.content.version ) 
    145139        aTemplate[ 'title' ] = Encode( self.content.data.title ) 
    146         aTemplate[ 'href' ] = Encode( aDatePath
     140        aTemplate[ 'dateLink' ] = Encode( aDateLink
    147141        aTemplate[ 'creation' ] = Encode( os.date( '!%A, %d %B %Y', self.content.creation ) ) 
    148142        aTemplate[ 'modification' ] = Encode( os.date( '!%A, %d %B %Y at %I:%M %p', self.content.modification ) ) 
     
    166160        aTemplate[ 'link' ] = aLinkTemplate 
    167161         
    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 ) 
    170166        aLayoutTemplate[ 'path' ] = Path( self ) 
    171167        aLayoutTemplate[ 'query' ] = nil 
     
    176172        return tostring( aLayoutTemplate ) 
    177173    else 
    178         return nil, HTTPService[ self ] .. '/editor' 
     174        return nil, self.path( 'editor' ) 
    179175    end 
    180176end 
     
    229225    end 
    230226     
    231     return WikiEditorService( aContent
     227    return WikiEditorService( aContent, self
    232228end 
    233229 
     
    242238end 
    243239 
     240-------------------------------------------------------------------------------- 
     241-- Metamethods 
     242-------------------------------------------------------------------------------- 
     243 
     244function meta:__call( aContent ) 
     245    local aService = { content = aContent } 
     246     
     247    setmetatable( aService, self ) 
     248    self.__index = self     
     249     
     250    return aService 
     251end 
     252 
     253function self:__concat( aValue ) 
     254    return tostring( self ) .. tostring( aValue ) 
     255end 
     256 
     257function self:__tostring() 
     258    return tostring( self.content.data.title ) 
     259end 
  • HTTP/WikiContentService.txt

    r1173 r1182  
    11<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> 
    33[v:message] 
    44[v:content] 
  • HTTP/WikiDateService.lua

    r1167 r1182  
    1919local WikiService = require( 'WikiService' ) 
    2020 
     21local BaseLink = WikiService.BaseLink 
     22local DateLink = WikiService.DateLink 
     23local FeedLink = WikiService.FeedLink 
     24local IndexLink = WikiService.IndexLink 
     25 
    2126local ContentIterator = WikiService.ContentIterator 
    2227local Description = WikiService.Description 
     
    2429local GetType = WikiService.GetType 
    2530local HTML = WikiService.HTML 
     31local Path = WikiService.Path 
    2632 
    2733local os = require( 'os' ) 
     
    4248local self = setmetatable( _M, {} ) 
    4349local meta = getmetatable( self ) 
     50 
     51-------------------------------------------------------------------------------- 
     52-- Utilities 
     53-------------------------------------------------------------------------------- 
     54 
     55local 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 ) 
     68end 
     69 
     70-------------------------------------------------------------------------------- 
     71-- Service methods 
     72-------------------------------------------------------------------------------- 
    4473 
    4574self.toURL =function( aService, anObject ) 
     
    74103end 
    75104 
    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 then 
    82         aService.year = aDate.year 
    83     end 
    84      
    85     if aMonth and aMonth ~= aDate.month then 
    86         aService.month = aDate.month 
    87     end 
    88      
    89     if aDay and aDay ~= aDate.day then 
    90         aService.day = aDate.day 
    91     end 
    92      
    93     setmetatable( aService, self ) 
    94     self.__index = self     
    95      
    96     return aService 
    97 end 
    98  
    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 then 
    104         aFormat = '!%A, %d %B %Y' 
    105     elseif aMonth then 
    106         aFormat = '!%B %Y' 
    107     else 
    108         aFormat = '!%Y' 
    109     end 
    110      
    111     return os.date( aFormat, aTime ) 
    112 end 
    113  
    114 local function Path( self ) 
    115     local WikiDateService = require( 'WikiDateService' ) 
    116     local WikiPath = require( 'WikiPath' ) 
    117     local aPath = WikiPath() 
    118     local aYear = self.year 
    119     local aMonth = self.month 
    120     local aDay = self.day 
    121      
    122     if aYear then     
    123         local aHref = HTTPService[ WikiDateService( aYear ) ].path 
    124         local aTitle = Title( aYear ) 
    125          
    126         aPath[ #aPath + 1 ] = { href = aHref, title = aTitle } 
    127     end 
    128      
    129     if aMonth then 
    130         local aHref = HTTPService[ WikiDateService( aYear, aMonth ) ].path 
    131         local aTitle = Title( aYear, aMonth ) 
    132  
    133         aPath[ #aPath + 1 ] = { href = aHref, title = aTitle } 
    134     end 
    135      
    136     if aDay then 
    137         local aHref = HTTPService[ WikiDateService( aYear, aMonth, aDay ) ].path 
    138         local aTitle = Title( aYear, aMonth, aDay ) 
    139  
    140         aPath[ #aPath + 1 ] = { href = aHref, title = aTitle } 
    141     end 
    142      
    143     return aPath 
    144 end 
    145  
    146105function self:getHtml() 
    147106    local WikiDateNavigation = require( 'WikiDateNavigation' ) 
     
    172131    aTemplate[ 'title' ] = Encode( aTitle ) 
    173132     
    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 ) ) 
    176137    aLayoutTemplate[ 'path' ] = Path( self ) 
    177138    aLayoutTemplate[ 'query' ] = nil 
     
    200161end 
    201162 
     163-------------------------------------------------------------------------------- 
     164-- Metamethods 
     165-------------------------------------------------------------------------------- 
    202166 
     167function 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 
     188end 
     189 
     190function self:__concat( aValue ) 
     191    return tostring( self ) .. tostring( aValue ) 
     192end 
     193 
     194function self:__tostring() 
     195    return Title( self.year, self.month, self.day ) 
     196end 
  • HTTP/WikiEditorService.lua

    r1181 r1182  
    2323local WikiService = require( 'WikiService' ) 
    2424 
     25local BaseLink = WikiService.BaseLink 
     26local DateLink = WikiService.DateLink 
     27local FeedLink = WikiService.FeedLink 
     28local IndexLink = WikiService.IndexLink 
     29 
    2530local Encode = WikiService.Encode 
    2631local GetType = WikiService.GetType 
     32local Path = WikiService.Path 
    2733 
    2834local os = require( 'os' ) 
     
    4854local meta = getmetatable( self ) 
    4955 
    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-------------------------------------------------------------------------------- 
    7059 
    7160local function Message( self ) 
     
    165154end 
    166155 
     156-------------------------------------------------------------------------------- 
     157-- Service methods 
     158-------------------------------------------------------------------------------- 
     159 
    167160function self:get() 
    168161    local aLayoutTemplate = Template[ 'WikiLayout.txt' ] 
    169162    local aTemplate = Template[ 'WikiEditorService.txt' ] 
    170163    local aContent = self.content 
     164    local aDate = os.date( '!*t', aContent.creation ) 
     165    local aDateLink = DateLink( aDate.year, aDate.month, aDate.day ) 
    171166    local aContext = Context() 
    172167    local aToken = Token() 
    173168     
    174169    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' )
    176171    aTemplate[ 'message' ] = Message( self ) 
    177172     
     
    190185    aTemplate[ 'version' ] = Encode( Version( aContent, aContext ) ) 
    191186 
    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 ) 
    194191    aLayoutTemplate[ 'path' ] = Path( self ) 
    195192    aLayoutTemplate[ 'query' ] = nil 
     
    206203 
    207204function self:postPreview() 
    208     local WikiPreviewService = require( 'WikiPreviewService' ) 
     205    local WikiPreview = require( 'WikiPreview' ) 
    209206    local aContext = Context() 
    210207    local aPath = Path( self ) 
     
    213210    aContext.path = aPath 
    214211    aContext.token = Token() 
    215  
    216     return tostring( WikiPreviewService( self.content, aContext ) ) 
     212     
     213    return tostring( WikiPreview( self.content, self, aContext ) ) 
    217214end 
    218215 
     
    261258        local WikiHistoryService = require( 'WikiHistoryService' ) 
    262259     
    263         return WikiHistoryService( self.content
     260        return WikiHistoryService( self.content, self
    264261    end 
    265262     
    266263    return nil, HTTPService[ WikiContentService( self.content ) ] 
    267264end 
     265 
     266-------------------------------------------------------------------------------- 
     267-- Metamethods 
     268-------------------------------------------------------------------------------- 
     269 
     270function meta:__call( aContent, aParent ) 
     271    local anEditor = { content = aContent, parent = aParent } 
     272     
     273    setmetatable( anEditor, self ) 
     274    self.__index = self     
     275     
     276    return anEditor 
     277end 
     278 
     279function self:__concat( aValue ) 
     280    return tostring( self ) .. tostring( aValue ) 
     281end 
     282 
     283function self:__tostring() 
     284    return 'Editor' 
     285end 
  • HTTP/WikiHistoryService.lua

    r1173 r1182  
    1818local WikiService = require( 'WikiService' ) 
    1919 
     20local BaseLink = WikiService.BaseLink 
     21local DateLink = WikiService.DateLink 
     22local FeedLink = WikiService.FeedLink 
     23local IndexLink = WikiService.IndexLink 
     24 
    2025local Description = WikiService.Description 
    2126local Encode = WikiService.Encode 
    2227local GetType = WikiService.GetType 
     28local Path = WikiService.Path 
    2329 
    2430local os = require( 'os' ) 
     
    4349local meta = getmetatable( self ) 
    4450 
    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-------------------------------------------------------------------------------- 
    7154 
    7255local function EntryComparator( anEntry, anotherEntry ) 
     
    121104end 
    122105 
     106-------------------------------------------------------------------------------- 
     107-- Service methods 
     108-------------------------------------------------------------------------------- 
     109 
    123110function self:get() 
    124111    local aLayoutTemplate = Template[ 'WikiLayout.txt' ] 
     
    126113    local aDate = os.date( '!*t', self.content.creation ) 
    127114    local aDateTitle = os.date( '!%A, %d %B %Y', self.content.creation ) 
     115    local aDateLink = DateLink( aDate.year, aDate.month, aDate.day ) 
    128116    local someEntries = Entries( self.content.name, self.content.versions ) 
    129117    local aCount = 0 
     
    159147    aTemplate[ 'description' ] = Description( aCount ) 
    160148 
    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 ) 
    163153    aLayoutTemplate[ 'path' ] = Path( self ) 
    164154    aLayoutTemplate[ 'query' ] = nil 
     
    180170            local WikiVersionService = require( 'WikiVersionService' ) 
    181171         
    182             return WikiVersionService( aContent
     172            return WikiVersionService( aContent, self
    183173        end 
    184174    end 
    185175end 
     176 
     177-------------------------------------------------------------------------------- 
     178-- Metamethods 
     179-------------------------------------------------------------------------------- 
     180 
     181function meta:__call( aContent, aParent ) 
     182    local aHistory = { content = aContent, parent = aParent } 
     183     
     184    setmetatable( aHistory, self ) 
     185    self.__index = self     
     186 
     187    return aHistory 
     188end 
     189 
     190function self:__concat( aValue ) 
     191    return tostring( self ) .. tostring( aValue ) 
     192end 
     193 
     194function self:__tostring() 
     195    return 'History' 
     196end 
  • HTTP/WikiIndexService.lua

    r1167 r1182  
    1919local WikiService = require( 'WikiService' ) 
    2020 
     21local BaseLink = WikiService.BaseLink 
     22local DateLink = WikiService.DateLink 
     23local FeedLink = WikiService.FeedLink 
     24local IndexLink = WikiService.IndexLink 
     25 
    2126local ContentIterator = WikiService.ContentIterator 
    2227local Description = WikiService.Description 
    2328local Encode = WikiService.Encode 
    2429local GetType = WikiService.GetType 
     30local Path = WikiService.Path 
    2531 
    2632local getmetatable = getmetatable 
     
    3844local self = setmetatable( _M, {} ) 
    3945local meta = getmetatable( self ) 
     46 
     47-------------------------------------------------------------------------------- 
     48-- Utilities 
     49-------------------------------------------------------------------------------- 
     50 
     51-------------------------------------------------------------------------------- 
     52-- Service methods 
     53-------------------------------------------------------------------------------- 
    4054 
    4155self.toURL =function( aService, anObject ) 
     
    6377 
    6478    return aService 
    65 end 
    66  
    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 = nil 
    71     local aService = {} 
    72      
    73     if aFirst then 
    74         aService.first = aFirst:lower() 
    75         aPrefix = aService.first 
    76     end 
    77      
    78     if aSecond then 
    79         aService.second = aSecond:lower() 
    80         aPrefix = aService.first .. aService.second 
    81     end 
    82      
    83     aService.prefix = aPrefix 
    84      
    85     setmetatable( aService, self ) 
    86     self.__index = self     
    87      
    88     return aService 
    89 end 
    90  
    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 then 
    100         aPath[ #aPath + 1 ] = { href = HTTPService[ WikiIndexService( self.first, self.second ) ].path, title = self.second:lower() } 
    101     end 
    102  
    103     return aPath 
    10479end 
    10580 
     
    132107    aTemplate[ 'title' ] = aTitle 
    133108     
    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() ) 
    136113    aLayoutTemplate[ 'path' ] = Path( self ) 
    137114    aLayoutTemplate[ 'query' ] = nil 
     
    159136end 
    160137 
     138-------------------------------------------------------------------------------- 
     139-- Metamethods 
     140-------------------------------------------------------------------------------- 
    161141 
     142function 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 
     164end 
     165 
     166function self:__concat( aValue ) 
     167    return tostring( self ) .. tostring( aValue ) 
     168end 
     169 
     170function self:__tostring() 
     171    return self.second or self.first 
     172end 
  • HTTP/WikiLayout.txt

    r1166 r1182  
    2626 
    2727            <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> 
    2929            </div> 
    3030 
  • HTTP/WikiPreview.lua

    r1166 r1182  
    11-------------------------------------------------------------------------------- 
    2 -- Title:               WikiPreviewService.lua 
     2-- Title:               WikiPreview.lua 
    33-- Description:         Like a square peg in a round hole 
    44-- Author:              RaphaĆ«l Szwarc http://alt.textdrive.com/lua/ 
     
    1414local WikiService = require( 'WikiService' ) 
    1515 
     16local BaseLink = WikiService.BaseLink 
     17local DateLink = WikiService.DateLink 
     18local FeedLink = WikiService.FeedLink 
     19local IndexLink = WikiService.IndexLink 
     20 
    1621local Encode = WikiService.Encode 
     22 
     23local os = require( 'os' ) 
    1724 
    1825local getmetatable = getmetatable 
     
    2229 
    2330-------------------------------------------------------------------------------- 
    24 -- WikiPreviewService 
     31-- WikiPreview 
    2532-------------------------------------------------------------------------------- 
    2633 
    27 module( 'WikiPreviewService' ) 
     34module( 'WikiPreview' ) 
    2835_VERSION = '1.0' 
    2936 
     
    3138local meta = getmetatable( self ) 
    3239 
    33 function meta:__call( aContent, aContext ) 
    34     local aPreview = { content = aContent, context = aContext } 
     40-------------------------------------------------------------------------------- 
     41-- Metamethods 
     42-------------------------------------------------------------------------------- 
     43 
     44function meta:__call( aContent, aParent, aContext ) 
     45    local aPreview = { content = aContent, parent = aParent, context = aContext } 
    3546 
    3647    setmetatable( aPreview, self ) 
     
    4354    local markdown = require( 'markdown' ) 
    4455    local aLayoutTemplate = Template[ 'WikiLayout.txt' ] 
    45     local aTemplate = Template[ 'WikiPreviewService.txt' ] 
     56    local aTemplate = Template[ 'WikiPreview.txt' ] 
    4657    local aContext = self.context 
     58    local aDate = os.date( '!*t', self.content.creation ) 
     59    local aDateLink = DateLink( aDate.year, aDate.month, aDate.day ) 
    4760    local aToken = aContext.token 
    4861 
     
    6679    aTemplate[ 'version' ] = Encode( aContext.version ) 
    6780 
    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 ) 
    7085    aLayoutTemplate[ 'path' ] = aContext.path 
    7186    aLayoutTemplate[ 'query' ] = nil 
     
    7691    return tostring( aLayoutTemplate ) 
    7792end 
     93 
     94 
  • HTTP/WikiRecentService.lua

    r1167 r1182  
    2727local GetType = WikiService.GetType 
    2828local HTML = WikiService.HTML 
     29local Path = WikiService.Path 
    2930 
    3031local os = require( 'os' ) 
     
    3738local require = require 
    3839local tostring = tostring 
    39 local print = print 
    4040 
    4141-------------------------------------------------------------------------------- 
     
    4949local meta = getmetatable( self ) 
    5050 
    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-------------------------------------------------------------------------------- 
    7754 
    7855local function EntryComparator( anEntry, anotherEntry ) 
     
    11188     
    11289    return aList 
     90end 
     91 
     92-------------------------------------------------------------------------------- 
     93-- Service methods 
     94-------------------------------------------------------------------------------- 
     95 
     96self.toURL =function( aService, anObject ) 
     97    return URL( aService.prefix ) 
     98end 
     99 
     100self.toObject = function( aService, aURL ) 
     101    local WikiRecentService = require( 'WikiRecentService' ) 
     102    local aService = WikiRecentService()     
     103 
     104    return aService 
    113105end 
    114106 
     
    177169end 
    178170 
     171-------------------------------------------------------------------------------- 
     172-- Metamethods 
     173-------------------------------------------------------------------------------- 
     174 
     175function meta:__call() 
     176    local aService = {} 
     177     
     178    setmetatable( aService, s