Merge pull request #2075 from jekyll/expose-static-files

This commit is contained in:
Parker Moore 2014-02-19 14:15:20 -05:00
commit 27be7e2e6a
7 changed files with 71 additions and 9 deletions

View File

@ -310,6 +310,7 @@ module Jekyll
"time" => self.time, "time" => self.time,
"posts" => self.posts.sort { |a, b| b <=> a }, "posts" => self.posts.sort { |a, b| b <=> a },
"pages" => self.pages, "pages" => self.pages,
"static_files" => self.static_files.sort { |a, b| a.relative_path <=> b.relative_path },
"html_pages" => self.pages.reject { |page| !page.html? }, "html_pages" => self.pages.reject { |page| !page.html? },
"categories" => post_attr_hash('categories'), "categories" => post_attr_hash('categories'),
"tags" => post_attr_hash('tags'), "tags" => post_attr_hash('tags'),

View File

@ -21,6 +21,11 @@ module Jekyll
File.join(@base, @dir, @name) File.join(@base, @dir, @name)
end end
# Returns the source file path relative to the site source
def relative_path
@relative_path ||= path.sub(/\A#{@site.source}/, '')
end
# Obtain destination path. # Obtain destination path.
# #
# dest - The String path to the destination dir. # dest - The String path to the destination dir.
@ -66,5 +71,13 @@ module Jekyll
@@mtimes = Hash.new @@mtimes = Hash.new
nil nil
end end
def to_liquid
{
"path" => relative_path,
"modified_time" => mtime.to_s,
"extname" => File.extname(relative_path)
}
end
end end
end end

View File

@ -112,6 +112,16 @@ following is a reference of the available data.
</p></td> </p></td>
</tr> </tr>
<tr>
<td><p><code>site.static_files</code></p></td>
<td><p>
A list of all static files (i.e. files not processed by Jekyll's
converters or the Liquid renderer). Each file has two properties:
<code>path</code>, <code>modified_time</code> and <code>extname</code>.
</p></td>
</tr>
<tr> <tr>
<td><p><code>site.categories.CATEGORY</code></p></td> <td><p><code>site.categories.CATEGORY</code></p></td>
<td><p> <td><p>

View File

@ -0,0 +1,4 @@
---
---
{% for file in site.static_files %}
- {{ file.path }} last edited at {{ file.modified_time }} with extname {{ file.extname }}{% endfor %}

View File

@ -131,7 +131,7 @@ class TestFilters < Test::Unit::TestCase
assert_equal 2, g["items"].size assert_equal 2, g["items"].size
when "" when ""
assert g["items"].is_a?(Array), "The list of grouped items for '' is not an Array." 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 end
end end

View File

@ -44,6 +44,15 @@ class TestGeneratedSite < Test::Unit::TestCase
assert File.exists?(dest_dir('/about/index.html')) assert File.exists?(dest_dir('/about/index.html'))
assert File.exists?(dest_dir('/contacts.html')) assert File.exists?(dest_dir('/contacts.html'))
end end
should "print a nice list of static files" do
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 end
context "generating limited posts" do context "generating limited posts" do

View File

@ -158,7 +158,24 @@ class TestSite < Test::Unit::TestCase
stub.proxy(Dir).entries { |entries| entries.reverse } stub.proxy(Dir).entries { |entries| entries.reverse }
@site.process @site.process
# files in symlinked directories may appear twice # 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-file
)
assert_equal sorted_pages, @site.pages.map(&:name) assert_equal sorted_pages, @site.pages.map(&:name)
end end
@ -169,6 +186,14 @@ class TestSite < Test::Unit::TestCase
assert_equal posts.size - @num_invalid_posts, @site.posts.size assert_equal posts.size - @num_invalid_posts, @site.posts.size
end 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 should "deploy payload" do
clear_dest clear_dest
@site.process @site.process