Skip to content
Snippets Groups Projects
Commit bbfd62bc authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg Committed by Alfredo Sumaran
Browse files

fixup! override content method

parent a18df1d1
Branches
Tags
1 merge request!4411GitLab CI Yaml template dropdown
Loading
@@ -27,11 +27,7 @@ module API
Loading
@@ -27,11 +27,7 @@ module API
required_attributes! [:name] required_attributes! [:name]
   
new_template = klass.find(params[:name]) new_template = klass.find(params[:name])
not_found!("#{template.to_s.singularize}") unless new_template 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
   
present new_template, with: Entities::Template present new_template, with: Entities::Template
end end
Loading
Loading
module Gitlab module Gitlab
module Template module Template
class BaseTemplate class BaseTemplate
attr_writer :content
def initialize(path) def initialize(path)
@path = path @path = path
end end
Loading
@@ -12,19 +10,7 @@ module Gitlab
Loading
@@ -12,19 +10,7 @@ module Gitlab
end end
   
def content def content
@content ||= File.read(@path) File.read(@path)
end
def categories
raise NotImplementedError
end
def extension
raise NotImplementedError
end
def base_dir
raise NotImplementedError
end end
   
class << self class << self
Loading
@@ -39,6 +25,18 @@ module Gitlab
Loading
@@ -39,6 +25,18 @@ module Gitlab
directory ? new(File.join(category_directory(directory), file_name)) : nil directory ? new(File.join(category_directory(directory), file_name)) : nil
end end
   
def categories
raise NotImplementedError
end
def extension
raise NotImplementedError
end
def base_dir
raise NotImplementedError
end
def by_category(category) def by_category(category)
templates_for_directory(category_directory(category)) templates_for_directory(category_directory(category))
end end
Loading
Loading
module Gitlab module Gitlab
module Template module Template
class GitlabCiYml < BaseTemplate 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 class << self
def extension def extension
'.gitlab-ci.yml' '.gitlab-ci.yml'
Loading
Loading
Loading
@@ -27,7 +27,7 @@ namespace :gitlab do
Loading
@@ -27,7 +27,7 @@ namespace :gitlab do
# - The LICENSE, because we have to # - The LICENSE, because we have to
# - The sub dirs so we can organise the file by category # - The sub dirs so we can organise the file by category
# - The templates themself # - The templates themself
# - Dir.entires returns also the entries '.' and '..' # - Dir.entries returns also the entries '.' and '..'
def remove_unneeded_files(directory, regex) def remove_unneeded_files(directory, regex)
Dir.foreach(directory) do |file| Dir.foreach(directory) do |file|
FileUtils.rm_rf(File.join(directory, file)) unless file =~ regex FileUtils.rm_rf(File.join(directory, file)) unless file =~ regex
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment