Commit bbfd62bc authored by Z.J. van de Weg's avatar Z.J. van de Weg Committed by Alfredo Sumaran

fixup! override content method

parent a18df1d1
......@@ -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
......
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
......
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'
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment