move Sitemap into application, it's core to the entire system

This commit is contained in:
Thomas Reynolds 2014-07-05 10:42:03 -07:00
parent 3a2cab4775
commit 3a19cc668d
3 changed files with 33 additions and 53 deletions

View file

@ -15,7 +15,6 @@ require 'hooks'
# Our custom logger # Our custom logger
require 'middleman-core/logger' require 'middleman-core/logger'
require 'middleman-core/sitemap'
require 'middleman-core/sitemap/store' require 'middleman-core/sitemap/store'
require 'middleman-core/configuration' require 'middleman-core/configuration'
@ -134,6 +133,27 @@ module Middleman
# @return [Boolean] # @return [Boolean]
config.define_setting :protect_from_csrf, false, 'Should Padrino include CRSF tag' 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 # Activate custom features and extensions
include Middleman::CoreExtensions::Extensions include Middleman::CoreExtensions::Extensions
@ -143,9 +163,6 @@ module Middleman
# Setup custom rendering # Setup custom rendering
include Middleman::CoreExtensions::Rendering include Middleman::CoreExtensions::Rendering
# Sitemap Config options and public api
include Middleman::Sitemap
# Reference to Logger singleton # Reference to Logger singleton
def logger def logger
::Middleman::Logger.singleton ::Middleman::Logger.singleton

View file

@ -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

View file

@ -154,5 +154,17 @@ module Middleman
file_renderer = ::Middleman::FileRenderer.new(@app, path) file_renderer = ::Middleman::FileRenderer.new(@app, path)
file_renderer.render(locs, opts, self, &block) file_renderer.render(locs, opts, self, &block)
end 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
end end