Class: Middleman::Blog::CustomPages
- Inherits:
-
Object
- Object
- Middleman::Blog::CustomPages
- 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
-
#property ⇒ Object
readonly
Returns the value of attribute property.
Instance Method Summary collapse
-
#initialize(property, app, controller, options) ⇒ CustomPages
constructor
A new instance of CustomPages.
-
#link(value) ⇒ Object
Return a path to the page for this property value.
- #manipulate_resource_list(resources) ⇒ Object
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, ) @property = property @sitemap = app.sitemap @blog_controller = controller @blog_data = controller.data @link_template = uri_template [:link] @page_template = [:template] end |
Instance Attribute Details
#property ⇒ Object (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
#link(value) ⇒ Object
Return a path to the page for this property value.
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 |