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



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

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



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

def property
  @property
end

Instance Method Details

Return a path to the page for this property value.

Parameters:

  • value (String)


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

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

#manipulate_resource_list(resources) ⇒ Object



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

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