Module: Middleman::Blog::Drafts::DraftArticle

Defined in:
lib/middleman-blog-drafts/draft_article.rb

Overview

A module that adds draft-article-specific methods to Resources. A DraftArticle can be retrieved via Helpers#current_article or methods on Data (accessible through BlogData#drafts).

Instance Method Summary collapse

Instance Method Details

#dataThor::CoreExt::HashWithIndifferentAccess

Extends resource data adding the date field

Returns:

  • (Thor::CoreExt::HashWithIndifferentAccess)


42
43
44
# File 'lib/middleman-blog-drafts/draft_article.rb', line 42

def data
  super.dup.merge(date: date)
end

#dateTimeWithZone

Returns current date as we can’t guess when the article will be published We need this in place or the layout used for blog posts might blow up

Returns:

  • (TimeWithZone)


35
36
37
# File 'lib/middleman-blog-drafts/draft_article.rb', line 35

def date
  Time.now.in_time_zone
end

#path_part(part) ⇒ String

Retrieve a section of the source path

Parameters:

  • The (String)

    part of the path, e.g. “title”

Returns:

  • (String)


24
25
26
27
28
# File 'lib/middleman-blog-drafts/draft_article.rb', line 24

def path_part(part)
  normalized_path = Addressable::URI.parse(path).normalize.to_s
  @_path_parts ||= blog_data.drafts.source_template.extract(normalized_path)
  @_path_parts[part.to_s]
end

#slugString

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

Returns:

  • (String)


17
18
19
# File 'lib/middleman-blog-drafts/draft_article.rb', line 17

def slug
  @_slug ||= path_part("title")
end

#titleString

The title of the draft article, or “(UNTITLED DRAFT)” if no title was provided

Returns:

  • (String)


11
12
13
# File 'lib/middleman-blog-drafts/draft_article.rb', line 11

def title
  data["title"] || "(UNTITLED DRAFT)"
end