project_template.rb 1.48 KB
Newer Older
1 2
module Gitlab
  class ProjectTemplate
3
    attr_reader :title, :name, :description, :preview
4

5 6
    def initialize(name, title, description, preview)
      @name, @title, @description, @preview = name, title, description, preview
7 8
    end

9
    alias_method :logo, :name
10 11

    def file
12
      archive_path.open
13 14
    end

15
    def archive_path
16 17 18
      Rails.root.join("vendor/project_templates/#{name}.tar.gz")
    end

19 20 21 22
    def clone_url
      "https://gitlab.com/gitlab-org/project-templates/#{name}.git"
    end

23 24 25 26
    def ==(other)
      name == other.name && title == other.title
    end

27
    TEMPLATES_TABLE = [
28 29 30
      ProjectTemplate.new('rails', 'Ruby on Rails', 'Includes a MVC structure, gemfile, rakefile, and .gitlab-ci.yml file, along with many others, to help you get started.', 'https://gitlab.com/gitlab-org/project-templates/rails'),
      ProjectTemplate.new('spring', 'Spring', 'Includes a MVC structure, mvnw, pom.xml, and .gitlab-ci.yml file to help you get started.', 'https://gitlab.com/gitlab-org/project-templates/spring'),
      ProjectTemplate.new('express', 'NodeJS Express', 'Includes a MVC structure, and .gitlab-ci.yml file to help you get started.', 'https://gitlab.com/gitlab-org/project-templates/express')
31 32 33 34
    ].freeze

    class << self
      def all
35
        TEMPLATES_TABLE
36 37 38 39 40
      end

      def find(name)
        all.find { |template| template.name == name.to_s }
      end
41 42 43 44

      def archive_directory
        Rails.root.join("vendor_directory/project_templates")
      end
45 46 47
    end
  end
end