module Middleman::BlogPage::BlogPageArticle

A module that adds blog_page-article methods to Resources.

Public Class Methods

extended(base) click to toggle source
# File lib/middleman-blog_page/blog_page_article.rb, line 8
def self.extended(base)
  base.class.send(:attr_accessor, :blog_page_controller)
end

Public Instance Methods

blog_options() click to toggle source
# File lib/middleman-blog_page/blog_page_article.rb, line 20
def blog_options
  if self.blog_page_controller
    self.blog_page_controller.options
  else
    app.blog_page.options
  end
end
blog_page_data() click to toggle source
# File lib/middleman-blog_page/blog_page_article.rb, line 12
def blog_page_data
  if self.blog_page_controller
    self.blog_page_controller.data
  else
    app.blog_page
  end
end
body() click to toggle source

The body of this article, in HTML. This is for things like RSS feeds or lists of articles - individual articles will automatically be rendered from their template. @return [String]

# File lib/middleman-blog_page/blog_page_article.rb, line 65
def body
  render(:layout => false)
end
inspect() click to toggle source
# File lib/middleman-blog_page/blog_page_article.rb, line 97
def inspect
  "#<Middleman::BlogPage::BlogPageArticle: #{data.inspect}>"
end
path_part(part) click to toggle source

Retrieve a section of the source path @param [String] The part of the path, e.g. “year”, “month”, “day”, “title” @return [String]

# File lib/middleman-blog_page/blog_page_article.rb, line 72
def path_part(part)
  @_path_parts ||= blog_page_data.path_matcher.match(path).captures
  @_path_parts[blog_page_data.matcher_indexes[part]]
end
priority() click to toggle source

The “priority” of the article make how order articles @return [Integer]

# File lib/middleman-blog_page/blog_page_article.rb, line 93
def priority
  @_priority ||= data["priority"].to_i
end
published?() click to toggle source

Whether or not this article has been published

An article is considered published in the following scenarios:

  1. frontmatter does not set published to false and either

  2. published_future_dated is true or

  3. article date is after the current time

@return [Boolean]

# File lib/middleman-blog_page/blog_page_article.rb, line 56
def published?
  data["published"] != false
end
render(opts={}, locs={}, &block) click to toggle source

Render this resource @return [String]

Calls superclass method
# File lib/middleman-blog_page/blog_page_article.rb, line 30
def render(opts={}, locs={}, &block)
  if opts[:layout].nil?
    if metadata[:options] && !metadata[:options][:layout].nil?
      opts[:layout] = metadata[:options][:layout]
    end
    opts[:layout] = blog_options.layout if opts[:layout].nil?
    opts[:layout] = opts[:layout].to_s if opts[:layout].is_a? Symbol
  end

  super(opts, locs, &block)
end
slug() click to toggle source

The “slug” of the article that shows up in its URL. @return [String]

# File lib/middleman-blog_page/blog_page_article.rb, line 79
def slug
  @_slug ||= data["slug"]

  @_slug ||= if blog_options.sources.include?(":title")
    path_part("title")
  elsif title
    title.parameterize
  else
    raise "Can't generate a slug for #{path} because it has no :title in its path pattern or title/slug in its frontmatter."
  end
end
title() click to toggle source

The title of the article, set from frontmatter @return [String]

# File lib/middleman-blog_page/blog_page_article.rb, line 44
def title
  data["title"]
end