Merge pull request #2994 from jekyll/fixes-from-benchmarking
This commit is contained in:
commit
00d29e7e77
|
@ -13,3 +13,4 @@ site/_site/
|
||||||
coverage
|
coverage
|
||||||
.ruby-version
|
.ruby-version
|
||||||
.sass-cache
|
.sass-cache
|
||||||
|
tmp/stackprof-*
|
||||||
|
|
|
@ -75,7 +75,7 @@ module Jekyll
|
||||||
# Returns a String containing the directory name where the collection
|
# Returns a String containing the directory name where the collection
|
||||||
# is stored on the filesystem.
|
# is stored on the filesystem.
|
||||||
def relative_directory
|
def relative_directory
|
||||||
"_#{label}"
|
@relative_directory ||= "_#{label}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# The full path to the directory containing the
|
# The full path to the directory containing the
|
||||||
|
@ -83,7 +83,7 @@ module Jekyll
|
||||||
# Returns a String containing th directory name where the collection
|
# Returns a String containing th directory name where the collection
|
||||||
# is stored on the filesystem.
|
# is stored on the filesystem.
|
||||||
def directory
|
def directory
|
||||||
Jekyll.sanitized_path(site.source, relative_directory)
|
@directory ||= Jekyll.sanitized_path(site.source, relative_directory)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks whether the directory "exists" for this collection.
|
# Checks whether the directory "exists" for this collection.
|
||||||
|
|
|
@ -46,9 +46,15 @@ module Jekyll
|
||||||
].map(&:to_sym)
|
].map(&:to_sym)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def extname_matches_regexp
|
||||||
|
@extname_matches_regexp ||= Regexp.new(
|
||||||
|
'(' + @config['markdown_ext'].gsub(',','|') +')$',
|
||||||
|
Regexp::IGNORECASE
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def matches(ext)
|
def matches(ext)
|
||||||
rgx = '^\.(' + @config['markdown_ext'].gsub(',','|') +')$'
|
ext =~ extname_matches_regexp
|
||||||
ext =~ Regexp.new(rgx, Regexp::IGNORECASE)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def output_ext(ext)
|
def output_ext(ext)
|
||||||
|
|
|
@ -16,9 +16,15 @@ module Jekyll
|
||||||
raise Errors::FatalException.new("Missing dependency: RedCloth")
|
raise Errors::FatalException.new("Missing dependency: RedCloth")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def extname_matches_regexp
|
||||||
|
@extname_matches_regexp ||= Regexp.new(
|
||||||
|
'(' + @config['textile_ext'].gsub(',','|') +')$',
|
||||||
|
Regexp::IGNORECASE
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def matches(ext)
|
def matches(ext)
|
||||||
rgx = '(' + @config['textile_ext'].gsub(',','|') +')'
|
ext =~ extname_matches_regexp
|
||||||
ext =~ Regexp.new(rgx, Regexp::IGNORECASE)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def output_ext(ext)
|
def output_ext(ext)
|
||||||
|
|
|
@ -4,7 +4,7 @@ module Jekyll
|
||||||
class Document
|
class Document
|
||||||
include Comparable
|
include Comparable
|
||||||
|
|
||||||
attr_reader :path, :site
|
attr_reader :path, :site, :extname
|
||||||
attr_accessor :content, :collection, :output
|
attr_accessor :content, :collection, :output
|
||||||
|
|
||||||
# Create a new Document.
|
# Create a new Document.
|
||||||
|
@ -16,6 +16,7 @@ module Jekyll
|
||||||
def initialize(path, relations)
|
def initialize(path, relations)
|
||||||
@site = relations[:site]
|
@site = relations[:site]
|
||||||
@path = path
|
@path = path
|
||||||
|
@extname = File.extname(path)
|
||||||
@collection = relations[:collection]
|
@collection = relations[:collection]
|
||||||
@has_yaml_header = nil
|
@has_yaml_header = nil
|
||||||
end
|
end
|
||||||
|
@ -33,23 +34,21 @@ module Jekyll
|
||||||
# Returns a String path which represents the relative path
|
# Returns a String path which represents the relative path
|
||||||
# from the site source to this document
|
# from the site source to this document
|
||||||
def relative_path
|
def relative_path
|
||||||
Pathname.new(path).relative_path_from(Pathname.new(site.source)).to_s
|
@relative_path ||= Pathname.new(path).relative_path_from(Pathname.new(site.source)).to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
# The base filename of the document, without the file extname.
|
||||||
|
#
|
||||||
|
# Returns the basename without the file extname.
|
||||||
|
def basename_without_ext
|
||||||
|
@basename_without_ext ||= File.basename(path, '.*')
|
||||||
end
|
end
|
||||||
|
|
||||||
# The base filename of the document.
|
# The base filename of the document.
|
||||||
#
|
#
|
||||||
# suffix - (optional) the suffix to be removed from the end of the filename
|
|
||||||
#
|
|
||||||
# Returns the base filename of the document.
|
# Returns the base filename of the document.
|
||||||
def basename(suffix = "")
|
def basename
|
||||||
File.basename(path, suffix)
|
@basename ||= File.basename(path)
|
||||||
end
|
|
||||||
|
|
||||||
# The extension name of the document.
|
|
||||||
#
|
|
||||||
# Returns the extension name of the document.
|
|
||||||
def extname
|
|
||||||
File.extname(path)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Produces a "cleaned" relative path.
|
# Produces a "cleaned" relative path.
|
||||||
|
@ -64,7 +63,8 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns the cleaned relative path of the document.
|
# Returns the cleaned relative path of the document.
|
||||||
def cleaned_relative_path
|
def cleaned_relative_path
|
||||||
relative_path[0 .. -extname.length - 1].sub(collection.relative_directory, "")
|
@cleaned_relative_path ||=
|
||||||
|
relative_path[0 .. -extname.length - 1].sub(collection.relative_directory, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Determine whether the document is a YAML file.
|
# Determine whether the document is a YAML file.
|
||||||
|
@ -129,8 +129,8 @@ module Jekyll
|
||||||
collection: collection.label,
|
collection: collection.label,
|
||||||
path: cleaned_relative_path,
|
path: cleaned_relative_path,
|
||||||
output_ext: Jekyll::Renderer.new(site, self).output_ext,
|
output_ext: Jekyll::Renderer.new(site, self).output_ext,
|
||||||
name: Utils.slugify(basename(".*")),
|
name: Utils.slugify(basename_without_ext),
|
||||||
title: Utils.slugify(data['title']) || Utils.slugify(basename(".*"))
|
title: Utils.slugify(data['title']) || Utils.slugify(basename_without_ext)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,14 @@ module Jekyll
|
||||||
|
|
||||||
class IncludeTag < Liquid::Tag
|
class IncludeTag < Liquid::Tag
|
||||||
|
|
||||||
|
attr_reader :includes_dir
|
||||||
|
|
||||||
VALID_SYNTAX = /([\w-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+))/
|
VALID_SYNTAX = /([\w-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+))/
|
||||||
VARIABLE_SYNTAX = /(?<variable>[^{]*\{\{\s*(?<name>[\w\-\.]+)\s*(\|.*)?\}\}[^\s}]*)(?<params>.*)/
|
VARIABLE_SYNTAX = /(?<variable>[^{]*\{\{\s*(?<name>[\w\-\.]+)\s*(\|.*)?\}\}[^\s}]*)(?<params>.*)/
|
||||||
|
|
||||||
def initialize(tag_name, markup, tokens)
|
def initialize(tag_name, markup, tokens)
|
||||||
super
|
super
|
||||||
|
@includes_dir = tag_includes_dir
|
||||||
matched = markup.strip.match(VARIABLE_SYNTAX)
|
matched = markup.strip.match(VARIABLE_SYNTAX)
|
||||||
if matched
|
if matched
|
||||||
@file = matched['variable'].strip
|
@file = matched['variable'].strip
|
||||||
|
@ -97,7 +100,7 @@ eos
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def includes_dir
|
def tag_includes_dir
|
||||||
'_includes'
|
'_includes'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -118,12 +121,12 @@ eos
|
||||||
partial.render!(context)
|
partial.render!(context)
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
raise IncludeTagError.new e.message, File.join(includes_dir, @file)
|
raise IncludeTagError.new e.message, File.join(@includes_dir, @file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def resolved_includes_dir(context)
|
def resolved_includes_dir(context)
|
||||||
File.join(File.realpath(context.registers[:site].source), includes_dir)
|
File.join(File.realpath(context.registers[:site].source), @includes_dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_path(path, dir, safe)
|
def validate_path(path, dir, safe)
|
||||||
|
@ -135,7 +138,7 @@ eos
|
||||||
end
|
end
|
||||||
|
|
||||||
def path_relative_to_source(dir, path)
|
def path_relative_to_source(dir, path)
|
||||||
File.join(includes_dir, path.sub(Regexp.new("^#{dir}"), ""))
|
File.join(@includes_dir, path.sub(Regexp.new("^#{dir}"), ""))
|
||||||
end
|
end
|
||||||
|
|
||||||
def realpath_prefixed_with?(path, dir)
|
def realpath_prefixed_with?(path, dir)
|
||||||
|
@ -149,13 +152,16 @@ eos
|
||||||
end
|
end
|
||||||
|
|
||||||
class IncludeRelativeTag < IncludeTag
|
class IncludeRelativeTag < IncludeTag
|
||||||
def includes_dir
|
def tag_includes_dir
|
||||||
'.'
|
'.'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def page_path(context)
|
||||||
|
context.registers[:page].nil? ? includes_dir : File.dirname(context.registers[:page]["path"])
|
||||||
|
end
|
||||||
|
|
||||||
def resolved_includes_dir(context)
|
def resolved_includes_dir(context)
|
||||||
page_path = context.registers[:page].nil? ? includes_dir : File.dirname(context.registers[:page]["path"])
|
Jekyll.sanitized_path(context.registers[:site].source, page_path(context))
|
||||||
Jekyll.sanitized_path(context.registers[:site].source, page_path)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,11 +3,14 @@
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
export BENCHMARK=true
|
export BENCHMARK=true
|
||||||
script/bootstrap
|
command -v stackprof > /dev/null || script/bootstrap
|
||||||
|
|
||||||
TEST_SCRIPT="Jekyll::Commands::Build.process({'source' => 'site'})"
|
TEST_SCRIPT="Jekyll::Commands::Build.process({'source' => 'site'})"
|
||||||
PROF_OUTPUT_FILE=tmp/stackprof-$(date +%Y%m%d).dump
|
PROF_OUTPUT_FILE=tmp/stackprof-$(date +%Y%m%d).dump
|
||||||
|
|
||||||
bundle exec ruby -r./lib/jekyll -rstackprof -e "StackProf.run(mode: :cpu, out: '${PROF_OUTPUT_FILE}') { ${TEST_SCRIPT} }"
|
test -f "$PROF_OUTPUT_FILE" || {
|
||||||
|
bundle exec ruby -r./lib/jekyll -rstackprof \
|
||||||
|
-e "StackProf.run(mode: :cpu, out: '${PROF_OUTPUT_FILE}') { ${TEST_SCRIPT} }"
|
||||||
|
}
|
||||||
|
|
||||||
bundle exec stackprof $PROF_OUTPUT_FILE $@
|
bundle exec stackprof $PROF_OUTPUT_FILE $@
|
||||||
|
|
|
@ -25,8 +25,8 @@ class TestDocument < Test::Unit::TestCase
|
||||||
assert_equal "configuration.md", @document.basename
|
assert_equal "configuration.md", @document.basename
|
||||||
end
|
end
|
||||||
|
|
||||||
should "allow the suffix to be specified for the basename" do
|
should "know its basename without extname" do
|
||||||
assert_equal "configuration", @document.basename(".*")
|
assert_equal "configuration", @document.basename_without_ext
|
||||||
end
|
end
|
||||||
|
|
||||||
should "know whether its a yaml file" do
|
should "know whether its a yaml file" do
|
||||||
|
|
Loading…
Reference in New Issue