Module: Octopress::Ink::Utils
Instance Method Summary collapse
Instance Method Details
#pretty_print_yaml(yaml) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/octopress-ink/utils.rb', line 8 def pretty_print_yaml(yaml) # Use json pretty_print, but make it look like yaml # JSON.pretty_generate(yaml) .sub(/\A{\n/,'') # remove leading { .sub(/}\z/,'') # remove trailing } .gsub(/^/,' ') # indent .gsub(/"(.+?)":/,'\1:') # remove quotes around keys .gsub(/,$/,'') # remove commas from end of lines .gsub(/{\n/,"\n") # remove keys with empty hashes .gsub(/^\s+}\n/,'') # remove keys with empty hashes .gsub(/\[\s+\]/,'[]') # remove whitespace in empty arrays end |