From a1fe810a50076792e3abe05bdc427e6aad7c1ee6 Mon Sep 17 00:00:00 2001 From: Ben Hollis Date: Mon, 7 Jul 2014 22:12:44 -0700 Subject: [PATCH] Fixup after rebase --- .../frontmatter-neighbor-app/config.rb | 2 +- .../config.rb | 2 +- .../core_extensions/front_matter.rb | 2 +- .../sitemap/extensions/proxies.rb | 14 +--- .../lib/middleman-core/sitemap/resource.rb | 70 ++----------------- 5 files changed, 10 insertions(+), 80 deletions(-) diff --git a/middleman-core/fixtures/frontmatter-neighbor-app/config.rb b/middleman-core/fixtures/frontmatter-neighbor-app/config.rb index 234b9a20..50a368eb 100644 --- a/middleman-core/fixtures/frontmatter-neighbor-app/config.rb +++ b/middleman-core/fixtures/frontmatter-neighbor-app/config.rb @@ -16,7 +16,7 @@ class NeighborFrontmatter < ::Middleman::Extension opts[:renderer_options].symbolize_keys! if opts.key?(:renderer_options) ignored = fmdata.delete(:ignored) resource.add_metadata options: opts, page: fmdata - resource.ignore! if ignored == true && !resource.proxy? + resource.ignore! if ignored == true && !resource.is_a?(::Middleman::Sitemap::ProxyResource) end end end diff --git a/middleman-core/fixtures/frontmatter-settings-neighbor-app/config.rb b/middleman-core/fixtures/frontmatter-settings-neighbor-app/config.rb index 4318d2fd..600b96f8 100644 --- a/middleman-core/fixtures/frontmatter-settings-neighbor-app/config.rb +++ b/middleman-core/fixtures/frontmatter-settings-neighbor-app/config.rb @@ -21,7 +21,7 @@ class NeighborFrontmatter < ::Middleman::Extension opts[:renderer_options].symbolize_keys! if opts.key?(:renderer_options) ignored = fmdata.delete(:ignored) resource.add_metadata options: opts, page: fmdata - resource.ignore! if ignored == true && !resource.proxy? + resource.ignore! if ignored == true && !resource.is_a?(::Middleman::Sitemap::ProxyResource) end end end diff --git a/middleman-core/lib/middleman-core/core_extensions/front_matter.rb b/middleman-core/lib/middleman-core/core_extensions/front_matter.rb index 546bc761..72412398 100644 --- a/middleman-core/lib/middleman-core/core_extensions/front_matter.rb +++ b/middleman-core/lib/middleman-core/core_extensions/front_matter.rb @@ -92,7 +92,7 @@ module Middleman::CoreExtensions data = {} - return [data, nil] if !app.files.exists?(full_path) || ::Middleman::Util.binary?(full_path) + return [data, nil] if !file_watcher.exists?(full_path) || ::Middleman::Util.binary?(full_path) content = File.read(full_path) diff --git a/middleman-core/lib/middleman-core/sitemap/extensions/proxies.rb b/middleman-core/lib/middleman-core/sitemap/extensions/proxies.rb index b9abe44e..9acce571 100644 --- a/middleman-core/lib/middleman-core/sitemap/extensions/proxies.rb +++ b/middleman-core/lib/middleman-core/sitemap/extensions/proxies.rb @@ -119,8 +119,7 @@ module Middleman resource end - # rubocop:disable AccessorMethodName - def get_source_file + def source_file target_resource.source_file end @@ -130,17 +129,6 @@ module Middleman target_resource.content_type end - - # Whether the Resource is ignored - # @return [Boolean] - def ignored? - return true if @ignored - - # Ignore based on the source path (without template extensions) - return true if @app.sitemap.ignored?(path) - - false - end end end end diff --git a/middleman-core/lib/middleman-core/sitemap/resource.rb b/middleman-core/lib/middleman-core/sitemap/resource.rb index a7bf56e9..fdd57b00 100644 --- a/middleman-core/lib/middleman-core/sitemap/resource.rb +++ b/middleman-core/lib/middleman-core/sitemap/resource.rb @@ -19,23 +19,15 @@ module Middleman # @return [String] attr_accessor :destination_path + # The on-disk source file for this resource, if there is one + # @return [String] + attr_reader :source_file + # The path to use when requesting this resource. Normally it's # the same as {#destination_path} but it can be overridden in subclasses. # @return [String] alias_method :request_path, :destination_path - # Get the on-disk source file for this resource - # @return [String] - def source_file - if @source_file - @source_file - elsif proxy? - proxied_to_resource.source_file - else - nil - end - end - # Initialize resource with parent store and URL # @param [Middleman::Sitemap::Store] store # @param [String] path @@ -54,13 +46,6 @@ module Middleman @metadata = { options: {}, locals: {}, page: {} } end - # Set the on-disk source file for this resource - # @return [String] - def source_file - # TODO: Make this work when get_source_file doesn't exist - @source_file || get_source_file - end - # Whether this resource has a template file # @return [Boolean] def template? @@ -164,56 +149,13 @@ module Middleman # Ignore based on the source path (without template extensions) return true if @app.sitemap.ignored?(path) # This allows files to be ignored by their source file name (with template extensions) - !proxy? && @app.sitemap.ignored?(source_file.sub("#{@app.source_dir}/", '')) + !self.is_a?(ProxyResource) && @app.sitemap.ignored?(source_file.sub("#{@app.source_dir}/", '')) end # The preferred MIME content type for this resource based on extension or metadata # @return [String] MIME type for this resource def content_type - mime_type = options[:content_type] || ::Rack::Mime.mime_type(ext, nil) - return mime_type if mime_type - - if proxy? - proxied_to_resource.content_type - else - nil - end - end - - # Whether this page is a proxy - # @return [Boolean] - def proxy? - @proxied_to - end - - # Set this page to proxy to a target path - # @param [String] target - # @return [void] - 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 - - # The path of the page this page is proxied to, or nil if it's not proxied. - # @return [String] - attr_reader :proxied_to - - # The resource for the page this page is proxied to. Throws an exception - # if there is no resource. - # @return [Sitemap::Resource] - 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 + options[:content_type] || ::Rack::Mime.mime_type(ext, nil) end end end