From 12ca8c7cc47f9c204f8c4c03fec42ed6474cb4ea Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Tue, 21 Aug 2012 11:06:15 +0200 Subject: [PATCH] Port the stat plugin to the webgen0.5 API --- ext/stat.rb | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ plugin/stat.rb | 60 ------------------------------------------------- 2 files changed, 61 insertions(+), 60 deletions(-) create mode 100644 ext/stat.rb delete mode 100644 plugin/stat.rb diff --git a/ext/stat.rb b/ext/stat.rb new file mode 100644 index 0000000..6255f21 --- /dev/null +++ b/ext/stat.rb @@ -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 + +# 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 diff --git a/plugin/stat.rb b/plugin/stat.rb deleted file mode 100644 index cf8e4ea..0000000 --- a/plugin/stat.rb +++ /dev/null @@ -1,60 +0,0 @@ -# This webgen plugin extends the available tags with tags that can retrieve -# stat(2) information. -# -# Copyright (2006) Paul van Tilburg - -# 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