class Hikkoshi::Jekyll::Post

Constants

SEPARATOR

Public Class Methods

new(filename) click to toggle source
Calls superclass method
# File lib/hikkoshi/jekyll/post.rb, line 12
def initialize(filename)
  super()

  @filename = filename
  @original_metadata, @content = load_file(@filename)

  cast_metadata
  post_process
end

Public Instance Methods

categories=(categories) click to toggle source
# File lib/hikkoshi/jekyll/post.rb, line 39
def categories=(categories)
  @categories += categories if categories.is_a? Array
end
category=(category) click to toggle source
# File lib/hikkoshi/jekyll/post.rb, line 43
def category=(category)
  @categories << category
end
date=(date) click to toggle source
# File lib/hikkoshi/jekyll/post.rb, line 35
def date=(date)
  @published_at = parse_time(date)
end
published=(published) click to toggle source
# File lib/hikkoshi/jekyll/post.rb, line 26
def published=(published)
  if published == false
    @status = "draft"
  else
    # by default it is published
    @status = "published"
  end
end
slug=(slug) click to toggle source
# File lib/hikkoshi/jekyll/post.rb, line 22
def slug=(slug)
  @slug = slug
end
tags=(tags) click to toggle source
# File lib/hikkoshi/jekyll/post.rb, line 47
def tags=(tags)
  @tags += tags if tags.is_a? Array
end

Private Instance Methods

cast_metadata() click to toggle source
# File lib/hikkoshi/jekyll/post.rb, line 66
def cast_metadata
  @original_metadata.each_pair do |name, value|
    if self.respond_to?(:"#{name}=")
      self.send(:"#{name}=", value)
    else
      STDERR.puts "Unknown property: #{name}"
    end
  end
end
load_file(filename) click to toggle source
# File lib/hikkoshi/jekyll/post.rb, line 52
def load_file(filename)
  fulltext = File.read(filename)

  # Hexo does not insert "---" at the first line.
  # This hack is to unify the formats of all the files
  fulltext.sub!(/^#{SEPARATOR}/, '')

  raw_metadata, content = fulltext.split(SEPARATOR, 2)

  metadata = OpenStruct.new(YAML.load(raw_metadata))

  return [metadata, content]
end
post_process() click to toggle source
# File lib/hikkoshi/jekyll/post.rb, line 76
def post_process
  post_process_slug
  post_process_time
end
post_process_slug() click to toggle source
# File lib/hikkoshi/jekyll/post.rb, line 81
def post_process_slug
  if @slug.nil? || @slug.blank?
    @slug = slug_from_filename(@filename) or slug_from_title(@title)
  end
end
post_process_time() click to toggle source
# File lib/hikkoshi/jekyll/post.rb, line 87
def post_process_time
  @published_at ||= date_from_filename(@filename)

  # default values for created / updated
  @created_at ||= @published_at
  @updated_at ||= @published_at
end