Module: Middleman::CoreExtensions::Routing::InstanceMethods

Defined in:
middleman-core/lib/middleman-core/core_extensions/routing.rb

Overview

Routing instance methods

Instance Method Summary (collapse)

Instance Method Details

- (void) page(url, opts = {}, &block)

This method returns an undefined value.

The page method allows the layout to be set on a specific path

page "/about.html", :layout => false
page "/", :layout => :homepage_layout

Parameters:

  • url (String)
  • opts (Hash) (defaults to: {})


47
48
49
50
51
52
53
54
55
56
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
87
88
# File 'middleman-core/lib/middleman-core/core_extensions/routing.rb', line 47

def page(url, opts={}, &block)
  a_block = block_given? ? block : nil
      
  # Default layout
  opts[:layout] = layout if opts[:layout].nil?

  # If the url is a regexp
  if url.is_a?(Regexp) || url.include?("*")

    # Use the metadata loop for matching against paths at runtime
    sitemap. url do |url|
      { :options => opts, :blocks => [a_block] }
    end

    return
  end
      
  # Normalized path
  url = full_path(url)

  # Setup proxy
  if opts.has_key?(:proxy)
    proxy(url, opts[:proxy])

    if opts.has_key?(:ignore) && opts[:ignore]
      ignore(opts[:proxy])
      opts.delete(:ignore)
    end  

    opts.delete(:proxy)
  else
    if opts.has_key?(:ignore) && opts[:ignore]
      ignore(url)
      opts.delete(:ignore)
    end
  end
      
  # Setup a metadata matcher for rendering those options
  sitemap. url do |url|
    { :options => opts, :blocks => [a_block] }
  end
end

- (void) with_layout(layout_name, &block)

This method returns an undefined value.

Takes a block which allows many pages to have the same layout

with_layout :admin do
  page "/admin/"
  page "/admin/login.html"
end

Parameters:

  • layout_name (String, Symbol)


30
31
32
33
34
35
36
37
# File 'middleman-core/lib/middleman-core/core_extensions/routing.rb', line 30

def with_layout(layout_name, &block)
  old_layout = layout
    
  set :layout, layout_name
  instance_exec(&block) if block_given?
ensure
  set :layout, old_layout
end