Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reloading content after partial change, bug fixes

  • Loading branch information...
commit b5f7894f0b928db292d77489eba4c70dccc51580 1 parent 9fc0985
@jdtornow authored
View
2  Rakefile
@@ -16,7 +16,7 @@ end
namespace :test do
desc "Build the sample site and leave its contents in test/sample/public"
task :sample do
- sh %q(turn -I"lib:test" test/test_builder.rb -n /sample/)
+ sh %q(LEAVE_SAMPLE=1 turn -I"lib:test" test/test_builder.rb -n /sample/)
end
end
View
3  lib/plate/builder.rb
@@ -249,6 +249,9 @@ def render_file!(relative_file_path)
if partial
partial.reload!
+
+ puts partial.pages.inspect
+
partial.pages.each do |page|
self.render_file!(page.relative_file)
end
View
17 test/helper.rb
@@ -17,18 +17,23 @@
class Test::Unit::TestCase
def setup
- FileUtils.rm_rf(sample_destination)
+ unless ENV['LEAVE_SAMPLE']
+ FileUtils.rm_rf(sample_destination)
+ FileUtils.rm_rf(sample_source('content/partials/_fake.haml'))
- if File.exists?(sample_source('posts/2012/08/2012-08-01-ready.md'))
- FileUtils.mv(sample_source('posts/2012/08/2012-08-01-ready.md'), sample_source('drafts/2012-08-01-ready.md'))
+ if File.exists?(sample_source('posts/2012/08/2012-08-01-ready.md'))
+ FileUtils.mv(sample_source('posts/2012/08/2012-08-01-ready.md'), sample_source('drafts/2012-08-01-ready.md'))
+ end
end
end
def teardown
- FileUtils.rm_rf(sample_destination)
+ unless ENV['LEAVE_SAMPLE']
+ FileUtils.rm_rf(sample_destination)
- if File.exists?(sample_source('posts/2012/08/2012-08-01-ready.md'))
- FileUtils.mv(sample_source('posts/2012/08/2012-08-01-ready.md'), sample_source('drafts/2012-08-01-ready.md'))
+ if File.exists?(sample_source('posts/2012/08/2012-08-01-ready.md'))
+ FileUtils.mv(sample_source('posts/2012/08/2012-08-01-ready.md'), sample_source('drafts/2012-08-01-ready.md'))
+ end
end
end
View
1  test/sample/content/partials/_fake.haml
@@ -0,0 +1 @@
+Sample fake partial content
View
10 test/sample/content/partials/tester.haml
@@ -3,7 +3,6 @@ title: "Partials Are Fun"
%h1 Partial Test
-
%pre
%strong By name
==========================
@@ -70,4 +69,11 @@ title: "Partials Are Fun"
==========================
= precede 'hash: ' do
- = render :partial => :three, :foo => 1, :nested => { :option => 1 }
+ = render :partial => :three, :foo => 1, :nested => { :option => 1 }
+
+%pre
+ %strong Non-existant partial
+ ==========================
+
+ = precede 'not-found: ' do
+ = render 'partials/fake'
View
8 test/test_builder.rb
@@ -369,6 +369,14 @@ class TestBuilder < Test::Unit::TestCase
# #####################################################################
should "build the sample site" do
+ if ENV['LEAVE_SAMPLE']
+ FileUtils.rm_rf(sample_destination)
+
+ if File.exists?(sample_source('posts/2012/08/2012-08-01-ready.md'))
+ FileUtils.mv(sample_source('posts/2012/08/2012-08-01-ready.md'), sample_source('drafts/2012-08-01-ready.md'))
+ end
+ end
+
builder = Builder.new(sample_source, sample_destination, :cache_location => './test/sample/_cache')
builder.render!
View
51 test/test_partial.rb
@@ -54,5 +54,56 @@ class TestPartial < Test::Unit::TestCase
partial = Partial.find(@site, 'blah')
assert_nil partial
end
+
+ should "reload parent pages when partials are added in watch mode" do
+ fake_path = sample_source('content/partials/_fake.haml')
+
+ FileUtils.rm_rf(fake_path)
+
+ builder = Builder.new(sample_source, sample_destination, :cache_location => './test/sample/_cache')
+ builder.render!
+
+ # Partial is missing by default
+ assert_file_missing(fake_path)
+
+ assert_equal false, builder.site.partials.collect(&:name).include?('partials/fake')
+
+ # So it should not be rendered
+ assert_file_exists sample_destination('/partials/tester/index.html')
+ content = File.read(sample_destination('/partials/tester/index.html'))
+
+ assert content =~ %r{#{Regexp.escape("not-found:</pre>")}}, "Partial 'fake' was rendered and it shouldn't have been"
+
+ # Add the partial (blank)
+ FileUtils.touch(fake_path)
+
+ # And re-render the whole site
+ builder.rebuild!
+
+ # Then the partial should be loaded
+ assert_file_exists(fake_path)
+ assert_equal true, builder.site.partials.collect(&:name).include?('partials/fake')
+
+ # And the content is loaded for that page.
+ assert_file_exists sample_destination('/partials/tester/index.html')
+ content = File.read(sample_destination('/partials/tester/index.html'))
+ assert content =~ %r{#{Regexp.escape("not-found:</pre>")}}, "Partial 'fake' was rendered and it shouldn't have been"
+
+ # Put some content in the partial now.
+ File.open(fake_path, 'w') do |f|
+ f.write('Sample fake partial content')
+ end
+
+ builder.render_file!(fake_path)
+
+ # And the content is reloaded for that page including the new text
+ assert_file_exists sample_destination('/partials/tester/index.html')
+ content = File.read(sample_destination('/partials/tester/index.html'))
+ assert content =~ %r{#{Regexp.escape("not-found:Sample fake partial content</pre>")}}, "Partial 'fake' was rendered blank and it should have content"
+
+ builder.clear_cache!
+
+ FileUtils.rm_rf(fake_path)
+ end
end
end
View
4 test/test_site.rb
@@ -244,7 +244,9 @@ class TestSite < Test::Unit::TestCase
partials/two
)
- assert_equal expected_partials, @site.partials.collect(&:name).sort
+ partial_names = @site.partials.collect(&:name).sort
+
+ assert_equal expected_partials, partial_names
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.