From 6ed41e373c83a1e34e209da6a4bcaecb3c05a17c Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 16 Apr 2013 02:55:31 +0200 Subject: [PATCH 1/3] Remove code duplication: #write in Page and Post is the same. --- lib/jekyll/convertible.rb | 13 +++++++++++++ lib/jekyll/page.rb | 13 ------------- lib/jekyll/post.rb | 13 ------------- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index dad0b163..015f88b3 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -118,5 +118,18 @@ module Jekyll end end end + + # Write the generated page file to the destination directory. + # + # dest - The String path to the destination dir. + # + # Returns nothing. + def write(dest) + path = destination(dest) + FileUtils.mkdir_p(File.dirname(path)) + File.open(path, 'w') do |f| + f.write(self.output) + end + end end end diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index 4c434564..2f7803d5 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -129,19 +129,6 @@ module Jekyll path end - # Write the generated page file to the destination directory. - # - # dest - The String path to the destination dir. - # - # Returns nothing. - def write(dest) - path = destination(dest) - FileUtils.mkdir_p(File.dirname(path)) - File.open(path, 'w') do |f| - f.write(self.output) - end - end - # Returns the object as a debug String. def inspect "#" diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index c210d235..a7afa800 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -258,19 +258,6 @@ module Jekyll path end - # Write the generated post file to the destination directory. - # - # dest - The String path to the destination dir. - # - # Returns nothing. - def write(dest) - path = destination(dest) - FileUtils.mkdir_p(File.dirname(path)) - File.open(path, 'w') do |f| - f.write(self.output) - end - end - # Convert this post into a Hash for use in Liquid templates. # # Returns the representative Hash. From ba64a9fe306eb629df3765a15bd995444b0ed2c1 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 16 Apr 2013 18:24:10 +0200 Subject: [PATCH 2/3] Fail if destination directory for jekyll new exists and is not empty. Fixes #981. --- lib/jekyll/commands/new.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/jekyll/commands/new.rb b/lib/jekyll/commands/new.rb index e650dc52..c5219e13 100644 --- a/lib/jekyll/commands/new.rb +++ b/lib/jekyll/commands/new.rb @@ -8,6 +8,10 @@ module Jekyll new_blog_path = File.expand_path(args.join(" "), Dir.pwd) FileUtils.mkdir_p new_blog_path + unless Dir["#{new_blog_path}/**/*"].empty? + Jekyll::Logger.error "Conflict:", "#{new_blog_path} exists and is not empty." + exit(1) + end create_sample_files new_blog_path From 24aabbe05f0ceb97a9fc496f843a640f4c8b3e9b Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Mon, 22 Apr 2013 12:57:52 +0200 Subject: [PATCH 3/3] Moving comparison for PostUrl tag to the PostComparer class --- lib/jekyll/tags/post_url.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/jekyll/tags/post_url.rb b/lib/jekyll/tags/post_url.rb index 6dbec9be..dd02d3bf 100644 --- a/lib/jekyll/tags/post_url.rb +++ b/lib/jekyll/tags/post_url.rb @@ -10,6 +10,13 @@ module Jekyll @slug = slug @date = Time.parse(date) end + + def ==(other) + slug == other.slug && + date.year == other.date.year && + date.month == other.date.month && + date.day == other.date.day + end end class PostUrl < Liquid::Tag @@ -23,11 +30,7 @@ module Jekyll site = context.registers[:site] site.posts.each do |p| - if p.slug == @post.slug \ - and p.date.year == @post.date.year \ - and p.date.month == @post.date.month \ - and p.date.day == @post.date.day - + if @post == p return p.url end end