diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/templates.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/template/base_template.rb | 28 | ||||
-rw-r--r-- | lib/gitlab/template/gitlab_ci_yml.rb | 5 | ||||
-rw-r--r-- | lib/tasks/gitlab/update_templates.rake | 2 |
4 files changed, 20 insertions, 21 deletions
diff --git a/lib/api/templates.rb b/lib/api/templates.rb index 33cbb0c9e1b..18408797756 100644 --- a/lib/api/templates.rb +++ b/lib/api/templates.rb @@ -27,11 +27,7 @@ module API required_attributes! [:name] new_template = klass.find(params[:name]) - not_found!("#{template.to_s.singularize}") unless new_template - - if new_template.class == Gitlab::Template::GitlabCiYml - new_template.content = "# This file is a template, and might need editing before it works on your project.\n" + new_template.content - end + not_found!(template.to_s.singularize) unless new_template present new_template, with: Entities::Template end diff --git a/lib/gitlab/template/base_template.rb b/lib/gitlab/template/base_template.rb index 4086d8701bf..760ff3e614a 100644 --- a/lib/gitlab/template/base_template.rb +++ b/lib/gitlab/template/base_template.rb @@ -1,8 +1,6 @@ module Gitlab module Template class BaseTemplate - attr_writer :content - def initialize(path) @path = path end @@ -12,19 +10,7 @@ module Gitlab end def content - @content ||= File.read(@path) - end - - def categories - raise NotImplementedError - end - - def extension - raise NotImplementedError - end - - def base_dir - raise NotImplementedError + File.read(@path) end class << self @@ -39,6 +25,18 @@ module Gitlab directory ? new(File.join(category_directory(directory), file_name)) : nil end + def categories + raise NotImplementedError + end + + def extension + raise NotImplementedError + end + + def base_dir + raise NotImplementedError + end + def by_category(category) templates_for_directory(category_directory(category)) end diff --git a/lib/gitlab/template/gitlab_ci_yml.rb b/lib/gitlab/template/gitlab_ci_yml.rb index f1e96d22d64..7f480fe33c0 100644 --- a/lib/gitlab/template/gitlab_ci_yml.rb +++ b/lib/gitlab/template/gitlab_ci_yml.rb @@ -1,6 +1,11 @@ module Gitlab module Template class GitlabCiYml < BaseTemplate + def content + explanation = "# This file is a template, and might need editing before it works on your project." + [explanation, super].join("\n") + end + class << self def extension '.gitlab-ci.yml' diff --git a/lib/tasks/gitlab/update_templates.rake b/lib/tasks/gitlab/update_templates.rake index 2d3c7993445..4f76dad7286 100644 --- a/lib/tasks/gitlab/update_templates.rake +++ b/lib/tasks/gitlab/update_templates.rake @@ -27,7 +27,7 @@ namespace :gitlab do # - The LICENSE, because we have to # - The sub dirs so we can organise the file by category # - The templates themself - # - Dir.entires returns also the entries '.' and '..' + # - Dir.entries returns also the entries '.' and '..' def remove_unneeded_files(directory, regex) Dir.foreach(directory) do |file| FileUtils.rm_rf(File.join(directory, file)) unless file =~ regex |