Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

support public_root configuration to help organization static files #474

Closed
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+57 −11
Split
@@ -92,3 +92,11 @@ Feature: Create sites
When I debug jekyll
Then the _site directory should exist
And I should see "Basic Site with include tag: Generated by Jekyll" in "_site/index.html"
+
+ Scenario: Basic site with static file in public root
+ Given I have a configuration file with "public_root" set to "/public"
+ And I have a public directory
+ And I have an "public/more.html" file that contains "To learn more spend time on wiki"
+ When I run jekyll
+ Then the _site directory should exist
+ And I should see "To learn more spend time on wiki" in "_site/more.html"
View
@@ -59,6 +59,7 @@ module Jekyll
'source' => Dir.pwd,
'destination' => File.join(Dir.pwd, '_site'),
'plugins' => File.join(Dir.pwd, '_plugins'),
+ 'public_root' => nil,
'future' => true,
'lsi' => false,
View
@@ -5,7 +5,7 @@ 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, :public_root, :limit_posts
attr_accessor :converters, :generators
@@ -26,6 +26,7 @@ def initialize(config)
self.include = config['include'] || []
self.future = config['future']
self.limit_posts = config['limit_posts'] || nil
+ self.public_root = config['public_root'] || nil
self.reset
self.setup
@@ -140,8 +141,9 @@ def read_directories(dir = '')
# file appears to have a YAML header so process it as a page
pages << Page.new(self, self.source, dir, f)
else
+ destination_dir = self.public_root.nil? ? dir : dir.sub(/^#{Regexp.escape(self.public_root)}/, '')
# otherwise treat it as a static file
- static_files << StaticFile.new(self, self.source, dir, f)
+ static_files << StaticFile.new(self.source, dir, destination_dir, f)
end
end
end
View
@@ -6,20 +6,20 @@ class StaticFile
# Initialize a new StaticFile.
#
- # site - The Site.
# base - The String path to the <source>.
- # dir - The String path between <source> and the file.
+ # source_dir - The String path between <source> and the file.
+ # destination_dir - The String path between <destinations> and the file.
# name - The String filename of the file.
- def initialize(site, base, dir, name)
- @site = site
+ def initialize(base, source_dir, destination_dir, name)
@base = base
- @dir = dir
+ @source_dir = source_dir
+ @destination_dir = destination_dir
@name = name
end
# Returns source file path.
def path
- File.join(@base, @dir, @name)
+ File.join(@base, @source_dir, @name)
end
# Obtain destination path.
@@ -28,7 +28,7 @@ def path
#
# Returns destination file path.
def destination(dest)
- File.join(dest, @dir, @name)
+ File.join(dest, @destination_dir, @name)
end
# Returns last modification time for this file.
@@ -0,0 +1 @@
+to learn more ...
@@ -5,7 +5,7 @@ class TestGeneratedSite < Test::Unit::TestCase
setup do
clear_dest
stub(Jekyll).configuration do
- Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir})
+ Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'public_root' => '/public'})
end
@site = Site.new(Jekyll.configuration)
@@ -40,6 +40,10 @@ class TestGeneratedSite < Test::Unit::TestCase
assert File.exists?(dest_dir('/about/index.html'))
assert File.exists?(dest_dir('/contacts.html'))
end
+
+ should "process static file in public folder" do
+ assert File.exists?(dest_dir('/learnmore.html'))
+ end
end
context "generating limited posts" do
View
@@ -4,7 +4,7 @@ class TestSite < Test::Unit::TestCase
context "creating sites" do
setup do
stub(Jekyll).configuration do
- Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir})
+ Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'public_folder' => '/public'})
end
@site = Site.new(Jekyll.configuration)
end
@@ -92,6 +92,36 @@ class TestSite < Test::Unit::TestCase
assert_equal mtime3, mtime4 # no modifications, so must be the same
end
+ should "write static modified static files from the public root" do
+ clear_dest
+ StaticFile.reset_cache
+
+ @site.process
+ some_static_file = @site.static_files.find{|f| f.path.end_with?('learnmore.html')}
+
+ dest = File.expand_path(some_static_file.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
+
+ # simulate file modification by user
+ FileUtils.touch some_static_file.path
+
+ sleep 1
+ @site.process
+ mtime3 = File.stat(dest).mtime.to_i
+ assert_not_equal mtime2, mtime3 # must be regenerated!
+
+ sleep 1
+ @site.process
+ mtime4 = File.stat(dest).mtime.to_i
+ assert_equal mtime3, mtime4 # no modifications, so must be the same
+ end
+
should "read layouts" do
@site.read_layouts
assert_equal ["default", "simple"].sort, @site.layouts.keys.sort