Class: Middleman::BlogExtension
- Inherits:
-
Extension
- Object
- Extension
- Middleman::BlogExtension
- Extended by:
- Forwardable
- Defined in:
- lib/middleman-blog/extension.rb
Instance Attribute Summary collapse
-
#alias_pages ⇒ AliasPages
readonly
Alias page handler for this blog.
-
#calendar_pages ⇒ CalendarPages
readonly
Calendar page handler for this blog.
-
#custom_pages ⇒ Hash<CustomPages>
readonly
Custom pages handlers for this blog, indexed by property name.
-
#data ⇒ BlogData
readonly
Blog data for this blog, which has all information about the blog articles.
-
#name ⇒ Symbol
readonly
The name of this blog (autogenerated if not provided).
-
#paginator ⇒ Paginator
readonly
Pagination handler for this blog.
-
#tag_pages ⇒ TagPages
readonly
Tag page handler for this blog.
Instance Method Summary collapse
- #after_configuration ⇒ Object
-
#initialize(app, options_hash = {}, &block) ⇒ BlogExtension
constructor
A new instance of BlogExtension.
Constructor Details
#initialize(app, options_hash = {}, &block) ⇒ BlogExtension
Returns a new instance of BlogExtension.
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 |
# File 'lib/middleman-blog/extension.rb', line 74 def initialize(app, = {}, &block) super @custom_pages = {} # NAME is the name of this particular blog, and how you reference it from #blog_controller or frontmatter. @name = .name.to_sym if .name # 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. return unless .prefix .prefix = "/#{options.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_value do |opts| opts[:link] = File.join(.prefix, opts[:link]) end # Apply prefix to alias patterns if specified unless .aliases.nil? || .aliases.empty? .aliases = .aliases.map { |alias_pattern| File.join(.prefix, alias_pattern) } end end |
Instance Attribute Details
#alias_pages ⇒ AliasPages (readonly)
Returns alias page handler for this blog.
69 70 71 |
# File 'lib/middleman-blog/extension.rb', line 69 def alias_pages @alias_pages end |
#calendar_pages ⇒ CalendarPages (readonly)
Returns calendar page handler for this blog.
60 61 62 |
# File 'lib/middleman-blog/extension.rb', line 60 def calendar_pages @calendar_pages end |
#custom_pages ⇒ Hash<CustomPages> (readonly)
Returns custom pages handlers for this blog, indexed by property name.
66 67 68 |
# File 'lib/middleman-blog/extension.rb', line 66 def custom_pages @custom_pages end |
#data ⇒ BlogData (readonly)
Returns blog data for this blog, which has all information about the blog articles.
51 52 53 |
# File 'lib/middleman-blog/extension.rb', line 51 def data @data end |
#name ⇒ Symbol (readonly)
Returns the name of this blog (autogenerated if not provided).
54 55 56 |
# File 'lib/middleman-blog/extension.rb', line 54 def name @name end |
#paginator ⇒ Paginator (readonly)
Returns pagination handler for this blog.
63 64 65 |
# File 'lib/middleman-blog/extension.rb', line 63 def paginator @paginator end |
#tag_pages ⇒ TagPages (readonly)
Returns tag page handler for this blog.
57 58 59 |
# File 'lib/middleman-blog/extension.rb', line 57 def tag_pages @tag_pages end |
Instance Method Details
#after_configuration ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/middleman-blog/extension.rb', line 110 def after_configuration @name ||= begin found_name = nil app.extensions[:blog].values.each_with_index do |ext, i| found_name = "blog#{i + 1}" if ext == self end found_name end # TODO: break up into private methods? @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.ignore .tag_template if .tag_template # Receiver zone support is the only supported method in 8.1+, and the setting triggers a # deprecation warning in 8.2, so only needed on older versions. if ActiveSupport.version < Gem::Version.new('8.1') ActiveSupport.to_time_preserves_timezone = :zone end # 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 || 'UTC' zone_default = Time.find_zone!(time_zone) raise 'Value assigned to time_zone not recognized.' unless zone_default Time.zone_default = zone_default # Initialize blog with options @data = Blog::BlogData.new(@app, self, ) @app.sitemap.register_resource_list_manipulator(:"blog_#{name}_articles", @data) if .tag_template @app.ignore .tag_template require 'middleman-blog/tag_pages' @tag_pages = Blog::TagPages.new(@app, self) @app.sitemap.register_resource_list_manipulator(:"blog_#{name}_tags", @tag_pages) end if .year_template || .month_template || .day_template require 'middleman-blog/calendar_pages' @calendar_pages = Blog::CalendarPages.new(@app, self) @app.sitemap.register_resource_list_manipulator(:"blog_#{name}_calendar", @calendar_pages) end if .custom_collections require 'middleman-blog/custom_pages' register_custom_pages end if .paginate require 'middleman-blog/paginator' @paginator = Blog::Paginator.new(@app, self) @app.sitemap.register_resource_list_manipulator(:"blog_#{name}_paginate", @paginator) end unless .aliases.nil? || .aliases.empty? require 'middleman-blog/alias_pages' @alias_pages = Blog::AliasPages.new(@app, self) @app.sitemap.register_resource_list_manipulator(:"blog_#{name}_aliases", @alias_pages) end logger.info "== Blog Sources: #{options.sources} (:prefix + :sources)" end |