fixup! override content method
This commit is contained in:
parent
a18df1d15a
commit
bbfd62bc34
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue