module Middleman::BlogPage::BlogPageArticle
A module that adds blog_page-article methods to Resources.
Public Class Methods
# 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
# 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
# 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
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
# File lib/middleman-blog_page/blog_page_article.rb, line 97 def inspect "#<Middleman::BlogPage::BlogPageArticle: #{data.inspect}>" end
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
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
Whether or not this article has been published
An article is considered published in the following scenarios:
-
frontmatter does not set published to false and either
-
published_future_dated is true or
-
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 this resource @return [String]
# 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
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
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