lib/nanoc/base/source_data/site.rb in nanoc-3.6.11 vs lib/nanoc/base/source_data/site.rb in nanoc-3.7.0
- old
+ new
@@ -30,11 +30,12 @@
# The default configuration for a site. A site's configuration overrides
# these options: when a {Nanoc::Site} is created with a configuration
# that lacks some options, the default value will be taken from
# `DEFAULT_CONFIG`.
DEFAULT_CONFIG = {
- :text_extensions => %w( css erb haml htm html js less markdown md php rb sass scss txt xhtml xml coffee hb handlebars mustache ms ).sort,
+ :text_extensions => %w( css erb haml htm html js less markdown md php rb sass scss txt xhtml xml coffee hb handlebars mustache ms slim ).sort,
+ :lib_dirs => %w( lib ),
:output_dir => 'output',
:data_sources => [ {} ],
:index_filenames => [ 'index.html' ],
:enable_output_diff => false,
:prune => { :auto_prune => false, :exclude => [ '.git', '.hg', '.svn', 'CVS' ] }
@@ -303,15 +304,19 @@
@code_snippets_loaded ||= false
return if @code_snippets_loaded
@code_snippets_loaded = true
# Get code snippets
- @code_snippets = Dir['lib/**/*.rb'].sort.map do |filename|
- Nanoc::CodeSnippet.new(
- File.read(filename),
- filename
- )
+ @code_snippets = []
+ config[:lib_dirs].each do |lib|
+ code_snippets = Dir["#{lib}/**/*.rb"].sort.map do |filename|
+ Nanoc::CodeSnippet.new(
+ File.read(filename),
+ filename
+ )
+ end
+ @code_snippets.concat(code_snippets)
end
# Execute code snippets
@code_snippets.each { |cs| cs.load }
end
@@ -348,10 +353,33 @@
layouts_in_ds.each { |i| i.identifier = File.join(ds.layouts_root, i.identifier) }
@layouts.concat(layouts_in_ds)
end
end
+ # Loads a configuration file.
+ def load_config(config_path)
+ YAML.load_file(config_path).symbolize_keys_recursively
+ end
+
+ def apply_parent_config(config, config_paths = [])
+ parent_config_file = config[:parent_config_file]
+ if parent_config_file
+ config.delete(:parent_config_file)
+ config_path = File.absolute_path(parent_config_file, File.dirname(config_paths.last))
+ if !File.file?(config_path)
+ raise Nanoc::Errors::GenericTrivial, "Could not find parent configuration file '#{parent_config_file}'"
+ end
+ if config_paths.include?(config_path)
+ raise Nanoc::Errors::GenericTrivial, "Cycle detected. Could not use parent configuration file '#{parent_config_file}'"
+ end
+ parent_config = load_config(config_path)
+ apply_parent_config(parent_config, config_paths + [config_path]).merge(config)
+ else
+ config
+ end
+ end
+
def ensure_identifier_uniqueness(objects, type)
seen = Set.new
objects.each do |obj|
if seen.include?(obj.identifier)
raise Nanoc::Errors::DuplicateIdentifier.new(obj.identifier, type)
@@ -373,24 +401,26 @@
config_path = Dir.chdir(dir_or_config_hash) do
filename = self.class.config_filename_for_cwd
if filename.nil?
raise Nanoc::Errors::GenericTrivial, 'Could not find nanoc.yaml or config.yaml in the current working directory'
end
- File.join(dir_or_config_hash, filename)
+ File.absolute_path(filename, dir_or_config_hash)
end
- @config = DEFAULT_CONFIG.merge(YAML.load_file(config_path).symbolize_keys_recursively)
- @config[:data_sources].map! { |ds| ds.symbolize_keys_recursively }
+
+ @config = apply_parent_config(load_config(config_path), [config_path])
else
# Use passed config hash
- @config = DEFAULT_CONFIG.merge(dir_or_config_hash)
+ @config = apply_parent_config(dir_or_config_hash.symbolize_keys_recursively)
end
+ # Merge config with default config
+ @config = DEFAULT_CONFIG.merge(@config)
+
# Merge data sources with default data source config
@config[:data_sources] = @config[:data_sources].map { |ds| DEFAULT_DATA_SOURCE_CONFIG.merge(ds) }
# Convert to proper configuration
@config = Nanoc::Configuration.new(@config)
end
-
end
end