Port the stat plugin to the webgen0.5 API

This commit is contained in:
Paul van Tilburg 2012-08-21 11:06:15 +02:00
parent c8ede2a622
commit 12ca8c7cc4
2 changed files with 61 additions and 60 deletions

61
ext/stat.rb Normal file
View File

@ -0,0 +1,61 @@
# -*- encoding: utf-8 -*-
#
# This webgen plugin extends the available tags with tags that can retrieve
# stat(2) information.
#
# Copyright (2012) Paul van Tilburg <paulvt@debian.org>
# This plugin is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
module Webgen::Tag
# Tag that puts the access time and date of the file on the page
class FileATimeTag
include Base
def call(tag, body, context)
atime = File.atime(File.join('src', context.content_node.node_info[:src]))
return atime.strftime(param('tag.fileatime.format'))
end
end # class FileADateTag
# Tag that puts the create time and date of the file on the page.
class FileCTimeTag
include Base
def call(tag, body, context)
ctime = File.ctime(File.join('src', context.content_node.node_info[:src]))
return ctime.strftime(param('tag.filectime.format'))
end
end # class FileCDateTag
# Tag that puts the modification time and date of the file on the page.
class FileMTimeTag
include Base
def call(tag, body, context)
mtime = File.mtime(File.join('src', context.content_node.node_info[:src]))
return mtime.strftime(param('tag.filemtime.format'))
end
end # class FileMDateTag
include Webgen::WebsiteAccess
website.config.tag.fileatime.format '%A, %B %d %H:%M:%S %Z %Y', :mandatory => 'default'
website.config.tag.filectime.format '%A, %B %d %H:%M:%S %Z %Y', :mandatory => 'default'
website.config.tag.filemtime.format '%A, %B %d %H:%M:%S %Z %Y', :mandatory => 'default'
website.config['contentprocessor.tags.map']['fileatime'] = FileATimeTag.to_s
website.config['contentprocessor.tags.map']['filectime'] = FileCTimeTag.to_s
website.config['contentprocessor.tags.map']['filemtime'] = FileMTimeTag.to_s
end

View File

@ -1,60 +0,0 @@
# This webgen plugin extends the available tags with tags that can retrieve
# stat(2) information.
#
# Copyright (2006) Paul van Tilburg <paulvt@debian.org>
# This plugin is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
class FileADateTag < Tags::DefaultTag
infos( :name => 'Custom/FileADate', :author => "Paul van Tilburg",
:summary => "Puts the access time and date of the file on the page" )
param 'format', '%A, %B %d %H:%M:%S %Z %Y',
'The format of the date (same options as Time#strftime).'
register_tag 'fileatime'
def process_tag(tag, chain)
atime = File.atime(chain.last.node_info[:src])
return atime.strftime(param('format'))
end
end # class FileADateTag
class FileCDateTag < Tags::DefaultTag
infos( :name => 'Custom/FileCDate', :author => "Paul van Tilburg",
:summary => "Puts the create time and date of the file on the page" )
param 'format', '%A, %B %d %H:%M:%S %Z %Y',
'The format of the date (same options as Time#strftime).'
register_tag 'filcatime'
def process_tag(tag, chain)
ctime = File.ctime(chain.last.node_info[:src])
return ctime.strftime(param('format'))
end
end # class FileCDateTag
class FileMDateTag < Tags::DefaultTag
infos( :name => 'Custom/FileMDate', :author => "Paul van Tilburg",
:summary => "Puts the modification time and date of the file on the page")
param 'format', '%A, %B %d %H:%M:%S %Z %Y',
'The format of the date (same options as Time#strftime).'
register_tag 'filemtime'
def process_tag(tag, chain)
mtime = File.mtime(chain.last.node_info[:src])
return mtime.strftime(param('format'))
end
end # class FileMDateTag