Sha256: 3ba0d9eac31073b4621a59c29cc8e01e7d779a1682295584ba42ebdb8f281c35

Contents?: true

Size: 915 Bytes

Versions: 4

Compression:

Stored size: 915 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

4 entries across 4 versions & 1 rubygems

Version Path
machined-1.1.0 lib/machined/utils.rb
machined-1.0.3 lib/machined/utils.rb
machined-1.0.2 lib/machined/utils.rb
machined-1.0.1 lib/machined/utils.rb