Sha256: 9847d1387af0c02d54bca352c1498d7548c2f900271da2cf515bc366e18f0a26

Contents?: true

Size: 1.5 KB

Versions: 31

Compression:

Stored size: 1.5 KB

Contents

# encoding: utf-8
require 'date'

# gem install facets
require 'facets/integer/ordinal'

module Jekyll
  module DateDe
    #Deutsche Lokalisation:
    MONTHNAMES_DE = [nil,
      "Januar", "Februar", "März", "April", "Mai", "Juni",
      "Juli", "August", "September", "Oktober", "November", "Dezember" ]
    ABBR_MONTHNAMES_DE = [nil,
      "Jan", "Feb", "Mär", "Apr", "Mai", "Jun",
      "Jul", "Aug", "Sep", "Okt", "Nov", "Dez" ]
    DAYNAMES_DE = [
      "Sonntag", "Montag", "Dienstag", "Mittwoch",
      "Donnerstag", "Freitag", "Samstag" ]
    ABBR_DAYNAMES_DE = [
      "So", "Mo", "Di", "Mi",
      "Do", "Fr", "Sa" ]

    # Returns a datetime if the input is a string
    def datetime(date)
      if date.class == String
        date = Time.parse(date)
      end
      date
    end

    # Formats date by given date format
    def format_date(date, format)
      date = datetime(date)
        if format.nil? || format.empty? || format == "ordinal"
          date_formatted = ordinalize(date)
        else
          format.gsub!(/%a/, ABBR_DAYNAMES_DE[date.wday])
          format.gsub!(/%A/, DAYNAMES_DE[date.wday])
          format.gsub!(/%b/, ABBR_MONTHNAMES_DE[date.mon])
          format.gsub!(/%B/, MONTHNAMES_DE[date.mon])
          date_formatted = date.strftime(format)
        end
        date_formatted
    end

    # Usage: {{ post.date | full_date_de }}
    # Result: 13. Dezember 2017
    def full_date_de(date)
      format_date(date, "%d. %B %Y")
    end
  end
end

Liquid::Template.register_filter(Jekyll::DateDe)

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
jekyll-octopod-0.9.23 lib/jekyll/date_de.rb
jekyll-octopod-0.9.22 lib/jekyll/date_de.rb
jekyll-octopod-0.9.21 lib/jekyll/date_de.rb
jekyll-octopod-0.9.20 lib/jekyll/date_de.rb
jekyll-octopod-0.9.19 lib/jekyll/date_de.rb
jekyll-octopod-0.9.18 lib/jekyll/date_de.rb
jekyll-octopod-0.9.17 lib/jekyll/date_de.rb
jekyll-octopod-0.9.15 lib/jekyll/date_de.rb
jekyll-octopod-0.9.14 lib/jekyll/date_de.rb
jekyll-octopod-0.9.13 lib/jekyll/date_de.rb
jekyll-octopod-0.9.12 lib/jekyll/date_de.rb
jekyll-octopod-0.9.11 lib/jekyll/date_de.rb
jekyll-octopod-0.9.10 lib/jekyll/date_de.rb
jekyll-octopod-0.9.9 lib/jekyll/date_de.rb
jekyll-octopod-0.9.8 lib/jekyll/date_de.rb
jekyll-octopod-0.9.7 lib/jekyll/date_de.rb
jekyll-octopod-0.9.6 lib/jekyll/date_de.rb
jekyll-octopod-0.9.5 lib/jekyll/date_de.rb
jekyll-octopod-0.9.4 lib/jekyll/date_de.rb
octopod-exe-0.9.4 lib/jekyll/date_de.rb