diff --git a/features/include_tag.feature b/features/include_tag.feature index c7e03ded..427c1bb4 100644 --- a/features/include_tag.feature +++ b/features/include_tag.feature @@ -77,3 +77,15 @@ Feature: Include tags When I run jekyll build Then the _site directory should exist And I should see "one included" in "_site/index.html" + + Scenario: Include a file and rebuild when include content is changed + Given I have an _includes directory + And I have an "_includes/one.html" file that contains "include" + And I have an "index.html" page that contains "{% include one.html %}" + When I run jekyll build + Then the _site directory should exist + And I should see "include" in "_site/index.html" + When I wait 1 second + Then I have an "_includes/one.html" file that contains "include content changed" + When I run jekyll build + Then I should see "include content changed" in "_site/index.html" diff --git a/lib/jekyll/tags/include.rb b/lib/jekyll/tags/include.rb index 92ce7c62..0e944407 100644 --- a/lib/jekyll/tags/include.rb +++ b/lib/jekyll/tags/include.rb @@ -123,7 +123,7 @@ eos end begin - partial = site.liquid_renderer.file(path).parse(read_file(path, context)) + partial = load_cached_partial(path, context) context.stack do context['include'] = parse_params(context) if @params @@ -134,6 +134,17 @@ eos end end + def load_cached_partial(path, context) + context.registers[:cached_partials] ||= {} + cached_partial = context.registers[:cached_partials] + + if cached_partial.has_key?(path) + cached_partial[path] + else + cached_partial[path] = context.registers[:site].liquid_renderer.file(path).parse(read_file(path, context)) + end + end + def resolved_includes_dir(context) context.registers[:site].in_source_dir(@includes_dir) end