Minor performance tweak

feature/pipeline
Thomas Reynolds 2016-04-28 10:08:43 -07:00
parent 87e0f240ff
commit 439ecb1887
13 changed files with 39 additions and 24 deletions

View File

@ -157,12 +157,12 @@ module Middleman
define_setting :layout, :_auto_layout, 'Default layout name' define_setting :layout, :_auto_layout, 'Default layout name'
# Which file extensions have a layout by default. # Which file extensions have a layout by default.
# @return [Array.<String>] # @return [Set.<String>]
define_setting :extensions_with_layout, %w(.htm .html .xhtml .php), 'Which file extensions have a layout by default.' define_setting :extensions_with_layout, %w(.htm .html .xhtml .php), 'Which file extensions have a layout by default.', set: true
# Which file extensions are "assets." # Which file extensions are "assets."
# @return [Array.<String>] # @return [Array.<String>]
define_setting :asset_extensions, %w(.css .png .jpg .jpeg .webp .svg .svgz .js .gif .ttf .otf .woff .woff2 .eot .ico .map), 'Which file extensions are treated as assets.' define_setting :asset_extensions, %w(.css .png .jpg .jpeg .webp .svg .svgz .js .gif .ttf .otf .woff .woff2 .eot .ico .map), 'Which file extensions are treated as assets.', set: true
# Default string encoding for templates and output. # Default string encoding for templates and output.
# @return [String] # @return [String]

View File

@ -1,3 +1,5 @@
require 'set'
module Middleman module Middleman
module Configuration module Configuration
# A class that manages a collection of documented settings. # A class that manages a collection of documented settings.
@ -129,23 +131,37 @@ module Middleman
def initialize(key, default, description, options={}) def initialize(key, default, description, options={})
@value_set = false @value_set = false
@array_wrapped_value = nil
@array_wrapped_default = nil
self.key = key self.key = key
self.default = default self.default = default
self.description = description self.description = description
self.options = options self.options = options
@array_wrapped_default = if self.default && options[:set] && self.default.is_a?(Array)
Set.new(self.default)
end
end end
# The user-supplied value for this setting, overriding the default # The user-supplied value for this setting, overriding the default
def value=(value) def value=(value)
@value = value @value = value
@value_set = true @value_set = true
@array_wrapped_value = if @value && options[:set] && @value.is_a?(Array)
Set.new(@value)
end
end end
# The effective value of the setting, which may be the default # The effective value of the setting, which may be the default
# if the user has not set a value themselves. Note that even if the # if the user has not set a value themselves. Note that even if the
# user sets the value to nil it will override the default. # user sets the value to nil it will override the default.
def value def value
value_set? ? @value : default if value_set?
@array_wrapped_value ? @array_wrapped_value : @value
else
@array_wrapped_default ? @array_wrapped_default : default
end
end end
# Whether or not there has been a value set beyond the default # Whether or not there has been a value set beyond the default

View File

@ -1,8 +1,8 @@
require 'middleman-core/util' require 'middleman-core/util'
class Middleman::Extensions::AssetHash < ::Middleman::Extension class Middleman::Extensions::AssetHash < ::Middleman::Extension
option :sources, %w(.css .htm .html .js .php .xhtml), 'List of extensions that are searched for hashable assets.' option :sources, %w(.css .htm .html .js .php .xhtml), 'List of extensions that are searched for hashable assets.', set: true
option :exts, nil, 'List of extensions that get asset hashes appended to them.' option :exts, nil, 'List of extensions that get asset hashes appended to them.', set: true
option :ignore, [], 'Regexes of filenames to skip adding asset hashes to' option :ignore, [], 'Regexes of filenames to skip adding asset hashes to'
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites' option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites'
@ -30,7 +30,6 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
asset_path asset_path
end end
return unless asset_page = app.sitemap.find_resource_by_destination_path(full_asset_path) || app.sitemap.find_resource_by_path(full_asset_path) return unless asset_page = app.sitemap.find_resource_by_destination_path(full_asset_path) || app.sitemap.find_resource_by_path(full_asset_path)
replacement_path = "/#{asset_page.destination_path}" replacement_path = "/#{asset_page.destination_path}"

View File

@ -1,7 +1,7 @@
# The Cache Buster extension # The Cache Buster extension
class Middleman::Extensions::CacheBuster < ::Middleman::Extension class Middleman::Extensions::CacheBuster < ::Middleman::Extension
option :exts, nil, 'List of extensions that get cache busters strings appended to them.' option :exts, nil, 'List of extensions that get cache busters strings appended to them.', set: true
option :sources, %w(.css .htm .html .js .php .xhtml), 'List of extensions that are searched for bustable assets.' option :sources, %w(.css .htm .html .js .php .xhtml), 'List of extensions that are searched for bustable assets.', set: true
option :ignore, [], 'Regexes of filenames to skip adding query strings to' option :ignore, [], 'Regexes of filenames to skip adding query strings to'
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites' option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites'

View File

@ -1,3 +1,5 @@
require 'set'
# Directory Indexes extension # Directory Indexes extension
class Middleman::Extensions::DirectoryIndexes < ::Middleman::Extension class Middleman::Extensions::DirectoryIndexes < ::Middleman::Extension
# This should run after most other sitemap manipulators so that it # This should run after most other sitemap manipulators so that it
@ -11,7 +13,7 @@ class Middleman::Extensions::DirectoryIndexes < ::Middleman::Extension
index_file = app.config[:index_file] index_file = app.config[:index_file]
new_index_path = "/#{index_file}" new_index_path = "/#{index_file}"
extensions = %w(.htm .html .php .xhtml) extensions = Set.new(%w(.htm .html .php .xhtml))
resources.each do |resource| resources.each do |resource|
# Check if it would be pointless to reroute # Check if it would be pointless to reroute

View File

@ -10,7 +10,7 @@
# to .css, .htm, .html, .js, and .xhtml # to .css, .htm, .html, .js, and .xhtml
# #
class Middleman::Extensions::Gzip < ::Middleman::Extension class Middleman::Extensions::Gzip < ::Middleman::Extension
option :exts, %w(.css .htm .html .js .svg .xhtml), 'File extensions to Gzip when building.' option :exts, %w(.css .htm .html .js .svg .xhtml), 'File extensions to Gzip when building.', set: true
option :ignore, [], 'Patterns to avoid gzipping' option :ignore, [], 'Patterns to avoid gzipping'
option :overwrite, false, 'Overwrite original files instead of adding .gz extension.' option :overwrite, false, 'Overwrite original files instead of adding .gz extension.'

View File

@ -9,8 +9,8 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
require 'sass' require 'sass'
SassCompressor SassCompressor
}, 'Set the CSS compressor to use.' }, 'Set the CSS compressor to use.'
option :content_types, %w(text/css), 'Content types of resources that contain CSS' option :content_types, %w(text/css), 'Content types of resources that contain CSS', set: true
option :inline_content_types, %w(text/html text/php), 'Content types of resources that contain inline CSS' option :inline_content_types, %w(text/html text/php), 'Content types of resources that contain inline CSS', set: true
INLINE_CSS_REGEX = /(<style[^>]*>\s*(?:\/\*<!\[CDATA\[\*\/\n)?)(.*?)((?:(?:\n\s*)?\/\*\]\]>\*\/)?\s*<\/style>)/m INLINE_CSS_REGEX = /(<style[^>]*>\s*(?:\/\*<!\[CDATA\[\*\/\n)?)(.*?)((?:(?:\n\s*)?\/\*\]\]>\*\/)?\s*<\/style>)/m

View File

@ -9,8 +9,8 @@ class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension
require 'uglifier' require 'uglifier'
::Uglifier.new ::Uglifier.new
}, 'Set the JS compressor to use.' }, 'Set the JS compressor to use.'
option :content_types, %w(application/javascript), 'Content types of resources that contain JS' option :content_types, %w(application/javascript), 'Content types of resources that contain JS', set: true
option :inline_content_types, %w(text/html text/php), 'Content types of resources that contain inline JS' option :inline_content_types, %w(text/html text/php), 'Content types of resources that contain inline JS', set: true
INLINE_JS_REGEX = /(<script[^>]*>\s*(?:\/\/(?:(?:<!--)|(?:<!\[CDATA\[))\n)?)(.*?)((?:(?:\n\s*)?\/\/(?:(?:-->)|(?:\]\]>)))?\s*<\/script>)/m INLINE_JS_REGEX = /(<script[^>]*>\s*(?:\/\/(?:(?:<!--)|(?:<!\[CDATA\[))\n)?)(.*?)((?:(?:\n\s*)?\/\/(?:(?:-->)|(?:\]\]>)))?\s*<\/script>)/m

View File

@ -1,7 +1,7 @@
# Relative Assets extension # Relative Assets extension
class Middleman::Extensions::RelativeAssets < ::Middleman::Extension class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
option :exts, nil, 'List of extensions that get converted to relative paths.' option :exts, nil, 'List of extensions that get converted to relative paths.', set: true
option :sources, %w(.css .htm .html .xhtml), 'List of extensions that are searched for relative assets.' option :sources, %w(.css .htm .html .xhtml), 'List of extensions that are searched for relative assets.', set: true
option :ignore, [], 'Regexes of filenames to skip converting to relative paths.' option :ignore, [], 'Regexes of filenames to skip converting to relative paths.'
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites.' option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites.'
option :helpers_only, false, 'Allow only Ruby helpers to change paths.' option :helpers_only, false, 'Allow only Ruby helpers to change paths.'

View File

@ -142,7 +142,7 @@ module Middleman
# Render this resource # Render this resource
# @return [String] # @return [String]
# Contract Maybe[Hash], Maybe[Hash], Maybe[Proc] => String # Contract Maybe[Hash], Maybe[Hash], Maybe[Proc] => String
def render(opts={}, locs={}, &block) def render(opts={}, locs={})
body = render_without_filters(opts, locs) body = render_without_filters(opts, locs)
return body if @filters.empty? return body if @filters.empty?

View File

@ -94,7 +94,7 @@ module Middleman
.transpose .transpose
.map(&::Regexp.method(:union)) .map(&::Regexp.method(:union))
match = / /
\A(?:[^\r\n]*coding:[^\r\n]*\r?\n)? \A(?:[^\r\n]*coding:[^\r\n]*\r?\n)?
(?<start>#{start_delims})[ ]*\r?\n (?<start>#{start_delims})[ ]*\r?\n
(?<frontmatter>.*?)[ ]*\r?\n? (?<frontmatter>.*?)[ ]*\r?\n?

View File

@ -56,10 +56,8 @@ module Middleman
Contract String => String Contract String => String
def step_through_extensions(path) def step_through_extensions(path)
while ::Middleman::Util.tilt_class(path) while ext = File.extname(path)
ext = ::File.extname(path) break if ext.empty? || !::Middleman::Util.tilt_class(ext)
break if ext.empty?
yield ext if block_given? yield ext if block_given?
# Strip templating extensions as long as Tilt knows them # Strip templating extensions as long as Tilt knows them

View File

@ -6,7 +6,7 @@ module Middleman
module_function module_function
Contract String, String, ArrayOf[String], IsA['::Middleman::Application'], Proc => String Contract String, String, SetOf[String], IsA['::Middleman::Application'], Proc => String
def rewrite_paths(body, path, exts, app, &_block) def rewrite_paths(body, path, exts, app, &_block)
exts = exts.sort_by(&:length).reverse exts = exts.sort_by(&:length).reverse
matcher = /([\'\"\(,]\s*|# sourceMappingURL=)([^\s\'\"\)\(>]+(#{::Regexp.union(exts)}))/ matcher = /([\'\"\(,]\s*|# sourceMappingURL=)([^\s\'\"\)\(>]+(#{::Regexp.union(exts)}))/