From df2ad2ac595d3ed5d998108cc3b55fb0eef97bf0 Mon Sep 17 00:00:00 2001 From: Tom Bell Date: Wed, 30 May 2012 21:39:43 -0400 Subject: [PATCH] Allow a custom 'layouts' directory * Add 'layouts' option to change the dir from '_layouts' to anything relative to the source directory * Add cucumber scenario for testing an alternative directory '_theme' * Closes #563 --- features/site_configuration.feature | 21 +++++++++++++++++++++ features/step_definitions/jekyll_steps.rb | 7 +++++++ lib/jekyll.rb | 1 + lib/jekyll/site.rb | 2 +- 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/features/site_configuration.feature b/features/site_configuration.feature index 6935af3d..5a83ee80 100644 --- a/features/site_configuration.feature +++ b/features/site_configuration.feature @@ -143,3 +143,24 @@ Feature: Site configuration Then the _site directory should exist And I should see ".DS_Store" in "_site/.gitignore" And the "_site/.htaccess" file should not exist + + Scenario: Using a different layouts directory + Given I have a _theme directory + And I have a page theme that contains "Page Layout: {{ site.posts.size }} on {{ site.time | date: "%Y-%m-%d" }}" + And I have a post theme that contains "Post Layout: {{ content }}" + And I have an "index.html" page with layout "page" that contains "site index page" + And I have a configuration file with: + | key | value | + | time | 2010-01-01 | + | future | true | + | layouts | _theme | + And I have a _posts directory + And I have the following posts: + | title | date | layout | content | + | entry1 | 12/31/2007 | post | content for entry1. | + | entry2 | 01/31/2020 | post | content for entry2. | + When I run jekyll + Then the _site directory should exist + And I should see "Page Layout: 2 on 2010-01-01" in "_site/index.html" + And I should see "Post Layout:

content for entry1.

" in "_site/2007/12/31/entry1.html" + And I should see "Post Layout:

content for entry2.

" in "_site/2020/01/31/entry2.html" diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 29abccec..20128964 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -39,6 +39,13 @@ Given /^I have a (.*) layout that contains "(.*)"$/ do |layout, text| end end +Given /^I have a (.*) theme that contains "(.*)"$/ do |layout, text| + File.open(File.join('_theme', layout + '.html'), 'w') do |f| + f.write(text) + f.close + end +end + Given /^I have an? (.*) directory$/ do |dir| FileUtils.mkdir_p(dir) end diff --git a/lib/jekyll.rb b/lib/jekyll.rb index fd455fb5..30fcdfd6 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -59,6 +59,7 @@ module Jekyll 'source' => Dir.pwd, 'destination' => File.join(Dir.pwd, '_site'), 'plugins' => File.join(Dir.pwd, '_plugins'), + 'layouts' => '_layouts', 'future' => true, 'lsi' => false, diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 8d989b21..19480119 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -106,7 +106,7 @@ module Jekyll # # Returns nothing. def read_layouts(dir = '') - base = File.join(self.source, dir, "_layouts") + base = File.join(self.source, dir, self.config['layouts']) return unless File.exists?(base) entries = [] Dir.chdir(base) { entries = filter_entries(Dir['*.*']) }