class Middleman::Blog::Drafts::Data

A store of all the draft articles in the site. Accessed via {blog.drafts} in templates.

Attributes

options[R]

The configured options for this blog @return [Thor::CoreExt::HashWithIndifferentAccess]

source_template[R]

A URITemplate for the source file path relative to blog's :source_dir @return [URITemplate]

Public Class Methods

new(blog_data, app, options) click to toggle source

@private

# File lib/middleman-blog-drafts/blog_data_extensions.rb, line 40
def initialize(blog_data, app, options)
  @blog_data = blog_data
  @app       = app
  @options   = options

  # A list of resources corresponding to draft articles
  @_drafts = []

  @source_template = uri_template options.sources
  @permalink_template = uri_template options.permalink
end

Public Instance Methods

articles() click to toggle source

A list of all draft articles. @return [Array<Middleman::Sitemap::Resource>]

# File lib/middleman-blog-drafts/blog_data_extensions.rb, line 54
def articles
  @_drafts.sort_by(&:title)
end
build?(draft) click to toggle source

Whether or not a given draft should be included in the sitemap. @param [DraftArticle] draft A draft article @return [Boolean] Whether it should be built

# File lib/middleman-blog-drafts/blog_data_extensions.rb, line 85
def build?(draft)
  build = draft.data["build"]
  build = @options.build if build == nil
  @app.environment == :development || build
end
manipulate_resource_list(resources) click to toggle source

Update blog draft articles destination paths to be the permalink. @return [void]

# File lib/middleman-blog-drafts/blog_data_extensions.rb, line 60
def manipulate_resource_list(resources)
  @_drafts = []
  used_resources = []

  resources.each do |resource|
    if (params = extract_params(@source_template, resource.path))
      draft = convert_to_draft(resource)
      next unless build?(draft)

      # compute output path
      draft.destination_path =
        apply_uri_template @permalink_template, title: draft.slug

      @_drafts << resource
    end

    used_resources << resource
  end

  used_resources
end

Private Instance Methods

convert_to_draft(resource) click to toggle source

Convert the resource into a DraftArticle. @param [Sitemap::Resource] resource The resource to convert @return [Sitemap::Resource] The converted resource

# File lib/middleman-blog-drafts/blog_data_extensions.rb, line 96
def convert_to_draft(resource)
  return resource if resource.is_a? DraftArticle

  resource.extend BlogArticle
  resource.extend DraftArticle
  resource.blog_controller = @blog_data.controller

  resource
end