Class: JekyllLastCommit::Tag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll-last-commit/tag.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, date_format, tokens) ⇒ Tag

Returns a new instance of Tag.



3
4
5
6
# File 'lib/jekyll-last-commit/tag.rb', line 3

def initialize(tag_name, date_format, tokens)
  super
  @date_format = date_format.empty? ? nil : date_format.strip
end

Instance Method Details

#default_date_format(context) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/jekyll-last-commit/tag.rb', line 18

def default_date_format(context)
  site = context.registers[:site]

  date_format = site.config.dig('jekyll-last-commit', 'date_format')
  date_format ||= '%B %d, %Y'

  date_format
end

#render(context) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/jekyll-last-commit/tag.rb', line 8

def render(context)
  @date_format ||= default_date_format(context)

  page = context.registers[:page]

  time = page['last_modified_at']

  time.nil? ? "" : Time.at(time.to_i).strftime(@date_format)
end