62 lines
1.9 KiB
Ruby
62 lines
1.9 KiB
Ruby
# -*- 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
|