From 3a19cc668da9f9b559155fd7ab7c6aee6b3ebedf Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Sat, 5 Jul 2014 10:42:03 -0700 Subject: [PATCH] move Sitemap into application, it's core to the entire system --- .../lib/middleman-core/application.rb | 25 ++++++++-- middleman-core/lib/middleman-core/sitemap.rb | 49 ------------------- .../lib/middleman-core/template_context.rb | 12 +++++ 3 files changed, 33 insertions(+), 53 deletions(-) delete mode 100644 middleman-core/lib/middleman-core/sitemap.rb diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index e264ea09..90dbb65f 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -15,7 +15,6 @@ require 'hooks' # Our custom logger require 'middleman-core/logger' -require 'middleman-core/sitemap' require 'middleman-core/sitemap/store' require 'middleman-core/configuration' @@ -134,6 +133,27 @@ module Middleman # @return [Boolean] config.define_setting :protect_from_csrf, false, 'Should Padrino include CRSF tag' + # Set to automatically convert some characters into a directory + config.define_setting :automatic_directory_matcher, nil, 'Set to automatically convert some characters into a directory' + + # Setup callbacks which can exclude paths from the sitemap + config.define_setting :ignored_sitemap_matchers, { + # dotfiles and folders in the root + root_dotfiles: proc { |file| file.start_with?('.') }, + + # Files starting with an dot, but not .htaccess + source_dotfiles: proc { |file| + file =~ %r{/\.} && file !~ %r{/\.(htaccess|htpasswd|nojekyll)} + }, + + # Files starting with an underscore, but not a double-underscore + partials: proc { |file| file =~ %r{/_[^_]} }, + + layout: proc { |file, sitemap_app| + file.start_with?(File.join(sitemap_app.config[:source], 'layout.')) || file.start_with?(File.join(sitemap_app.config[:source], 'layouts/')) + } + }, 'Callbacks that can exclude paths from the sitemap' + # Activate custom features and extensions include Middleman::CoreExtensions::Extensions @@ -143,9 +163,6 @@ module Middleman # Setup custom rendering include Middleman::CoreExtensions::Rendering - # Sitemap Config options and public api - include Middleman::Sitemap - # Reference to Logger singleton def logger ::Middleman::Logger.singleton diff --git a/middleman-core/lib/middleman-core/sitemap.rb b/middleman-core/lib/middleman-core/sitemap.rb deleted file mode 100644 index c320369c..00000000 --- a/middleman-core/lib/middleman-core/sitemap.rb +++ /dev/null @@ -1,49 +0,0 @@ -# Core Sitemap Extensions -module Middleman - module Sitemap - # Setup Extension - class << self - # Once registered - def included(app) - # Set to automatically convert some characters into a directory - app.config.define_setting :automatic_directory_matcher, nil, 'Set to automatically convert some characters into a directory' - - # Setup callbacks which can exclude paths from the sitemap - app.config.define_setting :ignored_sitemap_matchers, { - # dotfiles and folders in the root - root_dotfiles: proc { |file| file.start_with?('.') }, - - # Files starting with an dot, but not .htaccess - source_dotfiles: proc { |file| - file =~ %r{/\.} && file !~ %r{/\.(htaccess|htpasswd|nojekyll)} - }, - - # Files starting with an underscore, but not a double-underscore - partials: proc { |file| file =~ %r{/_[^_]} }, - - layout: proc { |file, sitemap_app| - file.start_with?(File.join(sitemap_app.config[:source], 'layout.')) || file.start_with?(File.join(sitemap_app.config[:source], 'layouts/')) - } - }, 'Callbacks that can exclude paths from the sitemap' - - # Include instance methods - ::Middleman::TemplateContext.send :include, InstanceMethods - end - end - - # Sitemap instance methods - module InstanceMethods - def current_path - @locs[:current_path] - end - - # Get the resource object for the current path - # @return [Middleman::Sitemap::Resource] - def current_resource - return nil unless current_path - sitemap.find_resource_by_destination_path(current_path) - end - alias_method :current_page, :current_resource - end - end -end diff --git a/middleman-core/lib/middleman-core/template_context.rb b/middleman-core/lib/middleman-core/template_context.rb index a81db78b..01b55fa5 100644 --- a/middleman-core/lib/middleman-core/template_context.rb +++ b/middleman-core/lib/middleman-core/template_context.rb @@ -154,5 +154,17 @@ module Middleman file_renderer = ::Middleman::FileRenderer.new(@app, path) file_renderer.render(locs, opts, self, &block) end + + def current_path + @locs[:current_path] + end + + # Get the resource object for the current path + # @return [Middleman::Sitemap::Resource] + def current_resource + return nil unless current_path + sitemap.find_resource_by_destination_path(current_path) + end + alias_method :current_page, :current_resource end end