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

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

Instance Method Summary collapse

Instance Method Details

#dataThor::CoreExt::HashWithIndifferentAccess

Extends resource data adding the date field

Returns:

  • (Thor::CoreExt::HashWithIndifferentAccess)


32
33
34
# File 'lib/middleman-blog-drafts/draft_article.rb', line 32

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)


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

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)


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

def path_part(part)
  @_path_parts ||= app.blog.drafts.path_matcher.match(path).captures

  @_path_parts[app.blog.drafts.matcher_indexes[part]]
end

#slugString

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

Returns:

  • (String)


7
8
9
# File 'lib/middleman-blog-drafts/draft_article.rb', line 7

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