Merge pull request #3592 from nickburlett/patch/incremental-build
Merge pull request 3592
This commit is contained in:
commit
e91527058a
|
@ -9,7 +9,7 @@ module Jekyll
|
||||||
read_metadata
|
read_metadata
|
||||||
|
|
||||||
# Initialize cache to an empty hash
|
# Initialize cache to an empty hash
|
||||||
@cache = {}
|
clear_cache
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks if a renderable object needs to be regenerated
|
# Checks if a renderable object needs to be regenerated
|
||||||
|
@ -56,6 +56,14 @@ module Jekyll
|
||||||
# Returns nothing
|
# Returns nothing
|
||||||
def clear
|
def clear
|
||||||
@metadata = {}
|
@metadata = {}
|
||||||
|
clear_cache
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# Clear just the cache
|
||||||
|
#
|
||||||
|
# Returns nothing
|
||||||
|
def clear_cache
|
||||||
@cache = {}
|
@cache = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,7 @@ module Jekyll
|
||||||
self.static_files = []
|
self.static_files = []
|
||||||
self.data = {}
|
self.data = {}
|
||||||
@collections = nil
|
@collections = nil
|
||||||
|
@regenerator.clear_cache()
|
||||||
|
|
||||||
if limit_posts < 0
|
if limit_posts < 0
|
||||||
raise ArgumentError, "limit_posts must be a non-negative number"
|
raise ArgumentError, "limit_posts must be a non-negative number"
|
||||||
|
|
|
@ -75,6 +75,15 @@ class TestRegenerator < JekyllUnitTest
|
||||||
assert @regenerator.cache[@path]
|
assert @regenerator.cache[@path]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "clear the cache on clear_cache" do
|
||||||
|
# @path will be in the cache because the
|
||||||
|
# site will have processed it
|
||||||
|
assert @regenerator.cache[@path]
|
||||||
|
|
||||||
|
@regenerator.clear_cache
|
||||||
|
assert_equal @regenerator.cache, {}
|
||||||
|
end
|
||||||
|
|
||||||
should "write to the metadata file" do
|
should "write to the metadata file" do
|
||||||
@regenerator.clear
|
@regenerator.clear
|
||||||
@regenerator.add(@path)
|
@regenerator.add(@path)
|
||||||
|
|
|
@ -459,5 +459,43 @@ class TestSite < JekyllUnitTest
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "incremental build" do
|
||||||
|
setup do
|
||||||
|
@site = Site.new(site_configuration({
|
||||||
|
'full_rebuild' => false
|
||||||
|
}))
|
||||||
|
@site.read
|
||||||
|
end
|
||||||
|
|
||||||
|
should "build incrementally" do
|
||||||
|
contacts_html = @site.pages.find { |p| p.name == "contacts.html" }
|
||||||
|
@site.process
|
||||||
|
|
||||||
|
source = @site.in_source_dir(contacts_html.path)
|
||||||
|
dest = File.expand_path(contacts_html.destination(@site.dest))
|
||||||
|
mtime1 = File.stat(dest).mtime.to_i # first run must generate dest file
|
||||||
|
|
||||||
|
# need to sleep because filesystem timestamps have best resolution in seconds
|
||||||
|
sleep 1
|
||||||
|
@site.process
|
||||||
|
mtime2 = File.stat(dest).mtime.to_i
|
||||||
|
assert_equal mtime1, mtime2 # no modifications, so remain the same
|
||||||
|
|
||||||
|
# simulate file modification by user
|
||||||
|
FileUtils.touch source
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
@site.process
|
||||||
|
mtime3 = File.stat(dest).mtime.to_i
|
||||||
|
refute_equal mtime2, mtime3 # must be regenerated
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
@site.process
|
||||||
|
mtime4 = File.stat(dest).mtime.to_i
|
||||||
|
assert_equal mtime3, mtime4 # no modifications, so remain the same
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue