Class: Middleman::BlogExtension
- Inherits:
-
Extension
- Object
- Extension
- Middleman::BlogExtension
- Defined in:
- lib/middleman-blog/extension_3_1.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#uid ⇒ Object
Returns the value of attribute uid.
Instance Method Summary collapse
- #after_configuration ⇒ Object
-
#generate_custom_helper(custom_property) ⇒ Object
Generate helpers to access the path to a custom collection.
-
#initialize(app, options_hash = {}, &block) ⇒ BlogExtension
constructor
A new instance of BlogExtension.
-
#register_custom_pages ⇒ Object
Register any custom page collections that may be set in the config.
Constructor Details
#initialize(app, options_hash = {}, &block) ⇒ BlogExtension
Returns a new instance of BlogExtension.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/middleman-blog/extension_3_1.rb', line 31 def initialize(app, ={}, &block) super @uid = .name require 'middleman-blog/blog_data' require 'middleman-blog/blog_article' require 'active_support/core_ext/time/zones' # app.set :time_zone, 'UTC' # optional: :tag_template # optional: :year_template # optional: :month_template # optional: :day_template # Allow one setting to set all the calendar templates if .calendar_template .year_template ||= .calendar_template .month_template ||= .calendar_template .day_template ||= .calendar_template end # If "prefix" option is specified, all other paths are relative to it. if .prefix .prefix = "/#{.prefix}" unless .prefix.start_with? '/' .permalink = File.join(.prefix, .permalink) .sources = File.join(.prefix, .sources) .taglink = File.join(.prefix, .taglink) .year_link = File.join(.prefix, .year_link) .month_link = File.join(.prefix, .month_link) .day_link = File.join(.prefix, .day_link) .custom_collections.each do |key, opts| opts[:link] = File.join(.prefix, opts[:link]) end end end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
29 30 31 |
# File 'lib/middleman-blog/extension_3_1.rb', line 29 def data @data end |
#uid ⇒ Object
Returns the value of attribute uid.
29 30 31 |
# File 'lib/middleman-blog/extension_3_1.rb', line 29 def uid @uid end |
Instance Method Details
#after_configuration ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/middleman-blog/extension_3_1.rb', line 69 def after_configuration @uid ||= "blog#{@app.blog_instances.keys.length}" @app.ignore(.calendar_template) if .calendar_template @app.ignore(.year_template) if .year_template @app.ignore(.month_template) if .month_template @app.ignore(.day_template) if .day_template @app.blog_instances[@uid.to_sym] = self # Make sure ActiveSupport's TimeZone stuff has something to work with, # allowing people to set their desired time zone via Time.zone or # set :time_zone Time.zone = app.config[:time_zone] if app.config[:time_zone] time_zone = Time.zone if Time.zone zone_default = Time.find_zone!(time_zone || 'UTC') unless zone_default raise 'Value assigned to time_zone not recognized.' end Time.zone_default = zone_default # Initialize blog with options @data = ::Middleman::Blog::BlogData.new(@app, , self) @app.sitemap.register_resource_list_manipulator( :"blog_#{uid}_articles", @data, false ) if .tag_template @app.ignore .tag_template require 'middleman-blog/tag_pages' @app.sitemap.register_resource_list_manipulator( :"blog_#{uid}_tags", ::Middleman::Blog::TagPages.new(@app, self), false ) end if .year_template || .month_template || .day_template require 'middleman-blog/calendar_pages' @app.sitemap.register_resource_list_manipulator( :"blog_#{uid}_calendar", ::Middleman::Blog::CalendarPages.new(@app, self), false ) end if .paginate require 'middleman-blog/paginator' @app.sitemap.register_resource_list_manipulator( :"blog_#{uid}_paginate", ::Middleman::Blog::Paginator.new(@app, self), false ) end if .custom_collections require 'middleman-blog/custom_pages' register_custom_pages end end |
#generate_custom_helper(custom_property) ⇒ Object
Generate helpers to access the path to a custom collection.
For example, when using a custom property called “category” to collect articles on the method category_path will be generated.
171 172 173 174 175 176 177 178 179 180 |
# File 'lib/middleman-blog/extension_3_1.rb', line 171 def generate_custom_helper(custom_property) m = Module.new m.module_eval(%Q{ def #{custom_property}_path(value, key = nil) sitemap.find_resource_by_path(::Middleman::Blog::CustomPages.link(blog_controller(key).options, :#{custom_property}, value)).try(:url) end }) app.class.send(:include, m) end |
#register_custom_pages ⇒ Object
Register any custom page collections that may be set in the config
A custom resource list manipulator will be generated for each key in the custom collections hash.
The following will collect posts on the “category” frontmatter property:
```
activate :blog do |blog|
blog.custom_collections = {
link: "/categories/:category.html",
template: "/category.html"
}
end
```
Category pages in the example above will use the category.html as a template file and it will be ignored when building.
152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/middleman-blog/extension_3_1.rb', line 152 def register_custom_pages .custom_collections.each do |property, | @app.ignore [:template] @app.sitemap.register_resource_list_manipulator( :"blog_#{uid}_#{property}", ::Middleman::Blog::CustomPages.new(property, @app, self), false ) generate_custom_helper(property) end end |