Class: Middleman::BlogPageExtension

Inherits:
Extension
  • Object
show all
Defined in:
lib/middleman-blog_page/extension_3_1.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of BlogPageExtension.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/middleman-blog_page/extension_3_1.rb', line 14

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

  @uid = options.name

  require 'middleman-blog_page/blog_page_data'
  require 'middleman-blog_page/blog_page_article'
  require 'active_support/core_ext/time/zones'

  # app.set :time_zone, 'UTC'

  # 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)
  end
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



12
13
14
# File 'lib/middleman-blog_page/extension_3_1.rb', line 12

def data
  @data
end

#uidObject

Returns the value of attribute uid.



12
13
14
# File 'lib/middleman-blog_page/extension_3_1.rb', line 12

def uid
  @uid
end

Instance Method Details

#after_configurationObject



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
# File 'lib/middleman-blog_page/extension_3_1.rb', line 33

def after_configuration
  @uid ||= "blog_page#{@app.blog_instances.keys.length}"

  @app.blog_page_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::BlogPage::BlogPageData.new(@app, options, self)

  @app.sitemap.register_resource_list_manipulator(
    :"blog_#{uid}_pages",
    @data,
    false
  )
end