Module: Middleman::BlogPage::BlogPageArticle

Defined in:
lib/middleman-blog_page/blog_page_article.rb

Overview

A module that adds blog_page-article methods to Resources.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



8
9
10
# File 'lib/middleman-blog_page/blog_page_article.rb', line 8

def self.extended(base)
  base.class.send(:attr_accessor, :blog_page_controller)
end

Instance Method Details

#blog_optionsObject



20
21
22
23
24
25
26
# 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_dataObject



12
13
14
15
16
17
18
# 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

#bodyString

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.

Returns:

  • (String)


65
66
67
# File 'lib/middleman-blog_page/blog_page_article.rb', line 65

def body
  render(:layout => false)
end

#inspectObject



97
98
99
# File 'lib/middleman-blog_page/blog_page_article.rb', line 97

def inspect
  "#<Middleman::BlogPage::BlogPageArticle: #{data.inspect}>"
end

#path_part(part) ⇒ String

Retrieve a section of the source path

Parameters:

  • The (String)

    part of the path, e.g. “year”, “month”, “day”, “title”

Returns:

  • (String)


72
73
74
75
# 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

#priorityInteger

The “priority” of the article make how order articles

Returns:

  • (Integer)


93
94
95
# File 'lib/middleman-blog_page/blog_page_article.rb', line 93

def priority
  @_priority ||= data["priority"].to_i
end

#published?Boolean

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

Returns:

  • (Boolean)


56
57
58
# File 'lib/middleman-blog_page/blog_page_article.rb', line 56

def published?
  data["published"] != false
end

#render(opts = {}, locs = {}, &block) ⇒ String

Render this resource

Returns:

  • (String)


30
31
32
33
34
35
36
37
38
39
40
# File 'lib/middleman-blog_page/blog_page_article.rb', line 30

def render(opts={}, locs={}, &block)
  if opts[:layout].nil?
    if [:options] && ![:options][:layout].nil?
      opts[:layout] = [: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

#slugString

The “slug” of the article that shows up in its URL.

Returns:

  • (String)


79
80
81
82
83
84
85
86
87
88
89
# 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

#titleString

The title of the article, set from frontmatter

Returns:

  • (String)


44
45
46
# File 'lib/middleman-blog_page/blog_page_article.rb', line 44

def title
  data["title"]
end