Class: Middleman::Blog::Drafts::Data
- Inherits:
-
Object
- Object
- Middleman::Blog::Drafts::Data
- Defined in:
- lib/middleman-blog-drafts/blog_data_extensions.rb
Overview
A store of all the draft articles in the site. Accessed via “blog.drafts” in templates.
Instance Attribute Summary collapse
-
#matcher_indexes ⇒ Object
readonly
Returns the value of attribute matcher_indexes.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path_matcher ⇒ Object
readonly
Returns the value of attribute path_matcher.
Instance Method Summary collapse
-
#articles ⇒ Array<Middleman::Sitemap::Resource>
A list of all draft articles.
-
#initialize(blog_data, app, options) ⇒ Data
constructor
A new instance of Data.
-
#manipulate_resource_list(resources) ⇒ void
Updates’ blog draft articles destination paths to be the permalink.
Constructor Details
#initialize(blog_data, app, options) ⇒ Data
Returns a new instance of Data.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/middleman-blog-drafts/blog_data_extensions.rb', line 29 def initialize(blog_data, app, ) @blog_data = blog_data @options = @app = app # A list of resources corresponding to draft articles @_drafts = [] matcher = Regexp.escape(.sources). sub(/^\//, ""). sub(":title", "([^/]+)") @path_matcher = /^#{matcher}/ # Build a hash of part name to capture index, e.g. {"year" => 0} @matcher_indexes = {} .sources.scan(/:title/). each_with_index do |key, i| @matcher_indexes[key[1..-1]] = i end # The path always appears at the end. @matcher_indexes["path"] = @matcher_indexes.size end |
Instance Attribute Details
#matcher_indexes ⇒ Object (readonly)
Returns the value of attribute matcher_indexes.
26 27 28 |
# File 'lib/middleman-blog-drafts/blog_data_extensions.rb', line 26 def matcher_indexes @matcher_indexes end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
26 27 28 |
# File 'lib/middleman-blog-drafts/blog_data_extensions.rb', line 26 def @options end |
#path_matcher ⇒ Object (readonly)
Returns the value of attribute path_matcher.
26 27 28 |
# File 'lib/middleman-blog-drafts/blog_data_extensions.rb', line 26 def path_matcher @path_matcher end |
Instance Method Details
#articles ⇒ Array<Middleman::Sitemap::Resource>
A list of all draft articles.
84 85 86 |
# File 'lib/middleman-blog-drafts/blog_data_extensions.rb', line 84 def articles @_drafts end |
#manipulate_resource_list(resources) ⇒ void
This method returns an undefined value.
Updates’ blog draft articles destination paths to be the permalink.
56 57 58 59 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 56 def manipulate_resource_list(resources) @_drafts = [] used_resources = [] resources.each do |resource| if resource.path =~ @path_matcher resource.extend BlogArticle resource.extend DraftArticle next unless @app.environment == :development || @options.build # compute output path: resource.destination_path = .permalink. sub(':title', resource.slug) resource.destination_path = Middleman::Util.normalize_path(resource.destination_path) @_drafts << resource end used_resources << resource end used_resources end |