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

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

Instance Method Summary collapse

Instance Method Details

#content_typeObject



70
71
72
73
74
75
76
77
78
79
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 70

def content_type
  mime_type = super
  return mime_type if mime_type

  if proxy?
    proxied_to_resource.content_type
  else
    nil
  end
end

#get_source_fileObject



62
63
64
65
66
67
68
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 62

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

#proxied_toString

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

Returns:



41
42
43
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 41

def proxied_to
  @proxied_to
end

#proxied_to_resourceSitemap::Resource

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

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 48

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

Returns:

  • (Boolean)


26
27
28
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 26

def proxy?
  !!@proxied_to
end

#proxy_to(target) ⇒ void

This method returns an undefined value.

Set this page to proxy to a target path

Parameters:



33
34
35
36
37
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 33

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