class Jekyll::Tags::PostComparer

Constants

MATCHER

Attributes

date[R]
name[R]
path[R]
slug[R]

Public Class Methods

new(name) click to toggle source
# File lib/jekyll/tags/post_url.rb, line 8
def initialize(name)
  @name = name
  all, @path, @date, @slug = *name.sub(/^\//, "").match(MATCHER)
  raise ArgumentError.new("'#{name}' does not contain valid date and/or title.") unless all

  @name_regex = /^#{path}#{date}-#{slug}\.[^.]+/
end

Public Instance Methods

==(other) click to toggle source
# File lib/jekyll/tags/post_url.rb, line 16
def ==(other)
  other.basename.match(@name_regex)
end
deprecated_equality(other) click to toggle source
# File lib/jekyll/tags/post_url.rb, line 20
def deprecated_equality(other)
  date = Utils.parse_date(name, "'#{name}' does not contain valid date and/or title.")
  slug == post_slug(other) &&
    date.year  == other.date.year &&
    date.month == other.date.month &&
    date.day   == other.date.day
end

Private Instance Methods

post_slug(other) click to toggle source

Construct the directory-aware post slug for a Jekyll::Post

other - the Jekyll::Post

Returns the post slug with the subdirectory (relative to _posts)

# File lib/jekyll/tags/post_url.rb, line 34
def post_slug(other)
  path = other.basename.split("/")[0...-1].join("/")
  if path.nil? || path == ""
    other.data['slug']
  else
    path + '/' + other.data['slug']
  end
end