Class: Middleman::CoreExtensions::Routing::PageDescriptor

Inherits:
Struct
  • Object
show all
Defined in:
middleman-core/lib/middleman-core/core_extensions/routing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#localsObject

Returns the value of attribute locals

Returns:

  • (Object)

    the current value of locals


14
15
16
# File 'middleman-core/lib/middleman-core/core_extensions/routing.rb', line 14

def locals
  @locals
end

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options


14
15
16
# File 'middleman-core/lib/middleman-core/core_extensions/routing.rb', line 14

def options
  @options
end

#pageObject

Returns the value of attribute page

Returns:

  • (Object)

    the current value of page


14
15
16
# File 'middleman-core/lib/middleman-core/core_extensions/routing.rb', line 14

def page
  @page
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path


14
15
16
# File 'middleman-core/lib/middleman-core/core_extensions/routing.rb', line 14

def path
  @path
end

Instance Method Details

#execute_descriptor(app, resource_list) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'middleman-core/lib/middleman-core/core_extensions/routing.rb', line 15

def execute_descriptor(app, resource_list)
  normalized_path = path.dup

  if normalized_path.is_a?(String) && !normalized_path.include?('*')
    # Normalize path
    normalized_path = ::Middleman::Util.normalize_path(normalized_path)
    normalized_path = ::File.join(normalized_path, app.config[:index_file]) if normalized_path.end_with?('/') || app.files.by_type(:source).watchers.any? { |w| (w.directory + Pathname(normalized_path)).directory? }
  end

  normalized_path = "/#{::Middleman::Util.strip_leading_slash(normalized_path)}" if normalized_path.is_a?(String)

  resource_list
    .select { |r| ::Middleman::Util.path_match(normalized_path, "/#{r.path}") }
    .each do |r|
      r.(locals, true) if locals

      if page
        if page.key?(:id)
          resource_list.update!(r, :page_id) do
            r.(page, true)
          end
        else
          r.(page, true)
        end
      end

      r.(options, true) if options
    end
end