Compare commits

...

51 Commits

Author SHA1 Message Date
Parker Moore
23be0d58b1 Release 💎 3.1.5 2016-05-18 21:21:02 -07:00
Parker Moore
eefbcf7cf4 Release 💎 v3.1.5 2016-05-18 21:20:57 -07:00
Parker Moore
cafbd83e55 Merge pull request #4912 from jekyll/3.1-sort-includes
Sort the results of the require_all glob.
2016-05-18 21:19:40 -07:00
Parker Moore
b48e6b342c lib/jekyll.rb: require document_drop to ease our pain 2016-05-18 21:11:14 -07:00
Parker Moore
539213ac11 Sort the results of the require_all glob.
Filesystems behave differently when performing glob listings.

In my environment, they are listed alphabetically. On my Mac, when asking for a list of files in a directory, those files are returned as a nicely sorted list. Alphabetized, like you'd want them to be. Like you'd expect them to be.

In some environments, quite different from my own, the return of a similar operation is quite random. Perhaps q comes before a, or e before d; the filesystem will choose its order of the day and you, the fare user, tired and weary from work, must bare the brunt of this.

And so, with this commit, I do hereby request that the noble makers of Dir[] provide for us, the downtrodden and ravaged users, some consistency. As a user of Ruby, I shouldn't have to know or consider the behaviour of an individual filesystem here; it should function the same for all filesystems.

Truly yours,
Parker
2016-05-18 18:54:49 -07:00
Parker Moore
0423633cfb Release 💎 3.1.4 2016-05-18 15:51:59 -07:00
Parker Moore
cc21d9cec9 Release 💎 v3.1.4 2016-05-18 15:51:55 -07:00
Parker Moore
928df67775 Update history to reflect merge of #4909 2016-05-18 15:45:57 -07:00
Parker Moore
21c563c0ff Merge pull request #4909 from jekyll/3.1-fix-layout-var-overflow
3.1: Fix `{{ layout }}` oddities (proper inheritance & fixing overflow of old data)
2016-05-18 15:34:53 -07:00
Parker Moore
c0f0a72f15 Update history to reflect the merge of #4910 2016-05-18 15:30:51 -07:00
Parker Moore
268c4a6cbc Merge pull request #4910 from jekyll/3.1-configuration-from-permalink-fix
3.1: Configuration permalink fix and addition of Configuration.from and sorting `site.collections` by label
2016-05-18 15:20:52 -07:00
Parker Moore
1b32c84e5f Fix tests for plugins in configuration. 2016-05-18 14:49:21 -07:00
Parker Moore
145afae307 Define Drop#each so we can use the new frozen/duping behavior 2016-05-18 12:53:08 -07:00
Parker Moore
8fae81861d Don't default 'include' and 'exclude' to an empty array 2016-05-18 12:49:23 -07:00
Parker Moore
3b6fb90b31 Fix some minor things in the tests 2016-05-18 12:49:06 -07:00
Parker Moore
c416495539 Freeze configuration defaults & duplicate in deep_merge_hashes if need be. 2016-05-18 12:48:42 -07:00
Parker Moore
ebf8be2de1 Remove merge conflicts I forgot to fix. 2016-05-18 11:36:57 -07:00
Parker Moore
cec9e510f2 Add missing 'end' to test/helper.rb 2016-05-18 11:31:22 -07:00
Parker Moore
644a760936 Remove call to #backwards_compatibilize in Configuration.from 2016-05-18 11:18:43 -07:00
Parker Moore
09ef65e49b Site#site_payload: sort collections by label 2016-05-18 11:16:26 -07:00
Parker Moore
4ed03641b7 Configuration#add_default_collections: fix bug where DEFAULTS['collections'] is modified 2016-05-18 10:58:38 -07:00
Parker Moore
0a733d4fbb Add Configuration.from & use in Jekyll.configuration.
This process streamlines the creation of new configurations. Creating a new
site will choke if not all the correct options are given.
Configuration.from will ensure the overrides have all string keys and
ensures all the common issues & defaults are in place so a Site can be
created.

A common use:

    config = Configuration.from({ 'permalink' => '/:title/' }) # etc
    site = Jekyll::Site.new(config)
2016-05-18 10:58:26 -07:00
Parker Moore
040040b980 Remove use of Marshal in runtime code. 2016-05-18 10:56:32 -07:00
Parker Moore
96feb89df0 Add tests for Configuration#add_default_collections 2016-05-18 10:55:43 -07:00
Parker Moore
cc5996afd2 Don't read a config file if the filename is empty. 2016-05-18 10:50:20 -07:00
Parker Moore
bfdf3e0d9b Use Marshal to duplicate configuration defaults to prevent manipulation 2016-05-18 10:50:11 -07:00
Parker Moore
827ec88c99 Refactor some tests to prevent manipulation of Jekyll::Config::DEFAULTS 2016-05-18 10:48:34 -07:00
Parker Moore
7baf560016 Only write collections.posts.permalink if permalink is set. 2016-05-18 10:47:35 -07:00
Parker Moore
aeadbfc6c0 Test#build_configs shouldn't overwrite default collections 2016-05-18 10:43:55 -07:00
Parker Moore
7ed3778756 Update history to reflect the merge of #4907 2016-05-18 10:43:26 -07:00
Parker Moore
be9226b4e8 Reset {{ layout }} between each render & merge layout data properly 2016-05-18 09:58:48 -07:00
Parker Moore
d09684dcb2 Add failing test for layout data inheritance bug (#4433) 2016-05-18 09:58:20 -07:00
Parker Moore
b46f8d0adf Add failing test for layout bug (#4897) 2016-05-18 09:48:09 -07:00
Parker Moore
43ceaf8c28 Update gemfile to specify rubocop version and require env before adding jekyll-docs 2016-05-18 09:43:53 -07:00
Parker Moore
f99ffe5bf1 Merge pull request #4907 from jekyll/3.1-page-excerpt-bug
Add ExcerptDrop and remove excerpt's ability to refer to itself in Liquid
2016-05-18 09:42:29 -07:00
Parker Moore
400a8d7b48 excerpt drop should give access to document's layout 2016-05-17 16:58:26 -07:00
Parker Moore
d6c972a9ba look up the content methods for drops in a smarter way 2016-05-17 16:58:06 -07:00
Parker Moore
aadf43727e travis: just run our builds, darn it 2016-05-17 16:57:33 -07:00
Parker Moore
fe5f9d80df Merge branch '3.1-page-excerpt-bug' of github.com:jekyll/jekyll into 3.1-page-excerpt-bug
* '3.1-page-excerpt-bug' of github.com:jekyll/jekyll:
  Use require_relative
2016-05-17 16:44:05 -07:00
Parker Moore
0dabdfb159 Run builds on this branch. 2016-05-17 16:43:53 -07:00
Parker Moore
e23520c793 Use require_relative 2016-05-17 16:42:35 -07:00
Parker Moore
e19e1629ba Add ExcerptDrop and remove excerpt's ability to refer to itself in Liquid 2016-05-17 14:38:15 -07:00
Parker Moore
6e208e89e6 Release 💎 3.1.3 2016-04-18 14:28:21 -07:00
Parker Moore
b962ed63a4 Allow release from here 2016-04-18 14:28:14 -07:00
Parker Moore
c4e452323e Release v3.1.3 2016-04-18 14:25:09 -07:00
Parker Moore
787f11de71 Merge pull request #4807 from jekyll/3.1-stable-fix-defaults
3.1.x: Fix defaults for Documents (posts/collection docs)
2016-04-18 14:24:37 -07:00
Parker Moore
b64345f0a0 test_document: scopes are based on relative_path 2016-04-18 13:54:16 -07:00
Parker Moore
50637ba0d4 Document#read: frontmatter.all should get relative_path not URL 2016-04-18 13:54:10 -07:00
Florian Thomas
e763d4c4b2 add failing test for scope values in subdirs
ref #4458
2016-04-18 13:54:05 -07:00
Parker Moore
bd2d9a4642 Merge pull request #4693 from jekyll/bug/fix-ssl-opts
Fix #4689: Use SSLEnable instead of EnableSSL and make URL HTTPS.
2016-03-22 16:09:12 -07:00
Jordon Bedwell
2b9e849bbb Fix #4689: Use SSLEnable instead of EnableSSL and make URL HTTPS. 2016-03-21 11:23:26 -05:00
29 changed files with 425 additions and 127 deletions

View File

@@ -23,10 +23,6 @@ env:
- TEST_SUITE=test
- TEST_SUITE=cucumber
branches:
only:
- master
notifications:
irc:
template: "%{repository}#%{build_number} (%{branch}) %{message} %{build_url}"

View File

@@ -4,7 +4,7 @@ gemspec :name => "jekyll"
gem "rake", "~> 10.1"
group :development do
gem "launchy", "~> 2.3"
gem "rubocop", :branch => :master, :github => "bbatsov/rubocop"
gem "rubocop", "~> 0.40"
gem "pry"
unless RUBY_ENGINE == "jruby"
@@ -55,7 +55,7 @@ end
group :jekyll_optional_dependencies do
gem "toml", "~> 0.1.0"
gem "coderay", "~> 1.1.0"
gem "jekyll-docs", path: '../docs' if Dir.exist?('../docs')
gem "jekyll-docs", path: '../docs' if Dir.exist?('../docs') && ENV["JEKYLL_VERSION"]
gem "jekyll-gist", "~> 1.0"
gem "jekyll-feed", "~> 0.1.3"
gem "jekyll-coffeescript", "~> 1.0"

View File

@@ -1,3 +1,20 @@
## 3.1.5 / 2016-05-18
### Bug Fixes
* Sort the results of the `require_all` glob (affects Linux only). (#4912)
## 3.1.4 / 2016-05-18
### Bug Fixes
* Add `ExcerptDrop` and remove excerpt's ability to refer to itself in Liquid (#4907)
* Configuration permalink fix where `collections.posts.permalink` inherits properly from `permalink` only when it doesn't exist (#4910)
* Add `Configuration.from` to make it easier to build configs from just a hash
* Sorting `site.collections` in Liquid by label (#4910)
* Fix bug where `layout` in Liquid would inherit from previously-rendered layouts' metadatas (#4909)
* Fix bug where `layout` in Liquid would override in the wrong direction (more-specific layouts' data were overwritten by their parent layouts' data; this has now been reversed) (#4909)
## 3.1.2 / 2016-02-19
### Minor Enhancements

View File

@@ -80,6 +80,26 @@ Feature: frontmatter defaults
And I should see "main: <p>content of site/special/2013/10/14/about1.html</p>" in "_site/special/2013/10/14/about1.html"
And I should see "main: <p>content of site/special/2013/10/14/about2.html</p>" in "_site/special/2013/10/14/about2.html"
Scenario: Use frontmatter scopes for subdirectories
Given I have a _layouts directory
And I have a main layout that contains "main: {{ content }}"
And I have a _posts/en directory
And I have the following post under "en":
| title | date | content |
| helloworld | 2014-09-01 | {{page.lang}} is the current language |
And I have a _posts/de directory
And I have the following post under "de":
| title | date | content |
| hallowelt | 2014-09-01 | {{page.lang}} is the current language |
And I have a configuration file with "defaults" set to "[{scope: {path: "_posts/en"}, values: {layout: "main", lang: "en"}}, {scope: {path: "_posts/de"}, values: {layout: "main", lang: "de"}}]"
When I run jekyll build
Then the _site directory should exist
And I should see "main: <p>en is the current language</p>" in "_site/2014/09/01/helloworld.html"
And I should see "main: <p>de is the current language</p>" in "_site/2014/09/01/hallowelt.html"
Scenario: Override frontmatter defaults by type
Given I have a _posts directory
And I have the following post:

View File

@@ -35,3 +35,36 @@ Feature: Layout data
When I run jekyll build
Then the "_site/index.html" file should exist
And I should see "page content\n foo: my custom data" in "_site/index.html"
Scenario: Inherit custom layout data and clear when not present
Given I have a _layouts directory
And I have a "_layouts/default.html" file with content:
"""
---
bar: i'm default
---
{{ content }} foo: '{{ layout.foo }}' bar: '{{ layout.bar }}'
"""
And I have a "_layouts/special.html" file with content:
"""
---
layout: default
foo: my special data
bar: im special
---
{{ content }}
"""
And I have a "_layouts/page.html" file with content:
"""
---
layout: default
bar: im page
---
{{ content }}
"""
And I have an "index.html" page with layout "special" that contains "page content"
And I have an "jekyll.html" page with layout "page" that contains "page content"
When I run jekyll build
Then the "_site/index.html" file should exist
And I should see "page content\n foo: 'my special data' bar: 'im special'" in "_site/index.html"
And I should see "page content\n foo: '' bar: 'im page'" in "_site/jekyll.html"

View File

@@ -7,7 +7,7 @@ $LOAD_PATH.unshift File.dirname(__FILE__) # For use/testing when no gem is insta
# Returns nothing.
def require_all(path)
glob = File.join(File.dirname(__FILE__), path, '*.rb')
Dir[glob].each do |f|
Dir[glob].sort.each do |f|
require f
end
end
@@ -95,18 +95,16 @@ module Jekyll
# list of option names and their defaults.
#
# Returns the final configuration Hash.
def configuration(override = {})
config = Configuration[Configuration::DEFAULTS]
override = Configuration[override].stringify_keys
def configuration(override = Hash.new)
config = Configuration.new
unless override.delete('skip_config_files')
config = config.read_config_files(config.config_files(override))
end
# Merge DEFAULTS < _config.yml < override
config = Utils.deep_merge_hashes(config, override).stringify_keys
set_timezone(config['timezone']) if config['timezone']
config
Configuration.from(Utils.deep_merge_hashes(config, override)).tap do |config|
set_timezone(config['timezone']) if config['timezone']
end
end
# Public: Set the TZ environment variable to use the timezone specified
@@ -170,6 +168,7 @@ module Jekyll
end
require "jekyll/drops/drop"
require "jekyll/drops/document_drop"
require_all 'jekyll/commands'
require_all 'jekyll/converters'
require_all 'jekyll/converters/markdown'

View File

@@ -112,11 +112,12 @@ module Jekyll
private
def server_address(server, opts)
address = server.config[:BindAddress]
baseurl = "#{opts["baseurl"]}/" if opts["baseurl"]
port = server.config[:Port]
"http://#{address}:#{port}#{baseurl}"
"%{prefix}://%{address}:%{port}%{baseurl}" % {
:prefix => server.config[:SSLEnable] ? "https" : "http",
:baseurl => opts["baseurl"] ? "#{opts["baseurl"]}/" : "",
:address => server.config[:BindAddress],
:port => server.config[:Port]
}
end
#
@@ -181,7 +182,7 @@ module Jekyll
source_certificate = Jekyll.sanitized_path(opts[:JekyllOptions]["source"], opts[:JekyllOptions]["ssl_cert"])
opts[:SSLCertificate] = OpenSSL::X509::Certificate.new(File.read(source_certificate))
opts[:SSLPrivateKey ] = OpenSSL::PKey::RSA.new(File.read(source_key))
opts[:EnableSSL] = true
opts[:SSLEnable] = true
end
private

View File

@@ -71,7 +71,24 @@ module Jekyll
'hard_wrap' => false,
'footnote_nr' => 1
}
}]
}.map { |k, v| [k, v.freeze] }].freeze
class << self
# Static: Produce a Configuration ready for use in a Site.
# It takes the input, fills in the defaults where values do not
# exist, and patches common issues including migrating options for
# backwards compatiblity. Except where a key or value is being fixed,
# the user configuration will override the defaults.
#
# user_config - a Hash or Configuration of overrides.
#
# Returns a Configuration filled with defaults and fixed for common
# problems and backwards-compatibility.
def from(user_config)
Utils.deep_merge_hashes(DEFAULTS, Configuration[user_config].stringify_keys).
fix_common_issues.add_default_collections
end
end
# Public: Turn all keys into string
#
@@ -168,6 +185,7 @@ module Jekyll
begin
files.each do |config_file|
next if config_file.nil? or config_file.empty?
new_config = read_config_file(config_file)
configuration = Utils.deep_merge_hashes(configuration, new_config)
end
@@ -227,7 +245,6 @@ module Jekyll
end
%w(include exclude).each do |option|
config[option] ||= []
if config[option].is_a?(String)
Jekyll::Deprecator.deprecation_message "The '#{option}' configuration option" \
" must now be specified as an array, but you specified" \
@@ -235,7 +252,7 @@ module Jekyll
" as a list of comma-separated values."
config[option] = csv_to_array(config[option])
end
config[option].map!(&:to_s)
config[option].map!(&:to_s) if config[option]
end
if (config['kramdown'] || {}).key?('use_coderay')
@@ -270,14 +287,22 @@ module Jekyll
def add_default_collections
config = clone
# It defaults to `{}`, so this is only if someone sets it to null manually.
return config if config['collections'].nil?
# Ensure we have a hash.
if config['collections'].is_a?(Array)
config['collections'] = Hash[config['collections'].map { |c| [c, {}] }]
end
config['collections']['posts'] ||= {}
config['collections']['posts']['output'] = true
config['collections']['posts']['permalink'] = style_to_permalink(config['permalink'])
config['collections'] = Utils.deep_merge_hashes(
{ 'posts' => {} }, config['collections']
).tap do |collections|
collections['posts']['output'] = true
if config['permalink']
collections['posts']['permalink'] ||= style_to_permalink(config['permalink'])
end
end
config
end

View File

@@ -209,10 +209,13 @@ module Jekyll
used = Set.new([layout])
# Reset the payload layout data to ensure it starts fresh for each page.
payload["layout"] = nil
while layout
Jekyll.logger.debug "Rendering Layout:", path
payload["content"] = output
payload["layout"] = Utils.deep_merge_hashes(payload["layout"] || {}, layout.data)
payload["layout"] = Utils.deep_merge_hashes(layout.data, payload["layout"] || {})
self.output = render_liquid(layout.content,
payload,

View File

@@ -259,7 +259,7 @@ module Jekyll
@data = SafeYAML.load_file(path)
else
begin
defaults = @site.frontmatter_defaults.all(url, collection.label.to_sym)
defaults = @site.frontmatter_defaults.all(relative_path, collection.label.to_sym)
merge_data!(defaults, source: "front matter defaults") unless defaults.empty?
self.content = File.read(path, Utils.merged_file_read_opts(site, opts))

View File

@@ -3,7 +3,7 @@
module Jekyll
module Drops
class Drop < Liquid::Drop
NON_CONTENT_METHODS = [:[], :[]=, :inspect, :to_h, :fallback_data].freeze
NON_CONTENT_METHODS = [:fallback_data].freeze
# Get or set whether the drop class is mutable.
# Mutability determines whether or not pre-defined fields may be
@@ -86,7 +86,7 @@ module Jekyll
# Returns an Array of strings which represent method-specific keys.
def content_methods
@content_methods ||= (
self.class.instance_methods(false) - NON_CONTENT_METHODS
self.class.instance_methods - Jekyll::Drops::Drop.instance_methods - NON_CONTENT_METHODS
).map(&:to_s).reject do |method|
method.end_with?("=")
end
@@ -147,6 +147,12 @@ module Jekyll
keys.each(&block)
end
def each(&block)
each_key.each do |key|
yield key, self[key]
end
end
def merge(other, &block)
self.dup.tap do |me|
if block.nil?

View File

@@ -0,0 +1,15 @@
# encoding: UTF-8
module Jekyll
module Drops
class ExcerptDrop < DocumentDrop
def layout
@obj.doc.data['layout']
end
def excerpt
nil
end
end
end
end

View File

@@ -28,7 +28,7 @@ module Jekyll
end
def collections
@site_collections ||= @obj.collections.values.map(&:to_liquid)
@site_collections ||= @obj.collections.values.sort_by(&:label).map(&:to_liquid)
end
private

View File

@@ -7,7 +7,7 @@ module Jekyll
attr_writer :output
def_delegators :@doc, :site, :name, :ext, :relative_path, :extname,
:render_with_liquid?, :collection, :related_posts
:render_with_liquid?, :collection, :related_posts, :url
# Initialize this Excerpt instance.
#
@@ -59,10 +59,7 @@ module Jekyll
end
def to_liquid
doc.data['excerpt'] = nil
@to_liquid ||= doc.to_liquid
doc.data['excerpt'] = self
@to_liquid
Jekyll::Drops::ExcerptDrop.new(self)
end
# Returns the shorthand String identifier of this doc.

View File

@@ -76,7 +76,7 @@ module Jekyll
#
# Returns an Array of plugin search paths
def plugins_path
if site.config['plugins_dir'] == Jekyll::Configuration::DEFAULTS['plugins_dir']
if site.config['plugins_dir'].eql? Jekyll::Configuration::DEFAULTS['plugins_dir']
[site.in_source_dir(site.config['plugins_dir'])]
else
Array(site.config['plugins_dir']).map { |d| File.expand_path(d) }

View File

@@ -135,10 +135,13 @@ module Jekyll
used = Set.new([layout])
# Reset the payload layout data to ensure it starts fresh for each page.
payload["layout"] = nil
while layout
payload['content'] = output
payload['page'] = document.to_liquid
payload['layout'] = Utils.deep_merge_hashes(payload['layout'] || {}, layout.data)
payload['layout'] = Utils.deep_merge_hashes(layout.data, payload["layout"] || {})
output = render_liquid(
layout.content,

View File

@@ -53,6 +53,10 @@ module Jekyll
target.default_proc = overwrite.default_proc
end
target.each do |key, val|
target[key] = val.dup if val.frozen? && duplicable?(val)
end
target
end
@@ -60,6 +64,15 @@ module Jekyll
value.is_a?(Hash) || value.is_a?(Drops::Drop)
end
def duplicable?(obj)
case obj
when nil, false, true, Symbol, Numeric
false
else
true
end
end
# Read array from the supplied hash favouring the singular key
# and then the plural key, and handling any nil entries.
#

View File

@@ -1,3 +1,3 @@
module Jekyll
VERSION = '3.1.2'
VERSION = '3.1.5'
end

View File

@@ -6,7 +6,7 @@
desc "Release #{name} v#{version}"
task :release => :build do
unless `git branch` =~ /^\* master$/
unless `git branch` =~ /^\* 3\.1-stable$/
puts "You must be on the master branch to release!"
exit!
end

View File

@@ -4,6 +4,29 @@ title: History
permalink: "/docs/history/"
---
## 3.1.5 / 2016-05-18
{: #v3-1-5}
### Bug Fixes
{: #bug-fixes-v3-1-5}
- Sort the results of the `require_all` glob (affects Linux only). ([#4912]({{ site.repository }}/issues/4912))
## 3.1.4 / 2016-05-18
{: #v3-1-4}
### Bug Fixes
{: #bug-fixes-v3-1-4}
- Add `ExcerptDrop` and remove excerpt's ability to refer to itself in Liquid ([#4907]({{ site.repository }}/issues/4907))
- Configuration permalink fix where `collections.posts.permalink` inherits properly from `permalink` only when it doesn't exist ([#4910]({{ site.repository }}/issues/4910))
- Add `Configuration.from` to make it easier to build configs from just a hash
- Sorting `site.collections` in Liquid by label ([#4910]({{ site.repository }}/issues/4910))
- Fix bug where `layout` in Liquid would inherit from previously-rendered layouts' metadatas ([#4909]({{ site.repository }}/issues/4909))
- Fix bug where `layout` in Liquid would override in the wrong direction (more-specific layouts' data were overwritten by their parent layouts' data; this has now been reversed) ([#4909]({{ site.repository }}/issues/4909))
## 3.1.2 / 2016-02-19
{: #v3-1-2}

View File

@@ -1 +1 @@
3.1.2
3.1.5

View File

@@ -21,7 +21,7 @@ require 'minitest/autorun'
require 'minitest/reporters'
require 'minitest/profile'
require 'rspec/mocks'
require 'jekyll'
require_relative "../lib/jekyll.rb"
Jekyll.logger = Logger.new(StringIO.new)
@@ -58,8 +58,30 @@ module Minitest::Assertions
end
end
module DirectoryHelpers
def dest_dir(*subdirs)
test_dir('dest', *subdirs)
end
def source_dir(*subdirs)
test_dir('source', *subdirs)
end
def test_dir(*subdirs)
File.join(File.dirname(__FILE__), *subdirs)
end
end
class JekyllUnitTest < Minitest::Test
include ::RSpec::Mocks::ExampleMethods
include DirectoryHelpers
extend DirectoryHelpers
def mu_pp obj
s = obj.is_a?(Hash) ? JSON.pretty_generate(obj) : obj.inspect
s = s.encode Encoding.default_external if defined? Encoding
s
end
def mocks_expect(*args)
RSpec::Mocks::ExampleMethods::ExpectHost.instance_method(:expect).\
@@ -82,9 +104,12 @@ class JekyllUnitTest < Minitest::Test
Jekyll::Site.new(site_configuration(overrides))
end
def build_configs(overrides, base_hash = Jekyll::Configuration::DEFAULTS)
def default_configuration
Marshal.load(Marshal.dump(Jekyll::Configuration::DEFAULTS))
end
def build_configs(overrides, base_hash = default_configuration)
Utils.deep_merge_hashes(base_hash, overrides)
.fix_common_issues.backwards_compatibilize.add_default_collections
end
def site_configuration(overrides = {})
@@ -94,15 +119,10 @@ class JekyllUnitTest < Minitest::Test
}))
build_configs({
"source" => source_dir
}, full_overrides)
end
def dest_dir(*subdirs)
test_dir('dest', *subdirs)
end
def source_dir(*subdirs)
test_dir('source', *subdirs)
}, full_overrides).
fix_common_issues.
backwards_compatibilize.
add_default_collections
end
def clear_dest
@@ -110,10 +130,6 @@ class JekyllUnitTest < Minitest::Test
FileUtils.rm_rf(source_dir('.jekyll-metadata'))
end
def test_dir(*subdirs)
File.join(File.dirname(__FILE__), *subdirs)
end
def directory_with_contents(path)
FileUtils.rm_rf(path)
FileUtils.mkdir(path)

View File

@@ -105,7 +105,7 @@ class TestCommandsServe < JekyllUnitTest
"ssl_key" => "bar"
})
assert result[:EnableSSL]
assert result[:SSLEnable]
assert_equal result[:SSLPrivateKey ], "c2"
assert_equal result[:SSLCertificate], "c1"
end

View File

@@ -1,7 +1,62 @@
require 'helper'
class TestConfiguration < JekyllUnitTest
@@defaults = Jekyll::Configuration::DEFAULTS.add_default_collections.freeze
@@test_config = {
"source" => new(nil).source_dir,
"destination" => dest_dir
}
context ".from" do
should "create a Configuration object" do
assert_instance_of Configuration, Configuration.from({})
end
should "merge input over defaults" do
result = Configuration.from({"source" => "blah"})
refute_equal result["source"], Configuration::DEFAULTS["source"]
assert_equal result["source"], "blah"
end
should "fix common mistakes" do
result = Configuration.from({"paginate" => 0})
assert_nil result["paginate"], "Expected 'paginate' to be corrected to 'nil', but was #{result["paginate"].inspect}"
end
should "add default collections" do
result = Configuration.from({})
assert_equal result["collections"], {"posts" => {"output" => true, "permalink" => "/:categories/:year/:month/:day/:title:output_ext"}}
end
should "NOT backwards-compatibilize" do
assert Configuration.from("watch" => true)["watch"], "Expected the 'watch' key to not be removed."
end
end
context "#add_default_collections" do
should "no-op if collections is nil" do
result = Configuration[{"collections" => nil}].add_default_collections
assert_nil result["collections"]
end
should "turn an array into a hash" do
result = Configuration[{"collections" => %w{methods}}].add_default_collections
assert_instance_of Hash, result["collections"]
assert_equal result["collections"], {"posts" => {"output" => true}, "methods" => {}}
end
should "only assign collections.posts.permalink if a permalink is specified" do
result = Configuration[{"permalink" => "pretty", "collections" => {}}].add_default_collections
assert_equal result["collections"], {"posts" => {"output" => true, "permalink" => "/:categories/:year/:month/:day/:title/"}}
result = Configuration[{"permalink" => nil, "collections" => {}}].add_default_collections
assert_equal result["collections"], {"posts" => {"output" => true}}
end
should "forces posts to output" do
result = Configuration[{"collections" => {"posts" => {"output" => false}}}].add_default_collections
assert_equal result["collections"]["posts"]["output"], true
end
end
context "#stringify_keys" do
setup do
@@ -154,27 +209,27 @@ class TestConfiguration < JekyllUnitTest
end
context "loading configuration" do
setup do
@path = File.join(Dir.pwd, '_config.yml')
@path = source_dir('_config.yml')
@user_config = File.join(Dir.pwd, "my_config_file.yml")
end
should "fire warning with no _config.yml" do
allow(SafeYAML).to receive(:load_file).with(@path) { raise SystemCallError, "No such file or directory - #{@path}" }
allow($stderr).to receive(:puts).with("Configuration file: none".yellow)
assert_equal @@defaults, Jekyll.configuration({})
assert_equal site_configuration, Jekyll.configuration(@@test_config)
end
should "load configuration as hash" do
allow(SafeYAML).to receive(:load_file).with(@path).and_return(Hash.new)
allow($stdout).to receive(:puts).with("Configuration file: #{@path}")
assert_equal @@defaults, Jekyll.configuration({})
assert_equal site_configuration, Jekyll.configuration(@@test_config)
end
should "fire warning with bad config" do
allow(SafeYAML).to receive(:load_file).with(@path).and_return(Array.new)
allow($stderr).to receive(:puts).and_return(("WARNING: ".rjust(20) + "Error reading configuration. Using defaults (and options).").yellow)
allow($stderr).to receive(:puts).and_return("Configuration file: (INVALID) #{@path}".yellow)
assert_equal @@defaults, Jekyll.configuration({})
assert_equal site_configuration, Jekyll.configuration(@@test_config)
end
should "fire warning when user-specified config file isn't there" do
@@ -193,8 +248,8 @@ class TestConfiguration < JekyllUnitTest
context "loading config from external file" do
setup do
@paths = {
:default => File.join(Dir.pwd, '_config.yml'),
:other => File.join(Dir.pwd, '_config.live.yml'),
:default => source_dir('_config.yml'),
:other => source_dir('_config.live.yml'),
:toml => source_dir('_config.dev.toml'),
:empty => ""
}
@@ -203,24 +258,31 @@ class TestConfiguration < JekyllUnitTest
should "load default plus posts config if no config_file is set" do
allow(SafeYAML).to receive(:load_file).with(@paths[:default]).and_return({})
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}")
assert_equal @@defaults, Jekyll.configuration({})
assert_equal site_configuration, Jekyll.configuration(@@test_config)
end
should "load different config if specified" do
allow(SafeYAML).to receive(:load_file).with(@paths[:other]).and_return({"baseurl" => "http://wahoo.dev"})
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}")
assert_equal Utils.deep_merge_hashes(@@defaults, { "baseurl" => "http://wahoo.dev" }), Jekyll.configuration({ "config" => @paths[:other] })
Jekyll.configuration({ "config" => @paths[:other] })
assert_equal \
site_configuration({ "baseurl" => "http://wahoo.dev" }),
Jekyll.configuration(@@test_config.merge({ "config" => @paths[:other] }))
end
should "load default config if path passed is empty" do
allow(SafeYAML).to receive(:load_file).with(@paths[:default]).and_return({})
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}")
assert_equal @@defaults, Jekyll.configuration({ "config" => @paths[:empty] })
assert_equal \
site_configuration,
Jekyll.configuration(@@test_config.merge({ "config" => [@paths[:empty]] }))
end
should "successfully load a TOML file" do
Jekyll.logger.log_level = :warn
assert_equal @@defaults.clone.merge({ "baseurl" => "/you-beautiful-blog-you", "title" => "My magnificent site, wut" }), Jekyll.configuration({ "config" => [@paths[:toml]] })
assert_equal \
site_configuration({ "baseurl" => "/you-beautiful-blog-you", "title" => "My magnificent site, wut" }),
Jekyll.configuration(@@test_config.merge({ "config" => [@paths[:toml]] }))
Jekyll.logger.log_level = :info
end
@@ -233,7 +295,9 @@ class TestConfiguration < JekyllUnitTest
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}")
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}")
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:toml]}")
assert_equal @@defaults, Jekyll.configuration({ "config" => [@paths[:default], @paths[:other], @paths[:toml]] })
assert_equal \
site_configuration,
Jekyll.configuration(@@test_config.merge({ "config" => [@paths[:default], @paths[:other], @paths[:toml]] }))
end
should "load multiple config files and last config should win" do
@@ -241,7 +305,63 @@ class TestConfiguration < JekyllUnitTest
allow(SafeYAML).to receive(:load_file).with(@paths[:other]).and_return({"baseurl" => "http://wahoo.dev"})
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}")
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}")
assert_equal Utils.deep_merge_hashes(@@defaults, { "baseurl" => "http://wahoo.dev" }), Jekyll.configuration({ "config" => [@paths[:default], @paths[:other]] })
assert_equal \
site_configuration({ "baseurl" => "http://wahoo.dev" }),
Jekyll.configuration(@@test_config.merge({ "config" => [@paths[:default], @paths[:other]] }))
end
end
context "#add_default_collections" do
should "not do anything if collections is nil" do
conf = Configuration[default_configuration].tap {|c| c['collections'] = nil }
assert_equal conf.add_default_collections, conf
assert_nil conf.add_default_collections['collections']
end
should "converts collections to a hash if an array" do
conf = Configuration[default_configuration].tap {|c| c['collections'] = ['docs'] }
assert_equal conf.add_default_collections, conf.merge({
"collections" => {
"docs" => {},
"posts" => {
"output" => true,
"permalink" => "/:categories/:year/:month/:day/:title:output_ext"
}}})
end
should "force collections.posts.output = true" do
conf = Configuration[default_configuration].tap {|c| c['collections'] = {'posts' => {'output' => false}} }
assert_equal conf.add_default_collections, conf.merge({
"collections" => {
"posts" => {
"output" => true,
"permalink" => "/:categories/:year/:month/:day/:title:output_ext"
}}})
end
should "set collections.posts.permalink if it's not set" do
conf = Configuration[default_configuration]
assert_equal conf.add_default_collections, conf.merge({
"collections" => {
"posts" => {
"output" => true,
"permalink" => "/:categories/:year/:month/:day/:title:output_ext"
}}})
end
should "leave collections.posts.permalink alone if it is set" do
posts_permalink = "/:year/:title/"
conf = Configuration[default_configuration].tap do |c|
c['collections'] = {
"posts" => { "permalink" => posts_permalink }
}
end
assert_equal conf.add_default_collections, conf.merge({
"collections" => {
"posts" => {
"output" => true,
"permalink" => posts_permalink
}}})
end
end
end

View File

@@ -122,7 +122,7 @@ class TestDocument < JekyllUnitTest
@site = fixture_site({
"collections" => ["slides"],
"defaults" => [{
"scope"=> {"path"=>"slides", "type"=>"slides"},
"scope"=> {"path"=>"_slides", "type"=>"slides"},
"values"=> {
"nested"=> {
"key"=>"value123",

36
test/test_excerpt_drop.rb Normal file
View File

@@ -0,0 +1,36 @@
require 'helper'
class TestExcerptDrop < JekyllUnitTest
context "an excerpt drop" do
setup do
@site = fixture_site
@site.read
@doc = @site.docs_to_write.find { |d| !d.data['layout'].nil? }
@doc_drop = @doc.to_liquid
@excerpt = @doc.data['excerpt']
@excerpt_drop = @excerpt.to_liquid
end
should "have the right thing" do
assert @doc.is_a? Jekyll::Document
assert @doc_drop.is_a? Jekyll::Drops::DocumentDrop
assert @excerpt.is_a? Jekyll::Excerpt
assert @excerpt_drop.is_a? Jekyll::Drops::ExcerptDrop
end
should "not have an excerpt" do
assert_nil @excerpt.data['excerpt']
assert @excerpt_drop.class.invokable? 'excerpt'
assert_nil @excerpt_drop['excerpt']
end
should "inherit the layout for the drop but not the excerpt" do
assert_nil @excerpt.data['layout']
assert_equal @excerpt_drop['layout'], @doc_drop['layout']
end
should "inherit values from the document" do
assert_equal @excerpt_drop.keys.sort, @doc_drop.keys.sort
end
end
end

View File

@@ -4,9 +4,7 @@ class TestFrontMatterDefaults < JekyllUnitTest
context "A site with full front matter defaults" do
setup do
@site = Site.new(Jekyll.configuration({
"source" => source_dir,
"destination" => dest_dir,
@site = fixture_site({
"defaults" => [{
"scope" => {
"path" => "contacts",
@@ -16,7 +14,7 @@ class TestFrontMatterDefaults < JekyllUnitTest
"key" => "val"
}
}]
}))
})
@site.process
@affected = @site.pages.find { |page| page.relative_path == "/contacts/bar.html" }
@not_affected = @site.pages.find { |page| page.relative_path == "about.html" }
@@ -30,9 +28,7 @@ class TestFrontMatterDefaults < JekyllUnitTest
context "A site with front matter type pages and an extension" do
setup do
@site = Site.new(Jekyll.configuration({
"source" => source_dir,
"destination" => dest_dir,
@site = fixture_site({
"defaults" => [{
"scope" => {
"path" => "index.html"
@@ -41,7 +37,7 @@ class TestFrontMatterDefaults < JekyllUnitTest
"key" => "val"
}
}]
}))
})
@site.process
@affected = @site.pages.find { |page| page.relative_path == "index.html" }
@@ -56,9 +52,7 @@ class TestFrontMatterDefaults < JekyllUnitTest
context "A site with front matter defaults with no type" do
setup do
@site = Site.new(Jekyll.configuration({
"source" => source_dir,
"destination" => dest_dir,
@site = fixture_site({
"defaults" => [{
"scope" => {
"path" => "win"
@@ -67,7 +61,8 @@ class TestFrontMatterDefaults < JekyllUnitTest
"key" => "val"
}
}]
}))
})
@site.process
@affected = @site.posts.docs.find { |page| page.relative_path =~ /win\// }
@not_affected = @site.pages.find { |page| page.relative_path == "about.html" }
@@ -81,9 +76,7 @@ class TestFrontMatterDefaults < JekyllUnitTest
context "A site with front matter defaults with no path and a deprecated type" do
setup do
@site = Site.new(Jekyll.configuration({
"source" => source_dir,
"destination" => dest_dir,
@site = fixture_site({
"defaults" => [{
"scope" => {
"type" => "page"
@@ -92,7 +85,8 @@ class TestFrontMatterDefaults < JekyllUnitTest
"key" => "val"
}
}]
}))
})
@site.process
@affected = @site.pages
@not_affected = @site.posts.docs
@@ -106,9 +100,7 @@ class TestFrontMatterDefaults < JekyllUnitTest
context "A site with front matter defaults with no path" do
setup do
@site = Site.new(Jekyll.configuration({
"source" => source_dir,
"destination" => dest_dir,
@site = fixture_site({
"defaults" => [{
"scope" => {
"type" => "pages"
@@ -117,7 +109,7 @@ class TestFrontMatterDefaults < JekyllUnitTest
"key" => "val"
}
}]
}))
})
@site.process
@affected = @site.pages
@not_affected = @site.posts.docs
@@ -131,9 +123,7 @@ class TestFrontMatterDefaults < JekyllUnitTest
context "A site with front matter defaults with no path or type" do
setup do
@site = Site.new(Jekyll.configuration({
"source" => source_dir,
"destination" => dest_dir,
@site = fixture_site({
"defaults" => [{
"scope" => {
},
@@ -141,7 +131,7 @@ class TestFrontMatterDefaults < JekyllUnitTest
"key" => "val"
}
}]
}))
})
@site.process
@affected = @site.pages
@not_affected = @site.posts
@@ -155,15 +145,13 @@ class TestFrontMatterDefaults < JekyllUnitTest
context "A site with front matter defaults with no scope" do
setup do
@site = Site.new(Jekyll.configuration({
"source" => source_dir,
"destination" => dest_dir,
@site = fixture_site({
"defaults" => [{
"values" => {
"key" => "val"
}
}]
}))
})
@site.process
@affected = @site.pages
@not_affected = @site.posts

View File

@@ -4,9 +4,8 @@ class TestGeneratedSite < JekyllUnitTest
context "generated sites" do
setup do
clear_dest
config = Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir})
@site = fixture_site(config)
@site = fixture_site
@site.process
@index = File.read(dest_dir('index.html'))
end
@@ -64,8 +63,7 @@ OUTPUT
context "generating limited posts" do
setup do
clear_dest
config = Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => 5})
@site = fixture_site(config)
@site = fixture_site("limit_posts" => 5)
@site.process
@index = File.read(dest_dir('index.html'))
end
@@ -77,24 +75,13 @@ OUTPUT
should "ensure limit posts is 0 or more" do
assert_raises ArgumentError do
clear_dest
config = Jekyll::Configuration::DEFAULTS.merge({
'source' => source_dir,
'destination' => dest_dir,
'limit_posts' => -1
})
@site = fixture_site(config)
@site = fixture_site("limit_posts" => -1)
end
end
should "acceptable limit post is 0" do
clear_dest
config = Jekyll::Configuration::DEFAULTS.merge({
'source' => source_dir,
'destination' => dest_dir,
'limit_posts' => 0
})
assert Site.new(config), "Couldn't create a site with the given limit_posts."
assert fixture_site("limit_posts" => 0), "Couldn't create a site with limit_posts=0."
end
end
end

View File

@@ -3,42 +3,42 @@ require 'helper'
class TestSite < JekyllUnitTest
context "configuring sites" do
should "have an array for plugins by default" do
site = Site.new(Jekyll::Configuration::DEFAULTS)
site = Site.new default_configuration
assert_equal [File.join(Dir.pwd, '_plugins')], site.plugins
end
should "look for plugins under the site directory by default" do
site = Site.new(site_configuration)
assert_equal [File.join(source_dir, '_plugins')], site.plugins
assert_equal [source_dir('_plugins')], site.plugins
end
should "have an array for plugins if passed as a string" do
site = Site.new(Jekyll::Configuration::DEFAULTS.merge({'plugins_dir' => '/tmp/plugins'}))
site = Site.new(site_configuration({ 'plugins_dir' => '/tmp/plugins' }))
assert_equal ['/tmp/plugins'], site.plugins
end
should "have an array for plugins if passed as an array" do
site = Site.new(Jekyll::Configuration::DEFAULTS.merge({'plugins_dir' => ['/tmp/plugins', '/tmp/otherplugins']}))
site = Site.new(site_configuration({ 'plugins_dir' => ['/tmp/plugins', '/tmp/otherplugins'] }))
assert_equal ['/tmp/plugins', '/tmp/otherplugins'], site.plugins
end
should "have an empty array for plugins if nothing is passed" do
site = Site.new(Jekyll::Configuration::DEFAULTS.merge({'plugins_dir' => []}))
site = Site.new(site_configuration({ 'plugins_dir' => [] }))
assert_equal [], site.plugins
end
should "have an empty array for plugins if nil is passed" do
site = Site.new(Jekyll::Configuration::DEFAULTS.merge({'plugins_dir' => nil}))
assert_equal [], site.plugins
should "have the default for plugins if nil is passed" do
site = Site.new(site_configuration({ 'plugins_dir' => nil }))
assert_equal [source_dir('_plugins')], site.plugins
end
should "expose default baseurl" do
site = Site.new(Jekyll::Configuration::DEFAULTS)
site = Site.new(default_configuration)
assert_equal Jekyll::Configuration::DEFAULTS['baseurl'], site.baseurl
end
should "expose baseurl passed in from config" do
site = Site.new(Jekyll::Configuration::DEFAULTS.merge({'baseurl' => '/blog'}))
site = Site.new(site_configuration({ 'baseurl' => '/blog' }))
assert_equal '/blog', site.baseurl
end
end