commit
6799606324
|
@ -197,10 +197,11 @@ module Middleman::Cli
|
|||
# Sort order, images, fonts, js/css and finally everything else.
|
||||
sort_order = %w(.png .jpeg .jpg .gif .bmp .svg .svgz .ico .woff .otf .ttf .eot .js .css)
|
||||
|
||||
@app.sitemap.all_paths.select do |p|
|
||||
File.extname(p) == ".css"
|
||||
# Pre-request CSS to give Compass a chance to build sprites
|
||||
@app.sitemap.pages.select do |p|
|
||||
p.ext == ".css"
|
||||
end.each do |p|
|
||||
Middleman::Cli::Build.shared_rack.get("/" + p.gsub(/\s/, "%20"))
|
||||
Middleman::Cli::Build.shared_rack.get(p.request_path.gsub(/\s/, "%20"))
|
||||
end
|
||||
|
||||
# Double-check for compass sprites
|
||||
|
@ -210,23 +211,17 @@ module Middleman::Cli
|
|||
# find files in the build folder when it needs to generate sprites for the
|
||||
# css files
|
||||
|
||||
# TODO: deal with pages, not paths
|
||||
paths = @app.sitemap.all_paths.sort do |a, b|
|
||||
a_ext = File.extname(a)
|
||||
b_ext = File.extname(b)
|
||||
|
||||
a_idx = sort_order.index(a_ext) || 100
|
||||
b_idx = sort_order.index(b_ext) || 100
|
||||
pages = @app.sitemap.pages.sort do |a, b|
|
||||
a_idx = sort_order.index(a.ext) || 100
|
||||
b_idx = sort_order.index(b.ext) || 100
|
||||
|
||||
a_idx <=> b_idx
|
||||
end
|
||||
|
||||
# Loop over all the paths and build them.
|
||||
paths.each do |path|
|
||||
page = @app.sitemap.page(path)
|
||||
|
||||
pages.each do |page|
|
||||
next if page.ignored?
|
||||
next if @config[:glob] && !File.fnmatch(@config[:glob], path)
|
||||
next if @config[:glob] && !File.fnmatch(@config[:glob], page.path)
|
||||
|
||||
base.tilt_template(page)
|
||||
|
||||
|
|
|
@ -6,45 +6,7 @@ module Middleman::CoreExtensions::Builder
|
|||
# @private
|
||||
def registered(app)
|
||||
app.define_hook :after_build
|
||||
app.extend ClassMethods
|
||||
app.send :include, InstanceMethods
|
||||
app.delegate :build_reroute, :to => :"self.class"
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
# Build Class Methods
|
||||
module ClassMethods
|
||||
# Get a list of callbacks which can modify a files build path
|
||||
# Each callback takes a destination path and a request path and
|
||||
# returns a new destination path, or false if it doesn't want to reroute.
|
||||
# @return [Array<Proc>]
|
||||
def build_reroute(&block)
|
||||
@build_rerouters ||= []
|
||||
@build_rerouters << block if block_given?
|
||||
@build_rerouters
|
||||
end
|
||||
end
|
||||
|
||||
# Build Instance Methods
|
||||
module InstanceMethods
|
||||
# Run through callbacks and get the new values
|
||||
#
|
||||
# @param [String] destination The current destination path of the built file
|
||||
# @param [String] request_path The request path of the file
|
||||
# @return [String] The new destination path
|
||||
def reroute_builder(destination, request_path)
|
||||
result = [destination, request_path]
|
||||
|
||||
build_reroute.each do |block|
|
||||
output = block.call(destination, request_path)
|
||||
if output
|
||||
result = output
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -72,7 +72,7 @@ module Middleman::Sitemap
|
|||
@_template ||= ::Middleman::Sitemap::Template.new(self)
|
||||
end
|
||||
|
||||
# Extension of the path
|
||||
# Extension of the path (i.e. '.js')
|
||||
# @return [String]
|
||||
def ext
|
||||
File.extname(path)
|
||||
|
@ -192,8 +192,9 @@ module Middleman::Sitemap
|
|||
# This path can be affected by proxy callbacks.
|
||||
# @return [String]
|
||||
def destination_path
|
||||
# TODO: memoize this value
|
||||
store.reroute_callbacks.inject(self.path) do |destination, callback|
|
||||
# memoizing this means that reroute callbacks should be in place before the sitemap
|
||||
# gets built
|
||||
@destination_path ||= store.reroute_callbacks.inject(self.path) do |destination, callback|
|
||||
callback.call(destination, self)
|
||||
end
|
||||
end
|
||||
|
@ -235,29 +236,27 @@ module Middleman::Sitemap
|
|||
|
||||
if eponymous_directory?
|
||||
base_path = eponymous_directory_path
|
||||
prefix = /^#{base_path.sub("/", "\\/")}/
|
||||
prefix = %r|^#{base_path.sub("/", "\\/")}|
|
||||
else
|
||||
base_path = path.sub("#{app.index_file}", "")
|
||||
prefix = /^#{base_path.sub("/", "\\/")}/
|
||||
prefix = %r|^#{base_path.sub("/", "\\/")}|
|
||||
end
|
||||
|
||||
store.all_paths.select do |sub_path|
|
||||
sub_path =~ prefix
|
||||
end.select do |sub_path|
|
||||
path != sub_path
|
||||
end.select do |sub_path|
|
||||
inner_path = sub_path.sub(prefix, "")
|
||||
parts = inner_path.split("/")
|
||||
if parts.length == 1
|
||||
true
|
||||
elsif parts.length == 2
|
||||
parts.last == app.index_file
|
||||
else
|
||||
false
|
||||
end
|
||||
end.map do |p|
|
||||
store.page(p)
|
||||
end.reject { |p| p.ignored? }
|
||||
store.pages.select do |sub_page|
|
||||
if sub_page == self || sub_page.path !~ prefix || sub_page.ignored?
|
||||
false
|
||||
else
|
||||
inner_path = sub_page.path.sub(prefix, "")
|
||||
parts = inner_path.split("/")
|
||||
if parts.length == 1
|
||||
true
|
||||
elsif parts.length == 2
|
||||
parts.last == app.index_file
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# This page's sibling pages
|
||||
|
|
|
@ -24,6 +24,12 @@ module Middleman::Sitemap
|
|||
@reroute_callbacks = []
|
||||
end
|
||||
|
||||
# A list of all pages
|
||||
# @return [Array<Middleman::Sitemap::Page>]
|
||||
def pages
|
||||
@pages.values
|
||||
end
|
||||
|
||||
# Check to see if we know about a specific path
|
||||
# @param [String] path
|
||||
# @return [Boolean]
|
||||
|
@ -82,22 +88,7 @@ module Middleman::Sitemap
|
|||
def page_by_destination(destination_path)
|
||||
# TODO: memoize this
|
||||
destination_path = normalize_path(destination_path)
|
||||
@pages.values.find {|p| p.destination_path == destination_path }
|
||||
end
|
||||
|
||||
# Loop over known pages
|
||||
# @yield [path, page]
|
||||
# @return [void]
|
||||
def each
|
||||
@pages.each do |k, v|
|
||||
yield k, v
|
||||
end
|
||||
end
|
||||
|
||||
# Get all known paths
|
||||
# @return [Array<String>]
|
||||
def all_paths
|
||||
@pages.keys
|
||||
pages.find {|p| p.destination_path == destination_path }
|
||||
end
|
||||
|
||||
# Whether a path is ignored
|
||||
|
@ -119,7 +110,7 @@ module Middleman::Sitemap
|
|||
# Get a list of ignored paths
|
||||
# @return [Array<String>]
|
||||
def ignored_paths
|
||||
@pages.values.select(&:ignored?).map(&:path)
|
||||
pages.select(&:ignored?).map(&:path)
|
||||
end
|
||||
|
||||
# Whether the given path is generic
|
||||
|
@ -133,7 +124,7 @@ module Middleman::Sitemap
|
|||
# @return [Array<String>]
|
||||
def generic_paths
|
||||
app.cache.fetch :generic_paths do
|
||||
@pages.values.select(&:generic?).map(&:path)
|
||||
pages.select(&:generic?).map(&:path)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -148,7 +139,7 @@ module Middleman::Sitemap
|
|||
# @return [Array<String>]
|
||||
def proxied_paths
|
||||
app.cache.fetch :proxied_paths do
|
||||
@pages.values.select(&:proxy?).map(&:path)
|
||||
pages.select(&:proxy?).map(&:path)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,10 +4,10 @@ require "rubygems"
|
|||
module Middleman
|
||||
# Current Version
|
||||
# @return [String]
|
||||
VERSION = '3.0.0.beta.1' unless const_defined?(:VERSION)
|
||||
VERSION = '3.0.0.beta.2' unless const_defined?(:VERSION)
|
||||
|
||||
# Parsed version for RubyGems
|
||||
# @private
|
||||
# @return [String]
|
||||
GEM_VERSION = ::Gem::Version.create(VERSION) unless const_defined?(:GEM_VERSION)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,18 +13,6 @@ module Middleman::CoreExtensions::Sprockets
|
|||
app.set :js_compressor, false
|
||||
app.set :css_compressor, false
|
||||
|
||||
# Cut off every extension after .js (which sprockets eats up)
|
||||
app.build_reroute do |destination, request_path|
|
||||
if !request_path.match(/\.js\./i)
|
||||
false
|
||||
else
|
||||
[
|
||||
destination.gsub(/\.js(\..*)$/, ".js"),
|
||||
request_path.gsub(/\.js(\..*)$/, ".js")
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
# Once Middleman is setup
|
||||
app.ready do
|
||||
# Create sprockets env for JS
|
||||
|
@ -172,4 +160,4 @@ module Middleman::CoreExtensions::Sprockets
|
|||
super(exception)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue