From 6e40338f9ed14fba7bcea33e216d066ca52aa059 Mon Sep 17 00:00:00 2001
From: Parker Moore
Date: Wed, 19 Feb 2014 13:04:33 -0500
Subject: [PATCH 1/9] Expose site.static_files to Liquid
---
lib/jekyll/site.rb | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb
index ed55598f..48e5fa82 100644
--- a/lib/jekyll/site.rb
+++ b/lib/jekyll/site.rb
@@ -307,13 +307,14 @@ module Jekyll
def site_payload
{"jekyll" => { "version" => Jekyll::VERSION },
"site" => self.config.merge({
- "time" => self.time,
- "posts" => self.posts.sort { |a, b| b <=> a },
- "pages" => self.pages,
- "html_pages" => self.pages.reject { |page| !page.html? },
- "categories" => post_attr_hash('categories'),
- "tags" => post_attr_hash('tags'),
- "data" => site_data})}
+ "time" => self.time,
+ "posts" => self.posts.sort { |a, b| b <=> a },
+ "pages" => self.pages,
+ "static_files" => self.static_files
+ "html_pages" => self.pages.reject { |page| !page.html? },
+ "categories" => post_attr_hash('categories'),
+ "tags" => post_attr_hash('tags'),
+ "data" => site_data})}
end
# Filter out any files/directories that are hidden or backup files (start
From 949aa3fc323f37d85942b3f0234d5b0239f4c90f Mon Sep 17 00:00:00 2001
From: Parker Moore
Date: Wed, 19 Feb 2014 13:16:21 -0500
Subject: [PATCH 2/9] Test fetching of static files
---
lib/jekyll/site.rb | 2 +-
test/test_site.rb | 8 ++++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb
index 48e5fa82..ce48366d 100644
--- a/lib/jekyll/site.rb
+++ b/lib/jekyll/site.rb
@@ -310,7 +310,7 @@ module Jekyll
"time" => self.time,
"posts" => self.posts.sort { |a, b| b <=> a },
"pages" => self.pages,
- "static_files" => self.static_files
+ "static_files" => self.static_files,
"html_pages" => self.pages.reject { |page| !page.html? },
"categories" => post_attr_hash('categories'),
"tags" => post_attr_hash('tags'),
diff --git a/test/test_site.rb b/test/test_site.rb
index 7e593c86..7509480f 100644
--- a/test/test_site.rb
+++ b/test/test_site.rb
@@ -169,6 +169,14 @@ class TestSite < Test::Unit::TestCase
assert_equal posts.size - @num_invalid_posts, @site.posts.size
end
+ should "expose jekyll version to site payload" do
+ assert_equal Jekyll::VERSION, @site.site_payload['jekyll']['version']
+ end
+
+ should "expose list of static files to site payload" do
+ assert_equal @site.static_files, @site.site_payload['site']['static_files']
+ end
+
should "deploy payload" do
clear_dest
@site.process
From 9659cfe8763a6cb0748bbecb04ffdb25e088e5a4 Mon Sep 17 00:00:00 2001
From: Parker Moore
Date: Wed, 19 Feb 2014 13:34:44 -0500
Subject: [PATCH 3/9] Test site.static_files
---
test/source/static_files.html | 6 ++++++
test/test_filters.rb | 2 +-
test/test_generated_site.rb | 4 ++++
test/test_site.rb | 19 ++++++++++++++++++-
4 files changed, 29 insertions(+), 2 deletions(-)
create mode 100644 test/source/static_files.html
diff --git a/test/source/static_files.html b/test/source/static_files.html
new file mode 100644
index 00000000..70283c00
--- /dev/null
+++ b/test/source/static_files.html
@@ -0,0 +1,6 @@
+---
+---
+
+{% for file in site.static_files %}
+ - {{ file.path }} last edited at {{ file.modified_time }}
+{% endfor %}
diff --git a/test/test_filters.rb b/test/test_filters.rb
index 1959e6f9..9a514229 100644
--- a/test/test_filters.rb
+++ b/test/test_filters.rb
@@ -131,7 +131,7 @@ class TestFilters < Test::Unit::TestCase
assert_equal 2, g["items"].size
when ""
assert g["items"].is_a?(Array), "The list of grouped items for '' is not an Array."
- assert_equal 9, g["items"].size
+ assert_equal 10, g["items"].size
end
end
end
diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb
index ea20a15f..5df3fd77 100644
--- a/test/test_generated_site.rb
+++ b/test/test_generated_site.rb
@@ -44,6 +44,10 @@ class TestGeneratedSite < Test::Unit::TestCase
assert File.exists?(dest_dir('/about/index.html'))
assert File.exists?(dest_dir('/contacts.html'))
end
+
+ should "print a nice list of static files" do
+ assert_equal "", File.read(dest_dir('static_files.html'))
+ end
end
context "generating limited posts" do
diff --git a/test/test_site.rb b/test/test_site.rb
index 7509480f..a256f91d 100644
--- a/test/test_site.rb
+++ b/test/test_site.rb
@@ -158,7 +158,24 @@ class TestSite < Test::Unit::TestCase
stub.proxy(Dir).entries { |entries| entries.reverse }
@site.process
# files in symlinked directories may appear twice
- sorted_pages = %w(.htaccess about.html bar.html coffeescript.coffee contacts.html deal.with.dots.html exploit.md foo.md index.html index.html main.scss main.scss properties.html sitemap.xml symlinked-file)
+ sorted_pages = %w(
+ .htaccess
+ about.html
+ bar.html
+ coffeescript.coffee
+ contacts.html
+ deal.with.dots.html
+ exploit.md
+ foo.md
+ index.html
+ index.html
+ main.scss
+ main.scss
+ properties.html
+ sitemap.xml
+ static_files.html
+ symlinked-fil
+ )
assert_equal sorted_pages, @site.pages.map(&:name)
end
From b5a398bdffb56c117046110df52db7c30b24955c Mon Sep 17 00:00:00 2001
From: Parker Moore
Date: Wed, 19 Feb 2014 13:35:13 -0500
Subject: [PATCH 4/9] Add StaticFile#to_liquid and StaticFile#relative_path
---
lib/jekyll/static_file.rb | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/lib/jekyll/static_file.rb b/lib/jekyll/static_file.rb
index 3d863ca7..bc39b178 100644
--- a/lib/jekyll/static_file.rb
+++ b/lib/jekyll/static_file.rb
@@ -21,6 +21,11 @@ module Jekyll
File.join(@base, @dir, @name)
end
+ # Returns the source file path relative to the site source
+ def relative_path
+ path.sub(/\A#{@site.source}/, '')
+ end
+
# Obtain destination path.
#
# dest - The String path to the destination dir.
@@ -66,5 +71,12 @@ module Jekyll
@@mtimes = Hash.new
nil
end
+
+ def to_liquid
+ {
+ "path" => relative_path,
+ "modified_time" => mtime.to_s
+ }
+ end
end
end
From d96e62c50f6a7b5e73a1098d10a389edccb9fc13 Mon Sep 17 00:00:00 2001
From: Parker Moore
Date: Wed, 19 Feb 2014 13:35:21 -0500
Subject: [PATCH 5/9] Add docs for site.static_files
---
site/docs/variables.md | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/site/docs/variables.md b/site/docs/variables.md
index 96578311..b150dda7 100644
--- a/site/docs/variables.md
+++ b/site/docs/variables.md
@@ -112,6 +112,16 @@ following is a reference of the available data.
+
+ site.static_files
|
+
+
+ A list of all static files (i.e. files not processed by Jekyll's
+ converters or the Liquid renderer). Each file has two properties:
+ path and modified_time
+
+ |
+
site.categories.CATEGORY
|
From 33490e4efc3e7f3e171fd4df86e8a50abde30d11 Mon Sep 17 00:00:00 2001
From: Parker Moore
Date: Wed, 19 Feb 2014 13:43:16 -0500
Subject: [PATCH 6/9] Fix error in tests.
---
test/test_site.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/test_site.rb b/test/test_site.rb
index a256f91d..c7ba23f9 100644
--- a/test/test_site.rb
+++ b/test/test_site.rb
@@ -174,7 +174,7 @@ class TestSite < Test::Unit::TestCase
properties.html
sitemap.xml
static_files.html
- symlinked-fil
+ symlinked-file
)
assert_equal sorted_pages, @site.pages.map(&:name)
end
From e3dd908d55700bfbc31b0c9df538d6207535910c Mon Sep 17 00:00:00 2001
From: Parker Moore
Date: Wed, 19 Feb 2014 13:55:58 -0500
Subject: [PATCH 7/9] Add StaticFile#to_liquid['extname'] :)
---
lib/jekyll/static_file.rb | 3 ++-
test/source/static_files.html | 4 +---
test/test_generated_site.rb | 7 ++++++-
3 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/lib/jekyll/static_file.rb b/lib/jekyll/static_file.rb
index bc39b178..f7c243ff 100644
--- a/lib/jekyll/static_file.rb
+++ b/lib/jekyll/static_file.rb
@@ -75,7 +75,8 @@ module Jekyll
def to_liquid
{
"path" => relative_path,
- "modified_time" => mtime.to_s
+ "modified_time" => mtime.to_s,
+ "extname" => File.extname(relative_path)
}
end
end
diff --git a/test/source/static_files.html b/test/source/static_files.html
index 70283c00..878b7ebe 100644
--- a/test/source/static_files.html
+++ b/test/source/static_files.html
@@ -1,6 +1,4 @@
---
---
-
{% for file in site.static_files %}
- - {{ file.path }} last edited at {{ file.modified_time }}
-{% endfor %}
+- {{ file.path }} last edited at {{ file.modified_time }} with extname {{ file.extname }}{% endfor %}
diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb
index 5df3fd77..5059dd12 100644
--- a/test/test_generated_site.rb
+++ b/test/test_generated_site.rb
@@ -46,7 +46,12 @@ class TestGeneratedSite < Test::Unit::TestCase
end
should "print a nice list of static files" do
- assert_equal "", File.read(dest_dir('static_files.html'))
+ expected_output = Regexp.new <<-OUTPUT
+- /css/screen.css last edited at \\d+ with extname .css
+- /products.yml last edited at \\d+ with extname .yml
+- /symlink-test/symlinked-dir/screen.css last edited at \\d+ with extname .css
+OUTPUT
+ assert_match expected_output, File.read(dest_dir('static_files.html'))
end
end
From e0166682da368817aedf37ca9d62aca5bc8a10a5 Mon Sep 17 00:00:00 2001
From: Parker Moore
Date: Wed, 19 Feb 2014 14:02:03 -0500
Subject: [PATCH 8/9] Sort the static files by relative path before sending to
liquid
---
lib/jekyll/site.rb | 2 +-
lib/jekyll/static_file.rb | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb
index ce48366d..b39041e6 100644
--- a/lib/jekyll/site.rb
+++ b/lib/jekyll/site.rb
@@ -310,7 +310,7 @@ module Jekyll
"time" => self.time,
"posts" => self.posts.sort { |a, b| b <=> a },
"pages" => self.pages,
- "static_files" => self.static_files,
+ "static_files" => self.static_files.sort { |a, b| a.relative_path <=> b.relative_path },
"html_pages" => self.pages.reject { |page| !page.html? },
"categories" => post_attr_hash('categories'),
"tags" => post_attr_hash('tags'),
diff --git a/lib/jekyll/static_file.rb b/lib/jekyll/static_file.rb
index f7c243ff..dba66739 100644
--- a/lib/jekyll/static_file.rb
+++ b/lib/jekyll/static_file.rb
@@ -23,7 +23,7 @@ module Jekyll
# Returns the source file path relative to the site source
def relative_path
- path.sub(/\A#{@site.source}/, '')
+ @relative_path ||= path.sub(/\A#{@site.source}/, '')
end
# Obtain destination path.
From 88b66858ffb264300df8a9c17ad5c7832b322f66 Mon Sep 17 00:00:00 2001
From: Parker Moore
Date: Wed, 19 Feb 2014 14:15:03 -0500
Subject: [PATCH 9/9] Update docs to include extname for static file object in
liquid. [ci skip]
---
site/docs/variables.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/site/docs/variables.md b/site/docs/variables.md
index b150dda7..32b96693 100644
--- a/site/docs/variables.md
+++ b/site/docs/variables.md
@@ -118,7 +118,7 @@ following is a reference of the available data.
A list of all static files (i.e. files not processed by Jekyll's
converters or the Liquid renderer). Each file has two properties:
- path and modified_time
+ path , modified_time and extname .
|