Sha256: b8ee61818897c152793fbd575ef81823a184cf99ca47e374f4b740e6865ed838

Contents?: true

Size: 979 Bytes

Versions: 13

Compression:

Stored size: 979 Bytes

Contents

module RevealCK
  module Templates
    #
    # Public: This class is home to a simple algorithm for looking up
    # files in a series of directories. Directory order matters, and the
    # first match for the file will be returned. It'll raise if it can't
    # find the file you've asked for.
    #
    class Finder
      attr_reader :paths

      def initialize(args = {})
        @paths = args[:paths] || default_paths
      end

      def default_paths
        pwd_templates = File.join Dir.pwd, 'templates'
        reveal_ck_templates =
          RevealCK.template_path('slides')
        [pwd_templates, reveal_ck_templates]
      end

      def find(template_name)
        paths.each do |path|
          glob_pattern = "#{File.join(path, template_name)}*"
          Dir.glob(glob_pattern).each do |match|
            return match unless File.directory? match
          end
        end
        fail "Unable to find #{template_name} in #{paths}"
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
reveal-ck-3.3.0 lib/reveal-ck/templates/finder.rb
reveal-ck-3.2.0 lib/reveal-ck/templates/finder.rb
reveal-ck-3.1.0 lib/reveal-ck/templates/finder.rb
reveal-ck-3.0.1 lib/reveal-ck/templates/finder.rb
reveal-ck-3.0.0 lib/reveal-ck/templates/finder.rb
reveal-ck-0.6.2 lib/reveal-ck/templates/finder.rb
reveal-ck-0.6.1 lib/reveal-ck/templates/finder.rb
reveal-ck-0.6.0 lib/reveal-ck/templates/finder.rb
reveal-ck-0.5.1 lib/reveal-ck/templates/finder.rb
reveal-ck-0.5.0 lib/reveal-ck/templates/finder.rb
reveal-ck-0.4.2 lib/reveal-ck/templates/finder.rb
reveal-ck-0.4.1 lib/reveal-ck/templates/finder.rb
reveal-ck-0.4.0 lib/reveal-ck/templates/finder.rb