Minor performance tweak
This commit is contained in:
parent
87e0f240ff
commit
439ecb1887
13 changed files with 39 additions and 24 deletions
|
@ -157,12 +157,12 @@ module Middleman
|
|||
define_setting :layout, :_auto_layout, 'Default layout name'
|
||||
|
||||
# Which file extensions have a layout by default.
|
||||
# @return [Array.<String>]
|
||||
define_setting :extensions_with_layout, %w(.htm .html .xhtml .php), 'Which file extensions have a layout by default.'
|
||||
# @return [Set.<String>]
|
||||
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."
|
||||
# @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.
|
||||
# @return [String]
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require 'set'
|
||||
|
||||
module Middleman
|
||||
module Configuration
|
||||
# A class that manages a collection of documented settings.
|
||||
|
@ -129,23 +131,37 @@ module Middleman
|
|||
|
||||
def initialize(key, default, description, options={})
|
||||
@value_set = false
|
||||
@array_wrapped_value = nil
|
||||
@array_wrapped_default = nil
|
||||
self.key = key
|
||||
self.default = default
|
||||
self.description = description
|
||||
self.options = options
|
||||
|
||||
@array_wrapped_default = if self.default && options[:set] && self.default.is_a?(Array)
|
||||
Set.new(self.default)
|
||||
end
|
||||
end
|
||||
|
||||
# The user-supplied value for this setting, overriding the default
|
||||
def value=(value)
|
||||
@value = value
|
||||
@value_set = true
|
||||
|
||||
@array_wrapped_value = if @value && options[:set] && @value.is_a?(Array)
|
||||
Set.new(@value)
|
||||
end
|
||||
end
|
||||
|
||||
# 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
|
||||
# user sets the value to nil it will override the default.
|
||||
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
|
||||
|
||||
# Whether or not there has been a value set beyond the default
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'middleman-core/util'
|
||||
|
||||
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 :exts, nil, 'List of extensions that get asset hashes appended to them.'
|
||||
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.', set: true
|
||||
option :ignore, [], 'Regexes of filenames to skip adding asset hashes to'
|
||||
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites'
|
||||
|
||||
|
@ -30,7 +30,6 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
|||
asset_path
|
||||
end
|
||||
|
||||
|
||||
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}"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# The Cache Buster extension
|
||||
class Middleman::Extensions::CacheBuster < ::Middleman::Extension
|
||||
option :exts, nil, 'List of extensions that get cache busters strings appended to them.'
|
||||
option :sources, %w(.css .htm .html .js .php .xhtml), 'List of extensions that are searched for bustable assets.'
|
||||
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.', set: true
|
||||
option :ignore, [], 'Regexes of filenames to skip adding query strings to'
|
||||
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites'
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require 'set'
|
||||
|
||||
# Directory Indexes extension
|
||||
class Middleman::Extensions::DirectoryIndexes < ::Middleman::Extension
|
||||
# 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]
|
||||
new_index_path = "/#{index_file}"
|
||||
|
||||
extensions = %w(.htm .html .php .xhtml)
|
||||
extensions = Set.new(%w(.htm .html .php .xhtml))
|
||||
|
||||
resources.each do |resource|
|
||||
# Check if it would be pointless to reroute
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
# to .css, .htm, .html, .js, and .xhtml
|
||||
#
|
||||
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 :overwrite, false, 'Overwrite original files instead of adding .gz extension.'
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
|
|||
require 'sass'
|
||||
SassCompressor
|
||||
}, 'Set the CSS compressor to use.'
|
||||
option :content_types, %w(text/css), 'Content types of resources that contain CSS'
|
||||
option :inline_content_types, %w(text/html text/php), 'Content types of resources that contain inline 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', set: true
|
||||
|
||||
INLINE_CSS_REGEX = /(<style[^>]*>\s*(?:\/\*<!\[CDATA\[\*\/\n)?)(.*?)((?:(?:\n\s*)?\/\*\]\]>\*\/)?\s*<\/style>)/m
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@ class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension
|
|||
require 'uglifier'
|
||||
::Uglifier.new
|
||||
}, 'Set the JS compressor to use.'
|
||||
option :content_types, %w(application/javascript), 'Content types of resources that contain JS'
|
||||
option :inline_content_types, %w(text/html text/php), 'Content types of resources that contain inline 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', set: true
|
||||
|
||||
INLINE_JS_REGEX = /(<script[^>]*>\s*(?:\/\/(?:(?:<!--)|(?:<!\[CDATA\[))\n)?)(.*?)((?:(?:\n\s*)?\/\/(?:(?:-->)|(?:\]\]>)))?\s*<\/script>)/m
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Relative Assets extension
|
||||
class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
|
||||
option :exts, nil, 'List of extensions that get converted to relative paths.'
|
||||
option :sources, %w(.css .htm .html .xhtml), 'List of extensions that are searched for relative assets.'
|
||||
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.', set: true
|
||||
option :ignore, [], 'Regexes of filenames to skip converting to relative paths.'
|
||||
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites.'
|
||||
option :helpers_only, false, 'Allow only Ruby helpers to change paths.'
|
||||
|
|
|
@ -142,7 +142,7 @@ module Middleman
|
|||
# Render this resource
|
||||
# @return [String]
|
||||
# Contract Maybe[Hash], Maybe[Hash], Maybe[Proc] => String
|
||||
def render(opts={}, locs={}, &block)
|
||||
def render(opts={}, locs={})
|
||||
body = render_without_filters(opts, locs)
|
||||
|
||||
return body if @filters.empty?
|
||||
|
|
|
@ -94,7 +94,7 @@ module Middleman
|
|||
.transpose
|
||||
.map(&::Regexp.method(:union))
|
||||
|
||||
match = /
|
||||
/
|
||||
\A(?:[^\r\n]*coding:[^\r\n]*\r?\n)?
|
||||
(?<start>#{start_delims})[ ]*\r?\n
|
||||
(?<frontmatter>.*?)[ ]*\r?\n?
|
||||
|
|
|
@ -56,10 +56,8 @@ module Middleman
|
|||
|
||||
Contract String => String
|
||||
def step_through_extensions(path)
|
||||
while ::Middleman::Util.tilt_class(path)
|
||||
ext = ::File.extname(path)
|
||||
break if ext.empty?
|
||||
|
||||
while ext = File.extname(path)
|
||||
break if ext.empty? || !::Middleman::Util.tilt_class(ext)
|
||||
yield ext if block_given?
|
||||
|
||||
# Strip templating extensions as long as Tilt knows them
|
||||
|
|
|
@ -6,7 +6,7 @@ module Middleman
|
|||
|
||||
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)
|
||||
exts = exts.sort_by(&:length).reverse
|
||||
matcher = /([\'\"\(,]\s*|# sourceMappingURL=)([^\s\'\"\)\(>]+(#{::Regexp.union(exts)}))/
|
||||
|
|
Loading…
Add table
Reference in a new issue