module Webgen::Tag::Date

Prints out the date using a format string which will be passed to Time#strftime. Therefore you can use everything Time#strftime offers.

Public Class Methods

call(tag, body, context) click to toggle source

Return the current date formatted as specified.

# File lib/webgen/tag/date.rb, line 10
def self.call(tag, body, context)
  key = context[:config]['tag.date.mi']
  val = context.content_node[key]

  if val && val.respond_to?(:strftime)
    time = val
  elsif val
    raise Webgen::RenderError.new("Value of meta information key '#{key}' not a valid date/time",
                                  "tag.date", context.dest_node, context.ref_node)
  elsif key
    raise Webgen::RenderError.new("No meta information key '#{key}' found",
                                  "tag.date", context.dest_node, context.ref_node)
  else
    time = Time.now
  end
  time.strftime(context[:config]['tag.date.format'])
end