Module: Middleman::CoreExtensions::Routing
- Included in:
- Application
- Defined in:
- lib/middleman-core/core_extensions/routing.rb
Instance Method Summary collapse
-
#page(url, opts = {}, &block) ⇒ void
The page method allows the layout to be set on a specific path.
-
#with_layout(layout_name, &block) ⇒ void
Takes a block which allows many pages to have the same layout.
Instance Method Details
#page(url, opts = {}, &block) ⇒ void
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
31 32 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 59 60 61 62 63 64 65 66 67 |
# File 'lib/middleman-core/core_extensions/routing.rb', line 31 def page(url, opts={}, &block) blocks = Array(block) # Default layout opts[:layout] = config[: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 |_| { :options => opts, :blocks => blocks } end return end # Normalized path url = '/' + Middleman::Util.normalize_path(url) if url.end_with?('/') || File.directory?(File.join(source_dir, url)) url = File.join(url, config[:index_file]) end # Setup proxy if target = opts.delete(:proxy) # TODO: deprecate proxy through page? proxy(url, target, opts, &block) and return elsif opts.delete(:ignore) # TODO: deprecate ignore through page? ignore(url) end # Setup a metadata matcher for rendering those options sitemap.(url) do |_| { :options => opts, :blocks => blocks } end end |
#with_layout(layout_name, &block) ⇒ void
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
14 15 16 17 18 19 20 21 |
# File 'lib/middleman-core/core_extensions/routing.rb', line 14 def with_layout(layout_name, &block) old_layout = config[:layout] config[:layout] = layout_name instance_exec(&block) if block_given? ensure config[:layout] = old_layout end |