diff options
author | Zeger-Jan van de Weg <zegerjan@gitlab.com> | 2016-04-29 17:25:03 +0300 |
---|---|---|
committer | Alfredo Sumaran <alfredo@gitlab.com> | 2016-05-20 23:58:36 +0300 |
commit | e166a8022a3f239938a1449a0a8ce3485f309766 (patch) | |
tree | af9f612f599b01f5736e7b439f9579d77658f156 /app | |
parent | 56eb42007ae8c3c390b35bf336884b3bad3591c5 (diff) |
Backend for a gitignores dropdown
Diffstat (limited to 'app')
-rw-r--r-- | app/helpers/blob_helper.rb | 4 | ||||
-rw-r--r-- | app/models/repository.rb | 20 | ||||
-rw-r--r-- | app/views/projects/blob/_editor.html.haml | 3 | ||||
-rw-r--r-- | app/views/projects/empty.html.haml | 10 |
4 files changed, 28 insertions, 9 deletions
diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 93241b3afb7..fb1b7649465 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -184,4 +184,8 @@ module BlobHelper Other: licenses.reject(&:featured).map { |license| [license.name, license.key] } } end + + def gitignores_for_select + @gitignores_for_select ||= Gitlab::Gitignore.all + end end diff --git a/app/models/repository.rb b/app/models/repository.rb index 47a7223c723..f26278cc3af 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -472,9 +472,7 @@ class Repository def changelog cache.fetch(:changelog) do - tree(:head).blobs.find do |file| - file.name =~ /\A(changelog|history|changes|news)/i - end + file_on_head(/\A(changelog|history|changes|news)/i) end end @@ -482,9 +480,7 @@ class Repository return nil unless head_exists? cache.fetch(:license_blob) do - tree(:head).blobs.find do |file| - file.name =~ /\A(licen[sc]e|copying)(\..+|\z)/i - end + file_on_head(/\A(licen[sc]e|copying)(\..+|\z)/i) end end @@ -496,6 +492,14 @@ class Repository end end + def gitignore + return nil if !exists? || empty? + + cache.fetch(:gitignore) do + file_on_head(/\A\.gitignore\z/) + end + end + def gitlab_ci_yml return nil unless head_exists? @@ -989,4 +993,8 @@ class Repository def head_exists? exists? && !empty? && !rugged.head_unborn? end + + def file_on_head(regex) + tree(:head).blobs.find { |file| file.name =~ regex } + end end diff --git a/app/views/projects/blob/_editor.html.haml b/app/views/projects/blob/_editor.html.haml index fefa652a3da..eac5014b7c9 100644 --- a/app/views/projects/blob/_editor.html.haml +++ b/app/views/projects/blob/_editor.html.haml @@ -16,6 +16,9 @@ .license-selector.js-license-selector.hide = select_tag :license_type, grouped_options_for_select(licenses_for_select, @project.repository.license_key), include_blank: true, class: 'select2 license-select', data: {placeholder: 'Choose a license template', project: @project.name, fullname: @project.namespace.human_name} + .gitignore-selector.js-gitignore-selector.hide + = select_tag :gitignore_template, options_for_select(Gitlab::Gitignore.all), include_blank: true, class: 'select2 gitignore-select', data: {placeholder: 'Choose a .gitignore template'} + .encoding-selector = select_tag :encoding, options_for_select([ "base64", "text" ], "text"), class: 'select2' diff --git a/app/views/projects/empty.html.haml b/app/views/projects/empty.html.haml index 1a2e59752fe..636beb73ec2 100644 --- a/app/views/projects/empty.html.haml +++ b/app/views/projects/empty.html.haml @@ -15,10 +15,14 @@ If you already have files you can push them using command line instructions below. %p Otherwise you can start with adding a - = link_to "README", new_readme_path, class: 'underlined-link' + = succeed ',' do + = link_to "README", new_readme_path, class: 'underlined-link' + a + = succeed ',' do + = link_to "LICENSE", add_special_file_path(@project, file_name: 'LICENSE'), class: 'underlined-link' or a - = link_to "LICENSE", add_special_file_path(@project, file_name: 'LICENSE'), class: 'underlined-link' - file to this project. + = link_to '.gitignore', add_special_file_path(@project, file_name: '.gitignore'), class: 'underlined-link' + to this project. - if can?(current_user, :push_code, @project) %div{ class: container_class } |