Class: Middleman::Blog::CustomPages

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

Overview

This adds new summary pages for arbitrarily defined blog article properties

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UriTemplates

apply_uri_template, date_to_params, extract_directory_path, extract_params, safe_parameterize, uri_template

Constructor Details

#initialize(property, app, controller, options) ⇒ CustomPages

Returns a new instance of CustomPages.



13
14
15
16
17
18
19
20
# File 'lib/middleman-blog/custom_pages.rb', line 13

def initialize(property, app, controller, options)
  @property = property
  @sitemap = app.sitemap
  @blog_controller = controller
  @blog_data = controller.data
  @link_template = uri_template options[:link]
  @page_template = options[:template]
end

Instance Attribute Details

#propertyObject (readonly)

Returns the value of attribute property.



11
12
13
# File 'lib/middleman-blog/custom_pages.rb', line 11

def property
  @property
end

Instance Method Details

Return a path to the page for this property value.

Parameters:

  • value (String)


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

def link(value)
  apply_uri_template @link_template, property => safe_parameterize(value)
end

#manipulate_resource_list(resources) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/middleman-blog/custom_pages.rb', line 29

def manipulate_resource_list(resources)
  articles_by_property = @blog_data.articles
                                   .select { |a| a.data[property] }
                                   .group_by { |a| a.data[property] }
  resources + articles_by_property.map do |property_value, articles|
    build_resource(link(property_value), property_value, articles)
  end
end