Sha256: 87437611ee1549910f81a33ccb6b41d8f6306e5324b73cd8030f190a4336fd63

Contents?: true

Size: 1008 Bytes

Versions: 13

Compression:

Stored size: 1008 Bytes

Contents

# -*- encoding: utf-8 -*-

module Webgen
  class Tag

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

      # Return the current date formatted as specified.
      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

    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
webgen-1.7.3 lib/webgen/tag/date.rb
webgen-1.7.2 lib/webgen/tag/date.rb
webgen-1.7.1 lib/webgen/tag/date.rb
webgen-1.7.0 lib/webgen/tag/date.rb
webgen-1.6.0 lib/webgen/tag/date.rb
webgen-1.5.2 lib/webgen/tag/date.rb
webgen-1.5.1 lib/webgen/tag/date.rb
webgen-1.5.0 lib/webgen/tag/date.rb
webgen-1.4.1 lib/webgen/tag/date.rb
webgen-1.4.0 lib/webgen/tag/date.rb
webgen-1.3.0 lib/webgen/tag/date.rb
webgen-1.2.1 lib/webgen/tag/date.rb
webgen-1.2.0 lib/webgen/tag/date.rb