Module: Middleman::Sitemap::Extensions::Proxies::ResourceInstanceMethods

Defined in:
lib/middleman-core/sitemap/extensions/proxies.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#proxied_toString (readonly)

The path of the page this page is proxied to, or nil if it’s not proxied.

Returns:

  • (String)


37
38
39
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 37

def proxied_to
  @proxied_to
end

Instance Method Details

#content_typeObject

rubocop:enable Style/AccessorMethodName



66
67
68
69
70
71
72
73
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 66

def content_type
  mime_type = super
  return mime_type if mime_type

  return proxied_to_resource.content_type if proxy?

  nil
end

#get_source_fileObject

rubocop:disable Style/AccessorMethodName



57
58
59
60
61
62
63
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 57

def get_source_file
  if proxy?
    proxied_to_resource.source_file
  else
    super
  end
end

#proxied_to_resourceSitemap::Resource

The resource for the page this page is proxied to. Throws an exception if there is no resource.

Returns:



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 42

def proxied_to_resource
  proxy_resource = store.find_resource_by_path(proxied_to)

  unless proxy_resource
    raise "Path #{path} proxies to unknown file #{proxied_to}:#{store.resources.map(&:path)}"
  end

  if proxy_resource.proxy?
    raise "You can't proxy #{path} to #{proxied_to} which is itself a proxy."
  end

  proxy_resource
end

#proxy?Boolean

Whether this page is a proxy rubocop:disable TrivialAccessors

Returns:

  • (Boolean)


22
23
24
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 22

def proxy?
  @proxied_to
end

#proxy_to(target)

This method returns an undefined value.

Set this page to proxy to a target path

Parameters:

  • target (String)


29
30
31
32
33
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 29

def proxy_to(target)
  target = ::Middleman::Util.normalize_path(target)
  raise "You can't proxy #{path} to itself!" if target == path
  @proxied_to = target
end