Sha256: 4cce6752325c1fce16e26cb7e758e0794512c98fa96d3f90f75ad92774643456

Contents?: true

Size: 1.05 KB

Versions: 38

Compression:

Stored size: 1.05 KB

Contents

class Ree::TemplateDetector
  DEFAULT_TEMPLATES_DIRECTORY = File.expand_path(__dir__)

  def initialize(project_path)
    @all_templates_directory ||= File.join(project_path, ".ree", "templates")
  end

  def detect_template_folder(template_name)
    template_path = [@all_templates_directory, DEFAULT_TEMPLATES_DIRECTORY]
      .map    {|dir| File.join(dir, template_name.to_s)}
      .detect  {|dir| Dir.exist?(dir)}

    raise Ree::Error.new('Template does not exist') if template_path.nil?

    template_path
  end

  def gem_template_folder(template_name)
    File.join(DEFAULT_TEMPLATES_DIRECTORY, template_name.to_s)
  end

  def project_template_folder(template_name)
    File.join(@all_templates_directory, template_name.to_s)
  end

  def template_file_path(template_name, relative_path)
    file_path = [detect_template_folder(template_name), DEFAULT_TEMPLATES_DIRECTORY]
      .map {|folder| File.join(folder, relative_path)}
      .detect {|file| File.exist?(file)}

      raise Ree::Error.new('Template does not exist') if file_path.nil?

    file_path
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
ree-1.0.47 lib/ree/templates/template_detector.rb
ree-1.0.46 lib/ree/templates/template_detector.rb
ree-1.0.45 lib/ree/templates/template_detector.rb
ree-1.0.44 lib/ree/templates/template_detector.rb
ree-1.0.43 lib/ree/templates/template_detector.rb
ree-1.0.42 lib/ree/templates/template_detector.rb
ree-1.0.41 lib/ree/templates/template_detector.rb
ree-1.0.40 lib/ree/templates/template_detector.rb
ree-1.0.39 lib/ree/templates/template_detector.rb
ree-1.0.38 lib/ree/templates/template_detector.rb
ree-1.0.37 lib/ree/templates/template_detector.rb
ree-1.0.36 lib/ree/templates/template_detector.rb
ree-1.0.35 lib/ree/templates/template_detector.rb
ree-1.0.34 lib/ree/templates/template_detector.rb
ree-1.0.33 lib/ree/templates/template_detector.rb
ree-1.0.32 lib/ree/templates/template_detector.rb
ree-1.0.31 lib/ree/templates/template_detector.rb
ree-1.0.30 lib/ree/templates/template_detector.rb
ree-1.0.29 lib/ree/templates/template_detector.rb
ree-1.0.28 lib/ree/templates/template_detector.rb