Class: Middleman::Blog::Drafts::Data
- Inherits:
-
Object
- Object
- Middleman::Blog::Drafts::Data
- 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
-
#options ⇒ Thor::CoreExt::HashWithIndifferentAccess
readonly
The configured options for this blog.
-
#source_template ⇒ URITemplate
readonly
A URITemplate for the source file path relative to blog’s :source_dir.
Instance Method Summary collapse
-
#articles ⇒ Array<Middleman::Sitemap::Resource>
A list of all draft articles.
-
#build?(draft) ⇒ Boolean
Whether or not a given draft should be included in the sitemap.
-
#initialize(blog_data, app, options) ⇒ Data
constructor
A new instance of Data.
-
#manipulate_resource_list(resources) ⇒ void
Update blog draft articles destination paths to be the permalink.
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, ) @blog_data = blog_data @app = app @options = # A list of resources corresponding to draft articles @_drafts = [] @source_template = uri_template .sources @permalink_template = uri_template .permalink end |
Instance Attribute Details
#options ⇒ Thor::CoreExt::HashWithIndifferentAccess (readonly)
The configured options for this blog
37 38 39 |
# File 'lib/middleman-blog-drafts/blog_data_extensions.rb', line 37 def @options end |
#source_template ⇒ URITemplate (readonly)
A URITemplate for the source file path relative to blog’s :source_dir
33 34 35 |
# File 'lib/middleman-blog-drafts/blog_data_extensions.rb', line 33 def source_template @source_template end |
Instance Method Details
#articles ⇒ Array<Middleman::Sitemap::Resource>
A list of all draft articles.
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.
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 |