Merge pull request #1022 from gkarekinian/patch-2

Fixed configuration overriding
This commit is contained in:
Parker Moore 2013-02-16 17:12:00 -08:00
commit 7265683c33
6 changed files with 85 additions and 3 deletions

View File

@ -9,6 +9,7 @@ require 'rake/minify'
require 'time'
require 'yaml'
require 'octopress'
require 'rake/testtask'
### Configuring Octopress:
### Under _config/ you will find:
@ -525,3 +526,7 @@ task :list do
puts "Tasks: #{(Rake::Task.tasks - [Rake::Task[:list]]).join(', ')}"
puts "(type rake -T for more detail)\n\n"
end
Rake::TestTask.new do |t|
t.pattern = "spec/**/*_spec.rb"
end

View File

@ -2,8 +2,10 @@ require 'yaml'
module Octopress
module Configuration
CONFIG_DIR = File.join(File.dirname(__FILE__), '../', '../' '_config')
def self.config_dir(*subdirs)
File.absolute_path(File.join(File.dirname(__FILE__), '../', '../' '_config', *subdirs))
File.absolute_path(File.join(CONFIG_DIR, *subdirs))
end
# Static: Reads the configuration of the specified file
@ -55,7 +57,7 @@ module Octopress
Dir.glob(self.config_dir('*.yml')) do |filename|
file_yaml = YAML.load(File.read(filename))
unless file_yaml.nil?
configs = file_yaml.deep_merge(configs)
configs = configs.deep_merge(file_yaml)
end
end

View File

@ -0,0 +1,11 @@
---
# ------------------------------- #
# Classic Theme Configuration #
# ------------------------------- #
url: http://yoursite.com
title: My Octopress Blog
subtitle: A blogging framework for hackers.
author: Your Name
simple_search: http://google.com/search
description:

View File

@ -0,0 +1,11 @@
---
# ------------------------------- #
# Classic Theme Configuration #
# ------------------------------- #
url: http://yoursite.com
title: My Octopress Blog
subtitle: A blogging framework for hackers.
author: Your Name
simple_search: http://google.com/search
description:

11
spec/fixtures/override/site.yml vendored Normal file
View File

@ -0,0 +1,11 @@
---
# ------------------------------- #
# Classic Theme Configuration #
# ------------------------------- #
url: http://myownsite.com
title: My Octopress custom Blog
subtitle: "How did this get here? I'm not good with computers"
author: John Doe
simple_search: http://google.com/search
description:

View File

@ -0,0 +1,42 @@
require 'minitest/autorun'
require_relative '../../lib/octopress'
describe Octopress::Configuration do
describe '.read_configuration' do
subject do
Octopress::Configuration.read_configuration
end
describe "when no override" do
before do
Octopress::Configuration::CONFIG_DIR = File.join(File.dirname(__FILE__), '../', 'fixtures', 'no_override')
end
it "returns the default config with keys as symbols" do
expected_config = { :url => "http://yoursite.com",
:title => "My Octopress Blog",
:subtitle => "A blogging framework for hackers.",
:author => "Your Name",
:simple_search => "http://google.com/search",
:description => nil }
subject.must_equal expected_config
end
end
describe "when override" do
before do
Octopress::Configuration::CONFIG_DIR = File.join(File.dirname(__FILE__), '../', 'fixtures', 'override')
end
it "returns the default config with keys as symbols" do
expected_config = { :url => "http://myownsite.com",
:title => "My Octopress custom Blog",
:subtitle => "How did this get here? I'm not good with computers",
:author => "John Doe",
:simple_search => "http://google.com/search",
:description => nil }
subject.must_equal expected_config
end
end
end
end