Module: Webgen::Tag::Date

Defined in:
lib/webgen/tag/date.rb

Overview

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

Class Method Summary collapse

Class Method Details

.call(tag, body, context) ⇒ Object

Return the current date formatted as specified.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/webgen/tag/date.rb', line 11

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