Browse files

Added a configuration variable: keep_files (default: ['.git']), based…

… on this pull request: jekyll#556
  • Loading branch information...
1 parent fa8400a commit 7c800d3b0753b76e0880853728ef87abd00e01ca @edeustace committed Aug 23, 2012
Showing with 54 additions and 4 deletions.
  1. +5 −0 bin/jekyll
  2. +5 −2 jekyll.gemspec
  3. +1 −0 lib/jekyll.rb
  4. +16 −2 lib/jekyll/site.rb
  5. +27 −0 test/test_site.rb
View
5 bin/jekyll
@@ -145,6 +145,11 @@ opts = OptionParser.new do |opts|
puts "Jekyll " + Jekyll::VERSION
exit 0
end
+
+ opts.on( "--keep-files filename1,filename2", Array, "Whether to keep files that match the filename (default: .git)") do |names|
+ puts "keep-files option: #{names}"
+ options['keep_files'] = names
+ end
end
# Read command line options into `options` hash
View
7 jekyll.gemspec
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
s.name = 'jekyll'
s.version = '0.11.2'
- s.date = '2011-12-27'
+ s.date = '2012-08-23'
s.rubyforge_project = 'jekyll'
s.summary = "A simple, blog aware, static site generator."
@@ -74,10 +74,12 @@ Gem::Specification.new do |s|
lib/jekyll/migrators/csv.rb
lib/jekyll/migrators/drupal.rb
lib/jekyll/migrators/enki.rb
+ lib/jekyll/migrators/joomla.rb
lib/jekyll/migrators/marley.rb
lib/jekyll/migrators/mephisto.rb
lib/jekyll/migrators/mt.rb
lib/jekyll/migrators/posterous.rb
+ lib/jekyll/migrators/rss.rb
lib/jekyll/migrators/textpattern.rb
lib/jekyll/migrators/tumblr.rb
lib/jekyll/migrators/typo.rb
@@ -90,6 +92,7 @@ Gem::Specification.new do |s|
lib/jekyll/static_file.rb
lib/jekyll/tags/highlight.rb
lib/jekyll/tags/include.rb
+ lib/jekyll/tags/post_url.rb
test/helper.rb
test/source/.htaccess
test/source/_includes/sig.markdown
@@ -141,9 +144,9 @@ Gem::Specification.new do |s|
test/test_post.rb
test/test_rdiscount.rb
test/test_redcarpet.rb
+ test/test_redcloth.rb
@parkr
parkr added a note Dec 8, 2012

Nicely alphabetized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
test/test_site.rb
test/test_tags.rb
- test/test_redcloth.rb
]
# = MANIFEST =
View
1 lib/jekyll.rb
@@ -59,6 +59,7 @@ module Jekyll
'source' => Dir.pwd,
'destination' => File.join(Dir.pwd, '_site'),
'plugins' => File.join(Dir.pwd, '_plugins'),
+ 'keep_files' => ['.git'],
@parkr
parkr added a note Dec 8, 2012

Maybe we should add '.svn'?

@mattr-
mattr- added a note Dec 19, 2012

I'd say 'yes', at least for the corporate environments (like mine) where svn is the standard and the use of git is nonexistant (sadly).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
'layouts' => '_layouts',
'future' => true,
View
18 lib/jekyll/site.rb
@@ -5,7 +5,8 @@ module Jekyll
class Site
attr_accessor :config, :layouts, :posts, :pages, :static_files,
:categories, :exclude, :include, :source, :dest, :lsi, :pygments,
- :permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts
+ :permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts,
+ :keep_files
attr_accessor :converters, :generators
@@ -26,6 +27,7 @@ def initialize(config)
self.include = config['include'] || []
self.future = config['future']
self.limit_posts = config['limit_posts'] || nil
+ self.keep_files = config['keep_files'] || []
self.reset
self.setup
@@ -217,7 +219,11 @@ def cleanup
# all files and directories in destination, including hidden ones
dest_files = Set.new
Dir.glob(File.join(self.dest, "**", "*"), File::FNM_DOTMATCH) do |file|
- dest_files << file unless file =~ /\/\.{1,2}$/
+ if self.keep_files.length > 0
+ dest_files << file unless file =~ /\/\.{1,2}$/ or file =~ keep_file_regex
+ else
+ dest_files << file unless file =~ /\/\.{1,2}$/
+ end
end
# files to be written
@@ -242,6 +248,14 @@ def cleanup
FileUtils.rm_rf(obsolete_files.to_a)
end
+ # create a regex from the keep_files array
+ # ['.git','.svn'] => /\/(\.git|\/.svn)/
+ def keep_file_regex
+ or_list = self.keep_files.map.inject("") { |x,y| "#{x}|#{y}" }[1..-1]
@parkr
parkr added a note Dec 8, 2012

Thoughts on using or_list = self.keep_files.join("|")?

In this case, it produces the exact same output.

@mattr-
mattr- added a note Dec 19, 2012

👍 to this. More understandable that way too. The current line just makes my head hurt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ pattern = "\/(#{or_list.gsub(".", "\.")})"
+ Regexp.new pattern
+ end
+
# Write static files, pages, and posts.
#
# Returns nothing.
View
27 test/test_site.rb
@@ -180,13 +180,23 @@ class TestSite < Test::Unit::TestCase
File.open(dest_dir('qux/obsolete.html'), 'w')
# empty directory
FileUtils.mkdir(dest_dir('quux'))
+ FileUtils.mkdir(dest_dir('.git'))
+ FileUtils.mkdir(dest_dir('.svn'))
+ FileUtils.mkdir(dest_dir('.hg'))
+ # single file in repository
+ File.open(dest_dir('.git/HEAD'), 'w')
+ File.open(dest_dir('.svn/HEAD'), 'w')
+ File.open(dest_dir('.hg/HEAD'), 'w')
end
teardown do
FileUtils.rm_f(dest_dir('.htpasswd'))
FileUtils.rm_f(dest_dir('obsolete.html'))
FileUtils.rm_rf(dest_dir('qux'))
FileUtils.rm_f(dest_dir('quux'))
+ FileUtils.rm_rf(dest_dir('.git'))
+ FileUtils.rm_rf(dest_dir('.svn'))
+ FileUtils.rm_rf(dest_dir('.hg'))
end
should 'remove orphaned files in destination' do
@@ -195,6 +205,23 @@ class TestSite < Test::Unit::TestCase
assert !File.exist?(dest_dir('obsolete.html'))
assert !File.exist?(dest_dir('qux'))
assert !File.exist?(dest_dir('quux'))
+ assert File.exist?(dest_dir('.git'))
+ assert File.exist?(dest_dir('.git/HEAD'))
+ end
+
+ should 'remove orphaned files in destination - keep_files .svn' do
@mattr-
mattr- added a note Dec 19, 2012

I think I would rename this to something like:

should 'recursively keeps files as specified in the config' do

or something like that, just to make the test case description more - heh - descriptive, but I'm not really bothered by the current description either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ config = Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'keep_files' => ['.svn']})
+ @site = Site.new(config)
+ @site.process
+ assert !File.exist?(dest_dir('.htpasswd'))
+ assert !File.exist?(dest_dir('obsolete.html'))
+ assert !File.exist?(dest_dir('qux'))
+ assert !File.exist?(dest_dir('quux'))
+ assert !File.exist?(dest_dir('.git'))
+ assert !File.exist?(dest_dir('.git/HEAD'))
+ assert File.exist?(dest_dir('.svn'))
+ assert File.exist?(dest_dir('.svn/HEAD'))
end
end

0 comments on commit 7c800d3

Please sign in to comment.