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.27 lib/ree/templates/template_detector.rb
ree-1.0.26 lib/ree/templates/template_detector.rb
ree-1.0.25 lib/ree/templates/template_detector.rb
ree-1.0.24 lib/ree/templates/template_detector.rb
ree-1.0.23 lib/ree/templates/template_detector.rb
ree-1.0.22 lib/ree/templates/template_detector.rb
ree-1.0.21 lib/ree/templates/template_detector.rb
ree-1.0.20 lib/ree/templates/template_detector.rb
ree-1.0.19 lib/ree/templates/template_detector.rb
ree-1.0.18 lib/ree/templates/template_detector.rb
ree-1.0.17 lib/ree/templates/template_detector.rb
ree-1.0.16 lib/ree/templates/template_detector.rb
ree-1.0.15 lib/ree/templates/template_detector.rb
ree-1.0.14 lib/ree/templates/template_detector.rb
ree-1.0.13 lib/ree/templates/template_detector.rb
ree-1.0.12 lib/ree/templates/template_detector.rb
ree-1.0.11 lib/ree/templates/template_detector.rb
ree-1.0.10 lib/ree/templates/template_detector.rb