Changeset 1324

Show
Ignore:
Timestamp:
02/18/08 18:11:59
Author:
rsz
Message:

cleanup

Files:

Legend:

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

    r1305 r1324  
    2525local tonumber = tonumber 
    2626local tostring = tostring 
     27local print = print 
    2728 
    2829-------------------------------------------------------------------------------- 
     
    313314end 
    314315 
     316local function CanWrite( aName ) 
     317    local File = require( 'File' ) 
     318    local aDirectory = Directory( aName ) 
     319    local aFile = File( aDirectory.path, 'nowrite' ) 
     320     
     321    if aFile.exists then 
     322        return false 
     323    end 
     324     
     325    return true 
     326end 
     327 
     328local function SetWrite( aName, aValue ) 
     329    local File = require( 'File' ) 
     330    local aDirectory = Directory( aName ) 
     331    local aFile = File( aDirectory.path, 'nowrite' ) 
     332     
     333    print( 'SetWrite', aFile, aValue ) 
     334 
     335    if aValue then 
     336        aFile.delete = true 
     337    else 
     338        aFile.content = 'nowrite' 
     339    end     
     340end 
     341 
    315342-------------------------------------------------------------------------------- 
    316343-- File utilities 
     
    412439 
    413440function self:__index( aKey ) 
    414     if aKey == 'data' then 
     441    if aKey == 'canWrite' then 
     442        return CanWrite( self.name ) 
     443    elseif aKey == 'data' then 
    415444        local someData = ContentData( self.name, self.version ) 
    416445        rawset( self, 'data', someData ) 
     
    447476 
    448477function self:__newindex( aKey, aValue ) 
    449     if aKey == 'file' then 
    450         AddFile( self.name, aValue ) 
    451          
    452         return 
     478    if aKey == 'canWrite' then 
     479        return SetWrite( self.name, aValue ) 
     480    elseif aKey == 'file' then 
     481        return AddFile( self.name, aValue ) 
    453482    elseif aKey == 'link' then 
    454         AddLink( self.name, aValue ) 
    455          
    456         return 
     483        return AddLink( self.name, aValue ) 
    457484    elseif aKey == 'modification' then 
    458485        DataFile( self.name, self.version ).modification = aValue 
  • HTTP/WikiContentService.lua

    r1314 r1324  
    9696     
    9797    return isLastWeek, aStartTime, anEndTime 
     98end 
     99 
     100local function EditorLink( self )  
     101    local aContent = self.content 
     102    local aTitle = Encode( aContent.data.title ) 
     103 
     104    if aContent.canWrite then 
     105        local aLink = Encode( self.path( 'editor' ) ) 
     106     
     107        return ( '<a href=\'%s\' title=\'Editor\' rel=\'nofollow\'>%s</a>' ):format( aLink, aTitle ) 
     108     
     109    end 
     110     
     111    return aTitle 
    98112end 
    99113 
     
    177191 
    178192-------------------------------------------------------------------------------- 
     193-- Default content 
     194-------------------------------------------------------------------------------- 
     195 
     196local function Syntax() 
     197    local aContent = WikiContent( 'markdown-syntax-reference' ) 
     198     
     199    if not aContent.exists then 
     200        local WikiDate = require( 'WikiDate' ) 
     201        local WikiRecent = require( 'WikiRecent' ) 
     202        local WikiSearch = require( 'WikiSearch' ) 
     203        local aTemplate = Template[ 'MarkdownSyntaxReference.txt' ] 
     204         
     205        aContent.by = 'file://nanoki@localhost/' 
     206        aContent.title = 'Markdown syntax reference' 
     207        aContent.text = tostring( aTemplate ) 
     208        aContent() 
     209         
     210        WikiDate[ aContent.creation ] = aContent.name 
     211        WikiRecent[ aContent.modification ] = aContent.name 
     212        WikiSearch[ aContent.name ] = aContent.name 
     213    end 
     214end 
     215 
     216local function Nanoki() 
     217    local aContent = WikiContent( 'nanoki' ) 
     218     
     219    if not aContent.exists then 
     220        local File = require( 'File' ) 
     221        local WikiDate = require( 'WikiDate' ) 
     222        local WikiRecent = require( 'WikiRecent' ) 
     223        local WikiSearch = require( 'WikiSearch' ) 
     224        local aDirectory = File( 'Nanoki' ) 
     225        local aTemplate = Template[ 'Nanoki.txt' ] 
     226         
     227        aContent.by = 'file://nanoki@localhost/' 
     228        aContent.title = 'Nanoki' 
     229        aContent.text = tostring( aTemplate ) 
     230        aContent() 
     231         
     232        for aFile in aDirectory() do 
     233            aContent.file = aFile 
     234        end 
     235         
     236        aContent.canWrite = false 
     237        WikiDate[ aContent.creation ] = aContent.name 
     238        WikiRecent[ aContent.modification ] = aContent.name 
     239        WikiSearch[ aContent.name ] = aContent.name 
     240    end 
     241end 
     242 
     243Syntax() 
     244Nanoki() 
     245 
     246-------------------------------------------------------------------------------- 
    179247-- Service methods 
    180248-------------------------------------------------------------------------------- 
     
    214282        Referer( self ) 
    215283 
    216         aTemplate[ 'editorLink' ] = Encode( self.path( 'editor' ) ) 
    217         aTemplate[ 'historyLink' ] = Encode( self.path( 'editor' )( 'history' ) ) 
     284        aTemplate[ 'editorLink' ] = EditorLink( self ) 
    218285        aTemplate[ 'version' ] = Encode(self.content.version ) 
    219286        aTemplate[ 'title' ] = Encode( self.content.data.title ) 
     
    297364    local aContent = WikiContent( self.content.name, aVersion ) 
    298365     
    299     if not aContent.exists then 
    300         aContent = self.content 
    301     end 
    302      
    303     if not aContent.exists then 
    304         HTTP.response.status.code = 404 
    305         HTTP.response.status.description = 'Not Found' 
    306     end 
    307      
    308     return WikiEditorService( aContent, self ) 
     366    if aContent.canWrite then 
     367        if not aContent.exists then 
     368            aContent = self.content 
     369        end 
     370         
     371        if not aContent.exists then 
     372            HTTP.response.status.code = 404 
     373            HTTP.response.status.description = 'Not Found' 
     374        end 
     375         
     376        return WikiEditorService( aContent, self ) 
     377    end 
    309378end 
    310379 
  • HTTP/WikiContentService.txt

    r1286 r1324  
    1 <h1><a href='[v:editorLink]' title='Editor' rel='nofollow'>[v:title]</a></h1> 
     1<h1>[v:editorLink]</h1> 
    22<h4>Published on <a href='[v:dateLink]' title='Published on [v:creation]. Edited on [v:modification] by [v:by].'>[v:creation]</a> [v:tag]</h4> 
    33[v:message] 
  • HTTP/WikiEditorService.lua

    r1322 r1324  
    254254end 
    255255 
    256 local function Syntax() 
    257     local aContent = WikiContent( 'markdown-syntax-reference' ) 
    258      
    259     if not aContent.exists then 
    260         local aTemplate = Template[ 'MarkdownSyntaxReference.txt' ] 
    261          
    262         aContent.by = 'file://nanoki@localhost/' 
    263         aContent.title = 'Markdown syntax reference' 
    264         aContent.text = tostring( aTemplate ) 
    265         aContent() 
    266          
    267         WikiDate[ aContent.creation ] = aContent.name 
    268         WikiSearch[ aContent.name ] = aContent.name 
    269         WikiRecent[ aContent.modification ] = aContent.name 
    270     end 
    271 end 
    272  
    273 local function Nanoki() 
    274     local aContent = WikiContent( 'nanoki' ) 
    275      
    276     if not aContent.exists then 
    277         local File = require( 'File' ) 
    278         local aDirectory = File( 'Nanoki' ) 
    279         local aTemplate = Template[ 'Nanoki.txt' ] 
    280          
    281         aContent.by = 'file://nanoki@localhost/' 
    282         aContent.title = 'Nanoki' 
    283         aContent.text = tostring( aTemplate ) 
    284         aContent() 
    285          
    286         for aFile in aDirectory() do 
    287             aContent.file = aFile 
    288         end 
    289          
    290         WikiDate[ aContent.creation ] = aContent.name 
    291         WikiSearch[ aContent.name ] = aContent.name 
    292         WikiRecent[ aContent.modification ] = aContent.name 
    293     end 
    294 end 
    295  
    296256-------------------------------------------------------------------------------- 
    297257-- Service methods 
     
    306266    local aContext = Context() 
    307267    local aToken = Token() 
    308      
    309     Syntax() 
    310     Nanoki() 
    311268     
    312269    aTemplate[ 'actionPath' ] = Encode( HTTP.request.url.path )