move util methods into their own namespace

This commit is contained in:
Thomas Reynolds 2012-04-14 13:36:24 -07:00
parent 094de61e92
commit 0bc35db4a6
8 changed files with 50 additions and 55 deletions

View file

@ -0,0 +1,35 @@
# Using Thor's indifferent hash access
require "thor"
module Middleman
module Util
# Recursively convert a normal Hash into a HashWithIndifferentAccess
#
# @private
# @param [Hash] data Normal hash
# @return [Thor::CoreExt::HashWithIndifferentAccess]
def self.recursively_enhance(data)
if data.is_a? Hash
data = ::Thor::CoreExt::HashWithIndifferentAccess.new(data)
data.each do |key, val|
data[key] = recursively_enhance(val)
end
data
elsif data.is_a? Array
data.each_with_index do |val, i|
data[i] = recursively_enhance(val)
end
data
else
data
end
end
# Normalize a path to not include a leading slash
# @param [String] path
# @return [String]
def self.normalize_path(path)
path.sub(/^\//, "").gsub("%20", " ")
end
end
end