Class: Middleman::Blog::CustomPages
- Inherits:
-
Object
- Object
- Middleman::Blog::CustomPages
- Defined in:
- lib/middleman-blog/custom_pages.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#blog_controller ⇒ Object
readonly
Returns the value of attribute blog_controller.
-
#property ⇒ Object
readonly
Returns the value of attribute property.
Class Method Summary collapse
-
.link(blog_options, property, value) ⇒ Object
Return a path to the given property / value pair.
Instance Method Summary collapse
- #articles ⇒ Object
- #blog_data ⇒ Object
- #blog_options ⇒ Object
- #build_resource(path, value, property_articles) ⇒ Object
-
#initialize(property, app, controller = nil) ⇒ CustomPages
constructor
A new instance of CustomPages.
- #manipulate_resource_list(resources) ⇒ Object
- #template_for_page ⇒ Object
Constructor Details
#initialize(property, app, controller = nil) ⇒ CustomPages
Returns a new instance of CustomPages.
22 23 24 25 26 |
# File 'lib/middleman-blog/custom_pages.rb', line 22 def initialize(property, app, controller = nil) @property = property @app = app @blog_controller = controller end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
20 21 22 |
# File 'lib/middleman-blog/custom_pages.rb', line 20 def app @app end |
#blog_controller ⇒ Object (readonly)
Returns the value of attribute blog_controller.
20 21 22 |
# File 'lib/middleman-blog/custom_pages.rb', line 20 def blog_controller @blog_controller end |
#property ⇒ Object (readonly)
Returns the value of attribute property.
20 21 22 |
# File 'lib/middleman-blog/custom_pages.rb', line 20 def property @property end |
Class Method Details
.link(blog_options, property, value) ⇒ Object
Return a path to the given property / value pair
13 14 15 16 |
# File 'lib/middleman-blog/custom_pages.rb', line 13 def link(, property, value) link_template = .custom_collections[property][:link] ::Middleman::Util.normalize_path(link_template.sub(":#{property}", value.parameterize)) end |
Instance Method Details
#articles ⇒ Object
44 45 46 |
# File 'lib/middleman-blog/custom_pages.rb', line 44 def articles blog_data.articles end |
#blog_data ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/middleman-blog/custom_pages.rb', line 28 def blog_data if blog_controller blog_controller.data else app.blog end end |
#blog_options ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/middleman-blog/custom_pages.rb', line 36 def if blog_controller blog_controller. else app.blog. end end |
#build_resource(path, value, property_articles) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/middleman-blog/custom_pages.rb', line 59 def build_resource(path, value, property_articles) p = ::Middleman::Sitemap::Resource.new(app.sitemap, path) p.proxy_to(template_for_page) p. :locals => { "page_type" => property, "#{property}" => value, "articles" => property_articles, "blog_controller" => blog_controller } prop_name = property p. do instance_variable_set("@#{prop_name}", value) @articles = property_articles end p end |
#manipulate_resource_list(resources) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/middleman-blog/custom_pages.rb', line 48 def manipulate_resource_list(resources) new_resources = [] articles.group_by { |a| a.data[property] }.each do |property_value, property_articles| path = CustomPages.link(, property, property_value) new_resources << build_resource(path, property_value, property_articles) end resources + new_resources end |
#template_for_page ⇒ Object
78 79 80 |
# File 'lib/middleman-blog/custom_pages.rb', line 78 def template_for_page .custom_collections[property][:template] end |