Sha256: 9142614e6596760f4168ad85e7078cfb22591f5260d3e16228098af14b9b7434

Contents?: true

Size: 919 Bytes

Versions: 6

Compression:

Stored size: 919 Bytes

Contents

require "pathname"
require "sprockets"
require "tilt"

module Machined
  module Utils
    # Returns a hash of the Tilt templates
    # that are registered and available to use, where
    # the key is the extension the template's registered for.
    def self.available_templates
      @available_templates ||= {}.tap do |templates|
        Tilt.mappings.each_key do |ext|
          begin
            templates[Sprockets::Utils.normalize_extension(ext)] = Tilt[ext]
          rescue LoadError, NameError
            # safely ignore...
          end
        end
      end
    end
    
    # Returns an `Array` of the child directories that
    # exist within the given +path+. If the path itself
    # does not exist, an emtpy array is returned.
    def self.existent_directories(path)
      pathname = Pathname.new path
      pathname.directory? or return []
      pathname.children.select &:directory?
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
machined-0.7.1 lib/machined/utils.rb
machined-0.7.0 lib/machined/utils.rb
machined-0.6.0 lib/machined/utils.rb
machined-0.5.0 lib/machined/utils.rb
machined-0.4.0 lib/machined/utils.rb
machined-0.3.1 lib/machined/utils.rb