Class: Middleman::MetaPages::Application

Inherits:
Object
  • Object
show all
Defined in:
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 '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 'lib/middleman-core/meta_pages.rb', line 38

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

#config(env) ⇒ Object

Inspect configuration



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/middleman-core/meta_pages.rb', line 61

def config(env)
  global_config = @middleman.inst.config.all_settings.map {|c| ConfigSetting.new(c) }
  extension_config = Hash[@middleman.inst.extensions.map do |ext_name, extension|
                            opts = if extension.is_a?(::Middleman::Extension)
                                     extension.options.all_settings.map {|c| ConfigSetting.new(c) }
                                   else 
                                     nil
                                   end
                            [ext_name, opts]
                          end]

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

#index(env) ⇒ Object

The index page



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

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

#sitemap(env) ⇒ Object

Inspect the sitemap



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

def sitemap(env)
  resources = @middleman.inst.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