Class: Middleman::BlogExtension

Inherits:
Extension
  • Object
show all
Defined in:
lib/middleman-blog/extension.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options_hash = {}, &block) ⇒ BlogExtension

Returns a new instance of BlogExtension.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/middleman-blog/extension.rb', line 57

def initialize(app, options_hash={}, &block)
  super

  @custom_pages = {}

  # NAME is the name of this particular blog, and how you reference it from #blog_controller or frontmatter.
  @name = options.name.to_sym if options.name

  # Allow one setting to set all the calendar templates
  if options.calendar_template
    options.year_template  ||= options.calendar_template
    options.month_template ||= options.calendar_template
    options.day_template   ||= options.calendar_template
  end

  # If "prefix" option is specified, all other paths are relative to it.
  if options.prefix
    options.prefix = "/#{options.prefix}" unless options.prefix.start_with? '/'
    options.permalink = File.join(options.prefix, options.permalink)
    options.sources = File.join(options.prefix, options.sources)
    options.taglink = File.join(options.prefix, options.taglink)
    options.year_link = File.join(options.prefix, options.year_link)
    options.month_link = File.join(options.prefix, options.month_link)
    options.day_link = File.join(options.prefix, options.day_link)

    options.custom_collections.each do |key, opts|
      opts[:link] = File.join(options.prefix, opts[:link])
    end
  end
end

Instance Attribute Details

#calendar_pagesCalendarPages (readonly)

Returns calendar page handler for this blog.

Returns:

  • (CalendarPages)

    calendar page handler for this blog



46
47
48
# File 'lib/middleman-blog/extension.rb', line 46

def calendar_pages
  @calendar_pages
end

#custom_pagesHash<CustomPages> (readonly)

Returns custom pages handlers for this blog, indexed by property name.

Returns:

  • (Hash<CustomPages>)

    custom pages handlers for this blog, indexed by property name



52
53
54
# File 'lib/middleman-blog/extension.rb', line 52

def custom_pages
  @custom_pages
end

#dataBlogData (readonly)

Returns blog data for this blog, which has all information about the blog articles.

Returns:

  • (BlogData)

    blog data for this blog, which has all information about the blog articles



37
38
39
# File 'lib/middleman-blog/extension.rb', line 37

def data
  @data
end

#nameSymbol (readonly)

Returns the name of this blog (autogenerated if not provided).

Returns:

  • (Symbol)

    the name of this blog (autogenerated if not provided).



40
41
42
# File 'lib/middleman-blog/extension.rb', line 40

def name
  @name
end

#paginatorPaginator (readonly)

Returns pagination handler for this blog.

Returns:

  • (Paginator)

    pagination handler for this blog



49
50
51
# File 'lib/middleman-blog/extension.rb', line 49

def paginator
  @paginator
end

#tag_pagesTagPages (readonly)

Returns tag page handler for this blog.

Returns:

  • (TagPages)

    tag page handler for this blog



43
44
45
# File 'lib/middleman-blog/extension.rb', line 43

def tag_pages
  @tag_pages
end

Instance Method Details

#after_configurationObject



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
134
135
136
137
138
139
140
141
# File 'lib/middleman-blog/extension.rb', line 88

def after_configuration
  @name ||= :"blog#{@app.blog_instances.keys.length}"

  # TODO: break up into private methods?

  @app.ignore(options.calendar_template) if options.calendar_template
  @app.ignore(options.year_template) if options.year_template
  @app.ignore(options.month_template) if options.month_template
  @app.ignore(options.day_template) if options.day_template
  @app.ignore options.tag_template if options.tag_template

  @app.blog_instances[@name] = 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 || 'UTC'
  zone_default = Time.find_zone!(time_zone)
  unless zone_default
    raise 'Value assigned to time_zone not recognized.'
  end
  Time.zone_default = zone_default

  # Initialize blog with options
  @data = Blog::BlogData.new(@app, self, options)

  @app.sitemap.register_resource_list_manipulator(:"blog_#{name}_articles", @data, false)

  if options.tag_template
    @app.ignore options.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, false)
  end

  if options.year_template || options.month_template || options.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, false)
  end

  if options.paginate
    require 'middleman-blog/paginator'
    @paginator = Blog::Paginator.new(@app, self)
    @app.sitemap.register_resource_list_manipulator(:"blog_#{name}_paginate", @paginator, false)
  end

  if options.custom_collections
    require 'middleman-blog/custom_pages'
    register_custom_pages
  end
end