lib/nanoc/data_sources/filesystem.rb in nanoc-4.0.0rc1 vs lib/nanoc/data_sources/filesystem.rb in nanoc-4.0.0rc2

- old
+ new

@@ -217,10 +217,11 @@ begin meta = YAML.load(meta_raw) || {} rescue Exception => e raise "Could not parse YAML for #{meta_filename}: #{e.message}" end + verify_meta(meta, meta_filename) return [meta, content] end # Read data data = read(content_filename) @@ -242,13 +243,26 @@ begin meta = YAML.load(pieces[2]) || {} rescue Exception => e raise "Could not parse YAML for #{content_filename}: #{e.message}" end + verify_meta(meta, content_filename) content = pieces[4] # Done [meta, content] + end + + class InvalidMetadataError < Nanoc::Error + def initialize(filename, klass) + super("The file #{filename} has invalid metadata (expected key-value pairs, found #{klass} instead)") + end + end + + def verify_meta(meta, filename) + return if meta.is_a?(Hash) + + raise InvalidMetadataError.new(filename, meta.class) end # Reads the content of the file with the given name and returns a string # in UTF-8 encoding. The original encoding of the string is derived from # the default external encoding, but this can be overridden by the