Sha256: 9c32ca21df7bd5d89ecfb6c0f92caaa981d196f1815567330e12fb4687f55e9f
Contents?: true
Size: 1.38 KB
Versions: 1
Compression:
Stored size: 1.38 KB
Contents
class Hash # Converts this hash into YAML format, splitting the YAML output into a # 'builtin' and a 'custom' section. A key that is present in # Nanoc2::Page::DEFAULTS will be considered a 'default' key; all other keys # will be put in the 'Custom' section. # # For example, the hash: # # { # :title => 'My Cool Page', # :filters_pre => [ 'foo', 'bar' ] # } # # will be converted into: # # # Built-in # filters_pre: [ 'foo', 'bar' ] # # # Custom # title: 'My Cool Page' # # as +filters_pre+ is considered a 'default' key while +title+ is not. def to_split_yaml # Skip irrelevant keys hash = self.reject { |k,v| k == :file } # Split keys hashes = { :builtin => {}, :custom => {} } hash.each_pair do |key, value| kind = Nanoc2::Page::DEFAULTS.include?(key) || Nanoc2::Asset::DEFAULTS.include?(key) ? :builtin : :custom hashes[kind][key] = value end # Dump and clean hashes dumps = { :builtin => '', :custom => '' } [ :builtin, :custom ].each do |kind| if hashes[kind].keys.empty? dumps[kind] = "\n" else raw_dump = YAML.dump(hashes[kind].stringify_keys) dumps[kind] = raw_dump.split('---')[1].gsub("\n\n", "\n") end end # Built composite YAML file '# Built-in' + dumps[:builtin] + "\n" + '# Custom' + dumps[:custom] end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nanoc2-2.2.3 | lib/nanoc2/extra/core_ext/hash.rb |