Class: Post

Inherits:
MdContent show all
Defined in:
lib/post.rb

Constant Summary collapse

@@glob =
"*.{md,mkd,markdown}"

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MdContent

#date, matcher, #raw_content

Methods inherited from Content

#account, #account?, #child, #content, #datas, #dir, #gravatar, #gravatar?, #method_missing, #raw_content, #url=

Methods included from Configuration

#config, config, #defaultLinks, defaultLinks, links_file_path, read_config, read_configuration, read_default_links, valid_location?

Constructor Details

#initialize(file_path) ⇒ Post

Returns a new instance of Post.



7
8
9
10
11
12
13
# File 'lib/post.rb', line 7

def initialize file_path
  super file_path

  base_path = File.join(Configuration.config['path'], '_posts') + '/'
  @cats = @cats.gsub(base_path, '') if !@cats.nil?
  @cats.chomp!('/')
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Content

Class Method Details

.allObject



29
30
31
# File 'lib/post.rb', line 29

def all
  post_files.inject([]) { |posts, file| posts << Post.new(file) }
end

Instance Method Details

#urlObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/post.rb', line 15

def url
  generate_url = {
    "year"  => @date.strftime("%Y"),
    "month" => @date.strftime("%m"),
    "day"   => @date.strftime("%d"),
    "title" => CGI.escape(@slug)
  }.inject(":year/:month/:day/:title.html") { |result, token|
    result.gsub(/:#{Regexp.escape token.first}/, token.last)
  }.gsub(/\/\//, "/")
  generate_url = "#{@cats}/#{generate_url}" if @cats != ''
  generate_url
end