module Middleman::Util
def self.all_files_under(*paths)
-
(Array)
- An array of filenames
Parameters:
-
path
() -- A path string or Pathname
def self.all_files_under(*paths) paths.flatten! paths.map! { |p| Pathname(p) } files = paths.select { |p| p.file? } paths.select {|p| p.directory? }.each do |dir| files << all_files_under(dir.children) end files.flatten end
def self.extract_response_text(response)
-
(String)
- The whole response as a string.
Parameters:
-
response
() -- The response from #call
def self.extract_response_text(response) case(response) when String response when Array response.join when Rack::Response response.body.join when Rack::File File.read(response.path) else response.to_s end end
def self.instrument(name, payload={}, &block)
def self.instrument(name, payload={}, &block) name << ".middleman" unless name =~ /\.middleman$/ ::ActiveSupport::Notifications.instrument(name, payload, &block) end
def self.logger(*args)
-
(Middleman::Logger)
- The logger
def self.logger(*args) if !@_logger || args.length > 0 @_logger = ::Middleman::Logger.new(*args) end @_logger end
def self.normalize_path(path)
-
(String)
-
Parameters:
-
path
(String
) --
def self.normalize_path(path) # The tr call works around a bug in Ruby's Unicode handling path.sub(/^\//, "").tr('','') end
def self.path_match(matcher, path)
-
(Boolean)
- Whether the path matches the matcher
Parameters:
-
path
() -- A path as a string
-
matcher
() -- A matcher string/regexp/proc/etc
def self.path_match(matcher, path) if matcher.respond_to? :match matcher.match path elsif matcher.respond_to? :call matcher.call path else File.fnmatch(matcher.to_s, path) end end
def self.recursively_enhance(data)
-
(Thor::CoreExt::HashWithIndifferentAccess)
-
Parameters:
-
data
(Hash
) -- Normal hash
Other tags:
- Private: -
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