Class: Middleman::MetaPages::Application

Inherits:
Object
  • Object
show all
Defined in:
middleman-core/lib/middleman-core/meta_pages.rb

Overview

Metadata pages to be served in preview, in order to present information about the Middleman application and its configuration. Analogous to Firefox/Chrome's "about:" pages.

Built using a ghetto little Rack web framework cobbled together because I didn't want to depend on Sinatra or figure out how to host Middleman inside Middleman.

Instance Method Summary collapse

Constructor Details

#initialize(middleman) ⇒ Application

Returns a new instance of Application.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'middleman-core/lib/middleman-core/meta_pages.rb', line 15

def initialize(middleman)
  # Hold a reference to the middleman application
  @middleman = middleman

  meta_pages = self
  @rack_app = ::Rack::Builder.new do
    # Serve assets from metadata/assets
    use ::Rack::Static, urls: ['/assets'], root: File.join(File.dirname(__FILE__), 'meta_pages')

    map '/' do
      run meta_pages.method(:index)
    end

    map '/sitemap' do
      run meta_pages.method(:sitemap)
    end

    map '/config' do
      run meta_pages.method(:config)
    end
  end
end

Instance Method Details

#call(*args) ⇒ Object



38
39
40
# File 'middleman-core/lib/middleman-core/meta_pages.rb', line 38

def call(*args)
  @rack_app.call(*args)
end

#config(_) ⇒ Object

Inspect configuration



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
87
88
89
90
91
# File 'middleman-core/lib/middleman-core/meta_pages.rb', line 61

def config(_)
  global_config = @middleman.config.all_settings.map { |c| ConfigSetting.new(c) }
  extension_config = {}
  auto_activated_config = {}

  @middleman.extensions.each do |ext_name, extension|
    if ::Middleman::Extensions.auto_activated.include? ext_name
      auto_activated_config[ext_name] = extension_options(extension)
      next
    end

    if extension.is_a?(Hash)
      # Multiple instance extension
      if extension.size == 1
        extension_config[ext_name] = extension_options(extension.values.first)
      else
        extension.each do |inst, ext|
          extension_config["#{ext_name} (#{inst})"] = extension_options(ext)
        end
      end
    else
      extension_config[ext_name] = extension_options(extension)
    end
  end

  template('config.html.erb',
           global_config: global_config,
           extension_config: extension_config,
           auto_activated_config: auto_activated_config,
           registered_extensions: Middleman::Extensions.registered.dup)
end

#index(_) ⇒ Object

The index page



43
44
45
# File 'middleman-core/lib/middleman-core/meta_pages.rb', line 43

def index(_)
  template('index.html.erb')
end

#sitemap(_) ⇒ Object

Inspect the sitemap



48
49
50
51
52
53
54
55
56
57
58
# File 'middleman-core/lib/middleman-core/meta_pages.rb', line 48

def sitemap(_)
  resources = @middleman.sitemap.resources(true)

  sitemap_tree = SitemapTree.new

  resources.each do |resource|
    sitemap_tree.add_resource resource
  end

  template('sitemap.html.erb', sitemap_tree: sitemap_tree)
end