Fix a lot of breakage caused by removing/hiding accessors
This commit is contained in:
parent
78b7bbb92a
commit
213c672969
9 changed files with 37 additions and 30 deletions
|
@ -254,7 +254,7 @@ module Middleman::Cli
|
||||||
FileUtils.cp(resource.source_file, output_file)
|
FileUtils.cp(resource.source_file, output_file)
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
response = @rack.get(URI.escape(resource.request_path))
|
response = @rack.get(URI.escape(resource.destination_path))
|
||||||
|
|
||||||
if response.status == 200
|
if response.status == 200
|
||||||
base.create_file(output_file, binary_encode(response.body))
|
base.create_file(output_file, binary_encode(response.body))
|
||||||
|
|
|
@ -7,7 +7,7 @@ module Middleman
|
||||||
class Liquid < Middleman::Extension
|
class Liquid < Middleman::Extension
|
||||||
# After config, setup liquid partial paths
|
# After config, setup liquid partial paths
|
||||||
def after_configuration
|
def after_configuration
|
||||||
::Liquid::Template.file_system = ::Liquid::LocalFileSystem.new(source_dir)
|
::Liquid::Template.file_system = ::Liquid::LocalFileSystem.new(app.source_dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
def manipulate_resource_list(resources)
|
def manipulate_resource_list(resources)
|
||||||
|
|
|
@ -3,15 +3,15 @@ module Middleman
|
||||||
module Extensions
|
module Extensions
|
||||||
# Class to handle managing ignores
|
# Class to handle managing ignores
|
||||||
class Ignores
|
class Ignores
|
||||||
def initialize(sitemap)
|
def initialize(app, sitemap)
|
||||||
@app = sitemap.app
|
@app = app
|
||||||
@app.add_to_config_context :ignore, &method(:create_ignore)
|
@app.add_to_config_context :ignore, &method(:create_ignore)
|
||||||
@app.define_singleton_method(:ignore, &method(:create_ignore))
|
@app.define_singleton_method :ignore, &method(:create_ignore)
|
||||||
|
|
||||||
# Array of callbacks which can ass ignored
|
# Array of callbacks which can ass ignored
|
||||||
@ignored_callbacks = []
|
@ignored_callbacks = []
|
||||||
|
|
||||||
sitemap.define_singleton_method(:ignored?, &method(:ignored?))
|
sitemap.define_singleton_method :ignored?, &method(:ignored?)
|
||||||
::Middleman::Sitemap::Resource.send :include, IgnoreResourceInstanceMethods
|
::Middleman::Sitemap::Resource.send :include, IgnoreResourceInstanceMethods
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,9 @@ module Middleman
|
||||||
attr_accessor :sitemap
|
attr_accessor :sitemap
|
||||||
attr_accessor :waiting_for_ready
|
attr_accessor :waiting_for_ready
|
||||||
|
|
||||||
def initialize(sitemap)
|
def initialize(app, sitemap)
|
||||||
@sitemap = sitemap
|
@sitemap = sitemap
|
||||||
@app = @sitemap.app
|
@app = app
|
||||||
@file_paths_on_disk = Set.new
|
@file_paths_on_disk = Set.new
|
||||||
|
|
||||||
scoped_self = self
|
scoped_self = self
|
||||||
|
|
|
@ -4,8 +4,8 @@ module Middleman
|
||||||
# Manages the list of proxy configurations and manipulates the sitemap
|
# Manages the list of proxy configurations and manipulates the sitemap
|
||||||
# to include new resources based on those configurations
|
# to include new resources based on those configurations
|
||||||
class Proxies
|
class Proxies
|
||||||
def initialize(sitemap)
|
def initialize(app)
|
||||||
@app = sitemap.app
|
@app = app
|
||||||
@app.add_to_config_context :proxy, &method(:create_proxy)
|
@app.add_to_config_context :proxy, &method(:create_proxy)
|
||||||
@app.define_singleton_method(:proxy, &method(:create_proxy))
|
@app.define_singleton_method(:proxy, &method(:create_proxy))
|
||||||
|
|
||||||
|
@ -109,10 +109,10 @@ module Middleman
|
||||||
# if there is no resource.
|
# if there is no resource.
|
||||||
# @return [Sitemap::Resource]
|
# @return [Sitemap::Resource]
|
||||||
def proxied_to_resource
|
def proxied_to_resource
|
||||||
proxy_resource = store.find_resource_by_path(proxied_to)
|
proxy_resource = @store.find_resource_by_path(proxied_to)
|
||||||
|
|
||||||
unless proxy_resource
|
unless proxy_resource
|
||||||
raise "Path #{path} proxies to unknown file #{proxied_to}:#{store.resources.map(&:path)}"
|
raise "Path #{path} proxies to unknown file #{proxied_to}:#{@store.resources.map(&:path)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
if proxy_resource.proxy?
|
if proxy_resource.proxy?
|
||||||
|
|
|
@ -6,8 +6,8 @@ module Middleman
|
||||||
# Manages the list of proxy configurations and manipulates the sitemap
|
# Manages the list of proxy configurations and manipulates the sitemap
|
||||||
# to include new resources based on those configurations
|
# to include new resources based on those configurations
|
||||||
class Redirects
|
class Redirects
|
||||||
def initialize(sitemap)
|
def initialize(app)
|
||||||
@app = sitemap.app
|
@app = app
|
||||||
@app.add_to_config_context :redirect, &method(:create_redirect)
|
@app.add_to_config_context :redirect, &method(:create_redirect)
|
||||||
|
|
||||||
@redirects = {}
|
@redirects = {}
|
||||||
|
@ -86,6 +86,10 @@ module Middleman
|
||||||
def metadata
|
def metadata
|
||||||
@local_metadata.dup
|
@local_metadata.dup
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_source_file
|
||||||
|
''
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,8 +4,8 @@ module Middleman
|
||||||
class RequestEndpoints
|
class RequestEndpoints
|
||||||
# Manages the list of proxy configurations and manipulates the sitemap
|
# Manages the list of proxy configurations and manipulates the sitemap
|
||||||
# to include new resources based on those configurations
|
# to include new resources based on those configurations
|
||||||
def initialize(sitemap)
|
def initialize(app)
|
||||||
@app = sitemap.app
|
@app = app
|
||||||
@app.add_to_config_context :endpoint, &method(:create_endpoint)
|
@app.add_to_config_context :endpoint, &method(:create_endpoint)
|
||||||
|
|
||||||
@endpoints = {}
|
@endpoints = {}
|
||||||
|
|
|
@ -7,7 +7,7 @@ module Middleman
|
||||||
def parent
|
def parent
|
||||||
parts = path.split('/')
|
parts = path.split('/')
|
||||||
tail = parts.pop
|
tail = parts.pop
|
||||||
is_index = (tail == app.config[:index_file])
|
is_index = (tail == @app.config[:index_file])
|
||||||
|
|
||||||
return nil if is_index && parts.length < 1
|
return nil if is_index && parts.length < 1
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ module Middleman
|
||||||
found
|
found
|
||||||
else
|
else
|
||||||
parts.pop if is_index
|
parts.pop if is_index
|
||||||
store.find_resource_by_destination_path("#{parts.join('/')}/#{app.config[:index_file]}")
|
store.find_resource_by_destination_path("#{parts.join('/')}/#{@app.config[:index_file]}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -34,11 +34,11 @@ module Middleman
|
||||||
base_path = eponymous_directory_path
|
base_path = eponymous_directory_path
|
||||||
prefix = %r{^#{base_path.sub("/", "\\/")}}
|
prefix = %r{^#{base_path.sub("/", "\\/")}}
|
||||||
else
|
else
|
||||||
base_path = path.sub("#{app.config[:index_file]}", '')
|
base_path = path.sub("#{@app.config[:index_file]}", '')
|
||||||
prefix = %r{^#{base_path.sub("/", "\\/")}}
|
prefix = %r{^#{base_path.sub("/", "\\/")}}
|
||||||
end
|
end
|
||||||
|
|
||||||
store.resources.select do |sub_resource|
|
@store.resources.select do |sub_resource|
|
||||||
if sub_resource.path == path || sub_resource.path !~ prefix
|
if sub_resource.path == path || sub_resource.path !~ prefix
|
||||||
false
|
false
|
||||||
else
|
else
|
||||||
|
@ -47,7 +47,7 @@ module Middleman
|
||||||
if parts.length == 1
|
if parts.length == 1
|
||||||
true
|
true
|
||||||
elsif parts.length == 2
|
elsif parts.length == 2
|
||||||
parts.last == app.config[:index_file]
|
parts.last == @app.config[:index_file]
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
@ -65,17 +65,17 @@ module Middleman
|
||||||
# Whether this resource is either a directory index, or has the same name as an existing directory in the source
|
# Whether this resource is either a directory index, or has the same name as an existing directory in the source
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def directory_index?
|
def directory_index?
|
||||||
path.include?(app.config[:index_file]) || path =~ /\/$/ || eponymous_directory?
|
path.include?(@app.config[:index_file]) || path =~ /\/$/ || eponymous_directory?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Whether the resource has the same name as a directory in the source
|
# Whether the resource has the same name as a directory in the source
|
||||||
# (e.g., if the resource is named 'gallery.html' and a path exists named 'gallery/', this would return true)
|
# (e.g., if the resource is named 'gallery.html' and a path exists named 'gallery/', this would return true)
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def eponymous_directory?
|
def eponymous_directory?
|
||||||
if !path.end_with?("/#{app.config[:index_file]}") && destination_path.end_with?("/#{app.config[:index_file]}")
|
if !path.end_with?("/#{@app.config[:index_file]}") && destination_path.end_with?("/#{@app.config[:index_file]}")
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
full_path = File.join(app.source_dir, eponymous_directory_path)
|
full_path = File.join(@app.source_dir, eponymous_directory_path)
|
||||||
File.exist?(full_path) && File.directory?(full_path)
|
File.exist?(full_path) && File.directory?(full_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,9 @@ module Middleman
|
||||||
# which is the path relative to the source directory, minus any template
|
# which is the path relative to the source directory, minus any template
|
||||||
# extensions. All "path" parameters used in this class are source paths.
|
# extensions. All "path" parameters used in this class are source paths.
|
||||||
class Store
|
class Store
|
||||||
|
# @return [Middleman::Application]
|
||||||
|
attr_reader :app
|
||||||
|
|
||||||
# Initialize with parent app
|
# Initialize with parent app
|
||||||
# @param [Middleman::Application] app
|
# @param [Middleman::Application] app
|
||||||
def initialize(app)
|
def initialize(app)
|
||||||
|
@ -34,23 +37,23 @@ module Middleman
|
||||||
reset_lookup_cache!
|
reset_lookup_cache!
|
||||||
|
|
||||||
# Handle ignore commands
|
# Handle ignore commands
|
||||||
Middleman::Sitemap::Extensions::Ignores.new(self)
|
Middleman::Sitemap::Extensions::Ignores.new(@app, self)
|
||||||
|
|
||||||
# Extensions
|
# Extensions
|
||||||
{
|
{
|
||||||
# Register classes which can manipulate the main site map list
|
# Register classes which can manipulate the main site map list
|
||||||
on_disk: Middleman::Sitemap::Extensions::OnDisk,
|
on_disk: Middleman::Sitemap::Extensions::OnDisk.new(@app, self),
|
||||||
|
|
||||||
# Request Endpoints
|
# Request Endpoints
|
||||||
request_endpoints: Middleman::Sitemap::Extensions::RequestEndpoints,
|
request_endpoints: Middleman::Sitemap::Extensions::RequestEndpoints.new(@app),
|
||||||
|
|
||||||
# Proxies
|
# Proxies
|
||||||
proxies: Middleman::Sitemap::Extensions::Proxies,
|
proxies: Middleman::Sitemap::Extensions::Proxies.new(@app),
|
||||||
|
|
||||||
# Redirects
|
# Redirects
|
||||||
redirects: Middleman::Sitemap::Extensions::Redirects
|
redirects: Middleman::Sitemap::Extensions::Redirects.new(@app)
|
||||||
}.each do |k, m|
|
}.each do |k, m|
|
||||||
register_resource_list_manipulator(k, m.new(self))
|
register_resource_list_manipulator(k, m)
|
||||||
end
|
end
|
||||||
|
|
||||||
@app.config_context.class.send :delegate, :sitemap, to: :app
|
@app.config_context.class.send :delegate, :sitemap, to: :app
|
||||||
|
|
Loading…
Add table
Reference in a new issue