Class: Middleman::Blog::Drafts::Data

Inherits:
Object
  • Object
show all
Includes:
UriTemplates
Defined in:
lib/middleman-blog-drafts/blog_data_extensions.rb

Overview

A store of all the draft articles in the site. Accessed via blogblog.drafts in templates.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blog_data, app, options) ⇒ Data

Returns a new instance of Data.



40
41
42
43
44
45
46
47
48
49
50
# 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

Instance Attribute Details

#optionsThor::CoreExt::HashWithIndifferentAccess (readonly)

The configured options for this blog

Returns:

  • (Thor::CoreExt::HashWithIndifferentAccess)


37
38
39
# File 'lib/middleman-blog-drafts/blog_data_extensions.rb', line 37

def options
  @options
end

#source_templateURITemplate (readonly)

A URITemplate for the source file path relative to blog’s :source_dir

Returns:

  • (URITemplate)


33
34
35
# File 'lib/middleman-blog-drafts/blog_data_extensions.rb', line 33

def source_template
  @source_template
end

Instance Method Details

#articlesArray<Middleman::Sitemap::Resource>

A list of all draft articles.

Returns:

  • (Array<Middleman::Sitemap::Resource>)


54
55
56
# File 'lib/middleman-blog-drafts/blog_data_extensions.rb', line 54

def articles
  @_drafts.sort_by(&:title)
end

#build?(draft) ⇒ Boolean

Whether or not a given draft should be included in the sitemap.

Parameters:

Returns:

  • (Boolean)

    Whether it should be built



85
86
87
88
89
# 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) ⇒ void

This method returns an undefined value.

Update blog draft articles destination paths to be the permalink.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# 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